pub struct VectorIndexCoordinator<E: StorageEngine> { /* private fields */ }Expand description
Coordinator for HNSW indexes with separated vector storage.
This struct provides a unified interface for:
- Storing vectors in
CollectionVectorStore - Maintaining HNSW indexes via
HnswIndexManager - Coordinating insert/update/delete operations
- Rebuilding indexes from stored vectors
The coordinator ensures that:
- Vectors are stored in the vector store for persistence
- HNSW indexes are updated automatically for fast similarity search
- Delete operations cascade properly to both stores
Implementations§
Source§impl<E: StorageEngine> VectorIndexCoordinator<E>
impl<E: StorageEngine> VectorIndexCoordinator<E>
Sourcepub fn with_manager(engine: E, index_manager: Arc<HnswIndexManager<E>>) -> Self
pub fn with_manager(engine: E, index_manager: Arc<HnswIndexManager<E>>) -> Self
Create a coordinator with an existing index manager.
Use this when you need to share an index manager across multiple coordinators.
Sourcepub fn vector_store(&self) -> &CollectionVectorStore<E>
pub fn vector_store(&self) -> &CollectionVectorStore<E>
Get a reference to the vector store.
Sourcepub fn index_manager(&self) -> &Arc<HnswIndexManager<E>>
pub fn index_manager(&self) -> &Arc<HnswIndexManager<E>>
Get a reference to the index manager.
Sourcepub fn upsert_vector(
&self,
collection_id: CollectionId,
entity_id: EntityId,
collection_name: &str,
vector_name: &str,
data: &VectorData,
) -> Result<(), VectorError>
pub fn upsert_vector( &self, collection_id: CollectionId, entity_id: EntityId, collection_name: &str, vector_name: &str, data: &VectorData, ) -> Result<(), VectorError>
Upsert a vector, updating both storage and HNSW index.
This method:
- Stores the vector in
CollectionVectorStore - Updates the HNSW index (if one exists for this named vector)
§Arguments
collection_id- The collection IDentity_id- The entity IDcollection_name- Collection name for index lookupvector_name- The vector name within the collectiondata- The vector data to store
§Errors
Returns an error if storage or index update fails.
Sourcepub fn upsert_vectors_batch(
&self,
collection_id: CollectionId,
collection_name: &str,
vectors: &[(EntityId, &str, &VectorData)],
) -> Result<(), VectorError>
pub fn upsert_vectors_batch( &self, collection_id: CollectionId, collection_name: &str, vectors: &[(EntityId, &str, &VectorData)], ) -> Result<(), VectorError>
Upsert multiple vectors in a batch.
More efficient than calling upsert_vector multiple times as it
batches storage operations and HNSW insertions.
§Arguments
collection_id- The collection IDcollection_name- Collection name for index lookupvectors- List of (entity_id, vector_name, vector_data) tuples
Sourcepub fn delete_vector(
&self,
collection_id: CollectionId,
entity_id: EntityId,
collection_name: &str,
vector_name: &str,
) -> Result<bool, VectorError>
pub fn delete_vector( &self, collection_id: CollectionId, entity_id: EntityId, collection_name: &str, vector_name: &str, ) -> Result<bool, VectorError>
Delete a vector from both storage and HNSW index.
§Returns
Returns true if the vector was deleted from storage.
Sourcepub fn delete_entity_vectors(
&self,
collection_id: CollectionId,
entity_id: EntityId,
collection_name: &str,
) -> Result<usize, VectorError>
pub fn delete_entity_vectors( &self, collection_id: CollectionId, entity_id: EntityId, collection_name: &str, ) -> Result<usize, VectorError>
Delete all vectors for an entity.
This cascades the delete to all HNSW indexes for the collection.
§Returns
Returns the number of vectors deleted from storage.
Sourcepub fn get_vector(
&self,
collection_id: CollectionId,
entity_id: EntityId,
vector_name: &str,
) -> Result<Option<VectorData>, VectorError>
pub fn get_vector( &self, collection_id: CollectionId, entity_id: EntityId, vector_name: &str, ) -> Result<Option<VectorData>, VectorError>
Get a vector from storage.
Sourcepub fn get_all_vectors(
&self,
collection_id: CollectionId,
entity_id: EntityId,
) -> Result<HashMap<String, VectorData>, VectorError>
pub fn get_all_vectors( &self, collection_id: CollectionId, entity_id: EntityId, ) -> Result<HashMap<String, VectorData>, VectorError>
Get all vectors for an entity.
Sourcepub fn search(
&self,
collection_name: &str,
vector_name: &str,
query: &Embedding,
k: usize,
ef_search: Option<usize>,
) -> Result<Vec<SearchResult>, VectorError>
pub fn search( &self, collection_name: &str, vector_name: &str, query: &Embedding, k: usize, ef_search: Option<usize>, ) -> Result<Vec<SearchResult>, VectorError>
Search for similar vectors using HNSW.
§Arguments
collection_name- The collection to searchvector_name- The named vector to searchquery- The query embeddingk- Number of results to returnef_search- Optional beam width (uses default if None)
§Returns
A list of search results with entity IDs and distances.
Sourcepub fn search_with_filter<F>(
&self,
collection_name: &str,
vector_name: &str,
query: &Embedding,
k: usize,
predicate: F,
ef_search: Option<usize>,
) -> Result<Vec<SearchResult>, VectorError>
pub fn search_with_filter<F>( &self, collection_name: &str, vector_name: &str, query: &Embedding, k: usize, predicate: F, ef_search: Option<usize>, ) -> Result<Vec<SearchResult>, VectorError>
Search with a filter predicate.
The predicate is applied during graph traversal, not as a post-filter.
Sourcepub fn rebuild_index_from_store(
&self,
collection_id: CollectionId,
collection_name: &str,
vector_name: &str,
) -> Result<usize, VectorError>
pub fn rebuild_index_from_store( &self, collection_id: CollectionId, collection_name: &str, vector_name: &str, ) -> Result<usize, VectorError>
Rebuild an HNSW index from the vector store.
This is useful for:
- Recovering from index corruption
- Building an index for existing vectors
- Re-indexing after configuration changes
§Arguments
collection_id- The collection IDcollection_name- Collection name for index lookupvector_name- The named vector to rebuild
§Returns
The number of vectors indexed.
Sourcepub fn is_index_loaded(&self, collection: &str, vector_name: &str) -> bool
pub fn is_index_loaded(&self, collection: &str, vector_name: &str) -> bool
Check if an index is loaded in memory.
Source§impl<E: StorageEngine> VectorIndexCoordinator<E>
Extension methods for the coordinator that require ownership of a storage engine.
impl<E: StorageEngine> VectorIndexCoordinator<E>
Extension methods for the coordinator that require ownership of a storage engine.
Sourcepub fn create_index(
&self,
engine: E,
collection: &str,
vector_name: &str,
dimension: usize,
distance_metric: DistanceMetric,
config: &HnswConfig,
) -> Result<String, VectorError>
pub fn create_index( &self, engine: E, collection: &str, vector_name: &str, dimension: usize, distance_metric: DistanceMetric, config: &HnswConfig, ) -> Result<String, VectorError>
Create an HNSW index for a collection’s named vector.
Note: This method takes a separate engine instance for index persistence. You may want to call this with a shared engine reference or a cloned engine.
§Arguments
engine- Storage engine for the index persistencecollection- Collection name (e.g., “documents”)vector_name- Vector name within the collection (e.g., “text_embedding”)dimension- Vector dimensiondistance_metric- Distance metric for similarityconfig- HNSW configuration
§Returns
The name of the created index (e.g., “documents_text_embedding_hnsw”)
Sourcepub fn drop_index(
&self,
engine: &E,
index_name: &str,
) -> Result<bool, VectorError>
pub fn drop_index( &self, engine: &E, index_name: &str, ) -> Result<bool, VectorError>
Drop an HNSW index.
Sourcepub fn drop_collection_indexes(
&self,
engine: &E,
collection: &str,
) -> Result<Vec<String>, VectorError>
pub fn drop_collection_indexes( &self, engine: &E, collection: &str, ) -> Result<Vec<String>, VectorError>
Drop all HNSW indexes for a collection.
Sourcepub fn has_index(&self, engine: &E, collection: &str, vector_name: &str) -> bool
pub fn has_index(&self, engine: &E, collection: &str, vector_name: &str) -> bool
Check if an HNSW index exists for a collection’s named vector.
Sourcepub fn load_index(&self, engine: E, index_name: &str) -> Result<(), VectorError>
pub fn load_index(&self, engine: E, index_name: &str) -> Result<(), VectorError>
Load an existing index into memory.
Sourcepub fn rebuild_index_from_scratch(
&self,
engine: E,
collection_id: CollectionId,
collection_name: &str,
vector_name: &str,
) -> Result<usize, VectorError>
pub fn rebuild_index_from_scratch( &self, engine: E, collection_id: CollectionId, collection_name: &str, vector_name: &str, ) -> Result<usize, VectorError>
Rebuild an index from scratch with new configuration.
This drops the existing index data and creates a fresh index.
§Arguments
engine- Storage engine for the new indexcollection_id- The collection IDcollection_name- Collection namevector_name- The named vector to rebuild
§Returns
The number of vectors indexed.