pub trait VectorIndex:
Send
+ Sync
+ Debug {
// Required methods
fn add(&mut self, id: String, vector: &[f32]) -> Result<()>;
fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>;
fn remove(&mut self, id: &str) -> Result<bool>;
fn contains(&self, id: &str) -> bool;
fn len(&self) -> usize;
fn dimension(&self) -> usize;
fn distance_type(&self) -> DistanceType;
fn clear(&mut self);
fn memory_usage(&self) -> usize;
// Provided methods
fn add_batch(
&mut self,
ids: Vec<String>,
vectors: &[Vec<f32>],
) -> Result<()> { ... }
fn search_with_ids(
&self,
query: &[f32],
k: usize,
ids: &[String],
) -> Result<Vec<SearchResult>> { ... }
fn is_empty(&self) -> bool { ... }
}Expand description
Core trait for vector indexes.
All index implementations must implement this trait.
Required Methods§
Sourcefn distance_type(&self) -> DistanceType
fn distance_type(&self) -> DistanceType
Distance type used by this index.
Sourcefn memory_usage(&self) -> usize
fn memory_usage(&self) -> usize
Get memory usage estimate in bytes.
Provided Methods§
Sourcefn add_batch(&mut self, ids: Vec<String>, vectors: &[Vec<f32>]) -> Result<()>
fn add_batch(&mut self, ids: Vec<String>, vectors: &[Vec<f32>]) -> Result<()>
Add multiple vectors in batch.
Default implementation calls add repeatedly.
Sourcefn search_with_ids(
&self,
query: &[f32],
k: usize,
ids: &[String],
) -> Result<Vec<SearchResult>>
fn search_with_ids( &self, query: &[f32], k: usize, ids: &[String], ) -> Result<Vec<SearchResult>>
Search with pre-filter (IDs to consider).
Default implementation searches all, then filters.