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;

    // Provided methods
    fn needs_compaction(&self) -> bool { ... }
    fn ghost_count(&self) -> usize { ... }
    fn rebuild_from_entries(
        &mut self,
        _entries: &[(String, Vec<f32>)],
    ) -> Result<(), CodememError> { ... }
}
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.

Provided Methods§

Source

fn needs_compaction(&self) -> bool

Whether the index has accumulated enough ghost entries to warrant compaction.

Source

fn ghost_count(&self) -> usize

Number of ghost entries left by removals.

Source

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

Rebuild the index from scratch given all current entries.

Implementors§