ruvector_core/
index.rs

1//! Index structures for efficient vector search
2
3pub mod flat;
4#[cfg(feature = "hnsw")]
5pub mod hnsw;
6
7use crate::error::Result;
8use crate::types::{DistanceMetric, SearchResult, VectorId};
9
10/// Trait for vector index implementations
11pub trait VectorIndex: Send + Sync {
12    /// Add a vector to the index
13    fn add(&mut self, id: VectorId, vector: Vec<f32>) -> Result<()>;
14
15    /// Add multiple vectors in batch
16    fn add_batch(&mut self, entries: Vec<(VectorId, Vec<f32>)>) -> Result<()> {
17        for (id, vector) in entries {
18            self.add(id, vector)?;
19        }
20        Ok(())
21    }
22
23    /// Search for k nearest neighbors
24    fn search(&self, query: &[f32], k: usize) -> Result<Vec<SearchResult>>;
25
26    /// Remove a vector from the index
27    fn remove(&mut self, id: &VectorId) -> Result<bool>;
28
29    /// Get the number of vectors in the index
30    fn len(&self) -> usize;
31
32    /// Check if the index is empty
33    fn is_empty(&self) -> bool {
34        self.len() == 0
35    }
36}