Skip to main content

VectorIndex

Trait VectorIndex 

Source
pub trait VectorIndex: Send + Sync {
    // Required methods
    fn upsert(&mut self, id: &str, embedding: &[f32]) -> Result<()>;
    fn remove(&mut self, id: &str) -> Result<()>;
    fn search(&self, query: &[f32], top_k: usize) -> Result<Vec<VectorHit>>;
    fn save(&self, path: &Path) -> Result<()>;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait for vector indexing and similarity search.

Required Methods§

Source

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

Add or update a vector in the index.

Source

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

Remove a vector from the index.

Source

fn search(&self, query: &[f32], top_k: usize) -> Result<Vec<VectorHit>>

Search for the top-k most similar vectors.

Source

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

Save the index to a file.

Source

fn len(&self) -> usize

Get the number of vectors in the index.

Provided Methods§

Source

fn is_empty(&self) -> bool

Check if the index is empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§