VectorIndex

Trait VectorIndex 

Source
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§

Source

fn add(&mut self, id: String, vector: &[f32]) -> Result<()>

Add a vector to the index.

§Arguments
  • id - Unique identifier for the vector
  • vector - The vector to index
§Errors

Returns error if dimension mismatch or capacity exceeded.

Source

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

Search for k nearest neighbors.

§Arguments
  • query - Query vector
  • k - Number of neighbors to return
§Returns

Vector of search results, sorted by distance (ascending).

Source

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

Remove a vector from the index.

§Returns

true if vector was found and removed, false otherwise.

Source

fn contains(&self, id: &str) -> bool

Check if ID exists in index.

Source

fn len(&self) -> usize

Number of vectors in the index.

Source

fn dimension(&self) -> usize

Vector dimension.

Source

fn distance_type(&self) -> DistanceType

Distance type used by this index.

Source

fn clear(&mut self)

Clear all vectors from the index.

Source

fn memory_usage(&self) -> usize

Get memory usage estimate in bytes.

Provided Methods§

Source

fn add_batch(&mut self, ids: Vec<String>, vectors: &[Vec<f32>]) -> Result<()>

Add multiple vectors in batch.

Default implementation calls add repeatedly.

Source

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.

Source

fn is_empty(&self) -> bool

Whether the index is empty.

Implementors§