Skip to main content

VectorBackend

Trait VectorBackend 

Source
pub trait VectorBackend: Send + Sync {
    // Required methods
    fn insert(
        &mut self,
        id: &str,
        embedding: &[f32],
    ) -> Result<(), CodememError>;
    fn insert_batch(
        &mut self,
        items: &[(String, Vec<f32>)],
    ) -> Result<(), CodememError>;
    fn search(
        &self,
        query: &[f32],
        k: usize,
    ) -> Result<Vec<(String, f32)>, CodememError>;
    fn remove(&mut self, id: &str) -> Result<bool, CodememError>;
    fn save(&self, path: &Path) -> Result<(), CodememError>;
    fn load(&mut self, path: &Path) -> Result<(), CodememError>;
    fn stats(&self) -> VectorStats;
}
Expand description

Vector backend trait for HNSW index operations.

Required Methods§

Source

fn insert(&mut self, id: &str, embedding: &[f32]) -> Result<(), CodememError>

Insert a vector with associated ID.

Source

fn insert_batch( &mut self, items: &[(String, Vec<f32>)], ) -> Result<(), CodememError>

Batch insert vectors.

Source

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

Search for k nearest neighbors. Returns (id, distance) pairs.

Source

fn remove(&mut self, id: &str) -> Result<bool, CodememError>

Remove a vector by ID.

Source

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

Save the index to disk.

Source

fn load(&mut self, path: &Path) -> Result<(), CodememError>

Load the index from disk.

Source

fn stats(&self) -> VectorStats

Get index statistics.

Implementors§