| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #pragma once
- #include "db_gateway.hpp"
- #include <nlohmann/json.hpp>
- #include <optional>
- #include <string>
- #include <vector>
- namespace svapi {
- /// Metadata describing a managed collection.
- struct CollectionMeta {
- std::string name;
- std::string kind;
- uint32_t vectorDimension = 0;
- std::string embeddingModel;
- uint64_t createdAt = 0;
- static CollectionMeta fromJson(const nlohmann::json&);
- nlohmann::json toJson() const;
- };
- /// Project-scoped registry: one document per managed collection stored in
- /// qualify(project, "vectorapi_collections").
- class CollectionRegistry {
- public:
- explicit CollectionRegistry(DbGateway& db);
- /// Ensure the registry collection for `project` exists (idempotent).
- void ensure(const std::string& project);
- /// Add (or overwrite) a collection entry. Returns true on success.
- bool add(const std::string& project, const CollectionMeta& meta);
- /// Look up a single collection entry by name.
- std::optional<CollectionMeta> get(const std::string& project, const std::string& name);
- /// List all collection entries for the project.
- std::vector<CollectionMeta> list(const std::string& project);
- /// Remove a collection entry. Returns true if the document was present.
- bool remove(const std::string& project, const std::string& name);
- private:
- DbGateway& db_;
- /// Qualified registry collection name for the given project.
- std::string coll(const std::string& project) const {
- return qualify(project, "vectorapi_collections");
- }
- };
- } // namespace svapi
|