| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #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);
- /// Re-open the registry collection for every given project. The DB only
- /// surfaces a collection through find()/list() once it has been opened in
- /// the current server process; without this, a restart leaves every
- /// per-project registry index invisible (collections appear empty / 404)
- /// even though the data survives. Call once at startup with all known
- /// projects — mirrors KeyStore::bootstrap re-opening vectorapi_keys. (issue #1)
- void bootstrap(const std::vector<std::string>& projects);
- /// 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
|