Skip to main content

VectorIndex

Trait VectorIndex 

Source
pub trait VectorIndex: Send + Sync {
    // Required methods
    fn add(&mut self, vectors: &[Vec<f32>]) -> Result<()>;
    fn add_with_ids(&mut self, vectors: &[Vec<f32>], ids: &[u64]) -> Result<()>;
    fn remove(&mut self, ids: &[u64]) -> Result<()>;
    fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchHit>>;
    fn search_filtered(
        &self,
        query: &[f32],
        k: usize,
        allowlist: &[u64],
    ) -> Result<Vec<SearchHit>>;
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;
    fn dim(&self) -> usize;
    fn save(&self, path: &Path) -> Result<()>;
}
Expand description

Trait for compressed vector indexes.

Implementations provide approximate nearest neighbor search with quantization-based compression. Follows the same pattern as EmbeddingProvider.

The trait is defined here with zero dependencies. Concrete implementations live in separate crates (e.g., llm-kernel-vector-index with TurboQuant).

This trait is fully object-safe — load is intentionally not included because it requires Self: Sized. Concrete types provide their own load inherent methods instead.

Required Methods§

Source

fn add(&mut self, vectors: &[Vec<f32>]) -> Result<()>

Add vectors with auto-assigned sequential IDs.

Source

fn add_with_ids(&mut self, vectors: &[Vec<f32>], ids: &[u64]) -> Result<()>

Add vectors with explicit external IDs.

Source

fn remove(&mut self, ids: &[u64]) -> Result<()>

Remove vectors by their external IDs.

IDs that do not exist in the index are silently ignored. Passing an empty slice is a no-op.

Source

fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchHit>>

Search for the k nearest neighbors of query.

Source

fn search_filtered( &self, query: &[f32], k: usize, allowlist: &[u64], ) -> Result<Vec<SearchHit>>

Search restricted to an allowlist of candidate IDs.

Useful for hybrid retrieval: first narrow candidates via BM25 or metadata filter, then dense-rerank within that set.

Source

fn len(&self) -> usize

Number of vectors currently indexed.

Source

fn is_empty(&self) -> bool

Whether the index is empty.

Source

fn dim(&self) -> usize

Vector dimensionality.

Source

fn save(&self, path: &Path) -> Result<()>

Persist the index to disk.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§