VectorIndexCoordinator

Struct VectorIndexCoordinator 

Source
pub struct VectorIndexCoordinator<E: StorageEngine> { /* private fields */ }
Expand description

Coordinator for HNSW indexes with separated vector storage.

This struct provides a unified interface for:

The coordinator ensures that:

  1. Vectors are stored in the vector store for persistence
  2. HNSW indexes are updated automatically for fast similarity search
  3. Delete operations cascade properly to both stores

Implementations§

Source§

impl<E: StorageEngine> VectorIndexCoordinator<E>

Source

pub fn new(engine: E) -> Self

Create a new coordinator.

§Arguments
  • engine - The storage engine
Source

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.

Source

pub fn vector_store(&self) -> &CollectionVectorStore<E>

Get a reference to the vector store.

Source

pub fn index_manager(&self) -> &Arc<HnswIndexManager<E>>

Get a reference to the index manager.

Source

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:

  1. Stores the vector in CollectionVectorStore
  2. Updates the HNSW index (if one exists for this named vector)
§Arguments
  • collection_id - The collection ID
  • entity_id - The entity ID
  • collection_name - Collection name for index lookup
  • vector_name - The vector name within the collection
  • data - The vector data to store
§Errors

Returns an error if storage or index update fails.

Source

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 ID
  • collection_name - Collection name for index lookup
  • vectors - List of (entity_id, vector_name, vector_data) tuples
Source

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.

Source

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.

Source

pub fn get_vector( &self, collection_id: CollectionId, entity_id: EntityId, vector_name: &str, ) -> Result<Option<VectorData>, VectorError>

Get a vector from storage.

Source

pub fn get_all_vectors( &self, collection_id: CollectionId, entity_id: EntityId, ) -> Result<HashMap<String, VectorData>, VectorError>

Get all vectors for an entity.

Source

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 search
  • vector_name - The named vector to search
  • query - The query embedding
  • k - Number of results to return
  • ef_search - Optional beam width (uses default if None)
§Returns

A list of search results with entity IDs and distances.

Source

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>
where F: Fn(EntityId) -> bool,

Search with a filter predicate.

The predicate is applied during graph traversal, not as a post-filter.

Source

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 ID
  • collection_name - Collection name for index lookup
  • vector_name - The named vector to rebuild
§Returns

The number of vectors indexed.

Source

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.

Source

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 persistence
  • collection - Collection name (e.g., “documents”)
  • vector_name - Vector name within the collection (e.g., “text_embedding”)
  • dimension - Vector dimension
  • distance_metric - Distance metric for similarity
  • config - HNSW configuration
§Returns

The name of the created index (e.g., “documents_text_embedding_hnsw”)

Source

pub fn drop_index( &self, engine: &E, index_name: &str, ) -> Result<bool, VectorError>

Drop an HNSW index.

Source

pub fn drop_collection_indexes( &self, engine: &E, collection: &str, ) -> Result<Vec<String>, VectorError>

Drop all HNSW indexes for a collection.

Source

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.

Source

pub fn load_index(&self, engine: E, index_name: &str) -> Result<(), VectorError>

Load an existing index into memory.

Source

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 index
  • collection_id - The collection ID
  • collection_name - Collection name
  • vector_name - The named vector to rebuild
§Returns

The number of vectors indexed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more