collection_registry.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include "db_gateway.hpp"
  3. #include <nlohmann/json.hpp>
  4. #include <optional>
  5. #include <string>
  6. #include <vector>
  7. namespace svapi {
  8. /// Metadata describing a managed collection.
  9. struct CollectionMeta {
  10. std::string name;
  11. std::string kind;
  12. uint32_t vectorDimension = 0;
  13. std::string embeddingModel;
  14. uint64_t createdAt = 0;
  15. static CollectionMeta fromJson(const nlohmann::json&);
  16. nlohmann::json toJson() const;
  17. };
  18. /// Project-scoped registry: one document per managed collection stored in
  19. /// qualify(project, "vectorapi_collections").
  20. class CollectionRegistry {
  21. public:
  22. explicit CollectionRegistry(DbGateway& db);
  23. /// Ensure the registry collection for `project` exists (idempotent).
  24. void ensure(const std::string& project);
  25. /// Add (or overwrite) a collection entry. Returns true on success.
  26. bool add(const std::string& project, const CollectionMeta& meta);
  27. /// Look up a single collection entry by name.
  28. std::optional<CollectionMeta> get(const std::string& project, const std::string& name);
  29. /// List all collection entries for the project.
  30. std::vector<CollectionMeta> list(const std::string& project);
  31. /// Remove a collection entry. Returns true if the document was present.
  32. bool remove(const std::string& project, const std::string& name);
  33. private:
  34. DbGateway& db_;
  35. /// Qualified registry collection name for the given project.
  36. std::string coll(const std::string& project) const {
  37. return qualify(project, "vectorapi_collections");
  38. }
  39. };
  40. } // namespace svapi