Skip to main content

VectorIndex

Trait VectorIndex 

Source
pub trait VectorIndex: Send + Sync {
    // Required methods
    fn search(&self, query: &Embedding, k: usize) -> Vec<IndexResult>;
    fn len(&self) -> usize;
    fn name(&self) -> &'static str;
    fn dim(&self) -> usize;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn search_with_filter(
        &self,
        query: &Embedding,
        k: usize,
        filter: &dyn Fn(&str) -> bool,
    ) -> Vec<IndexResult> { ... }
}
Expand description

Trait for vector similarity search indexes Implementations must be thread-safe (Send + Sync) for use in async contexts like the sqlx store.

Required Methods§

Source

fn search(&self, query: &Embedding, k: usize) -> Vec<IndexResult>

Search for nearest neighbors

§Arguments
  • query - Query embedding vector (dimension depends on configured model)
  • k - Maximum number of results to return
§Returns

Results sorted by descending similarity score

Source

fn len(&self) -> usize

Number of vectors in the index

Source

fn name(&self) -> &'static str

Index type name (e.g., “HNSW”, “CAGRA”)

Source

fn dim(&self) -> usize

Embedding dimension of vectors in this index

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the index is empty

Source

fn search_with_filter( &self, query: &Embedding, k: usize, filter: &dyn Fn(&str) -> bool, ) -> Vec<IndexResult>

Search with traversal-time filtering.

The predicate receives a chunk_id and returns true to keep the candidate. HNSW overrides this with traversal-time filtering (skips non-matching nodes during graph walk). Default impl over-fetches and post-filters.

Implementors§