在 Storage Daemon 中设计一个VectorIndexManager单例对整个 Storaged 中的 Ann Index 进行管理。
Ann Index 的生命周期:
创建:通过 CreateTagAnnIndex 请求创建 Ann Index。
除非删除,否则会一直在内存中维护,在退出时需要持久化到磁盘,同时重启系统后需要从磁盘中加载已经存在的 Ann Index。
使用:在查询时使用 Ann Index 进行加速。
删除:通过 DropTagAnnIndex 请求删除 Ann Index。
更新:通过 UpdateTagAnnIndex 请求更新 Ann Index。
class VectorIndexManager final { public: static VectorIndexManager& getInstance(); // Initialize the manager with necessary dependencies Status init(meta::IndexManager* indexManager, std::string annIndexPath); // Start the manager (background tasks, cleanup threads, etc.) Status start(); // Stop the manager gracefully Status stop(); // Wait until the manager stops (similar to StorageServer::waitUntilStop) void waitUntilStop(); // Notify the manager to stop (used for signal handling) void notifyStop(); // Create a vector index for a specific partition and index ID Status createOrUpdateIndex(GraphSpaceID spaceId, PartitionID partitionId, IndexID indexId, const std::shared_ptr<meta::cpp2::AnnIndexItem>& indexItem); // Get an existing vector index StatusOr<std::shared_ptr<AnnIndex>> getIndex(GraphSpaceID spaceId, PartitionID partitionId, IndexID indexId); // Remove a vector index Status removeIndex(GraphSpaceID spaceId, PartitionID partitionId, IndexID indexId); // Get all managed indexes for a partition std::vector<std::shared_ptr<AnnIndex>> getIndexesByPartition(GraphSpaceID spaceId, PartitionID partitionId); // Check if an index exists bool hasIndex(GraphSpaceID spaceId, PartitionID partitionId, IndexID indexId) const; // Rebuild an index (called during BuildVectorIndexTask) Status rebuildIndex(GraphSpaceID spaceId, PartitionID partitionId, IndexID indexId, const std::shared_ptr<meta::cpp2::AnnIndexItem>& indexItem);};