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§
Sourcefn add(&mut self, vectors: &[Vec<f32>]) -> Result<()>
fn add(&mut self, vectors: &[Vec<f32>]) -> Result<()>
Add vectors with auto-assigned sequential IDs.
Sourcefn add_with_ids(&mut self, vectors: &[Vec<f32>], ids: &[u64]) -> Result<()>
fn add_with_ids(&mut self, vectors: &[Vec<f32>], ids: &[u64]) -> Result<()>
Add vectors with explicit external IDs.
Sourcefn remove(&mut self, ids: &[u64]) -> Result<()>
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.
Sourcefn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchHit>>
fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchHit>>
Search for the k nearest neighbors of query.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".