Skip to main content

VectorBackend

Trait VectorBackend 

Source
pub trait VectorBackend: Send + Sync {
    // Required methods
    fn dimensions(&self) -> usize;
    fn upsert(&self, id: &MemoryId, embedding: &[f32]) -> Result<()>;
    fn remove(&self, id: &MemoryId) -> Result<bool>;
    fn search(
        &self,
        query_embedding: &[f32],
        filter: &VectorFilter,
        limit: usize,
    ) -> Result<Vec<(MemoryId, f32)>>;
    fn count(&self) -> Result<usize>;
    fn clear(&self) -> Result<()>;
}
Expand description

Trait for vector layer backends.

Vector backends provide similarity search using embedding vectors. Implementations should be thread-safe (Send + Sync).

§Implementor Notes

  • Methods use &self to enable sharing via Arc<dyn VectorBackend>
  • Use interior mutability (e.g., Mutex<HashMap<K,V>>) for mutable state

§Dimensionality

All embeddings must match the backend’s dimensions(). The default FastEmbed model (all-MiniLM-L6-v2) produces 384-dimensional vectors.

Required Methods§

Source

fn dimensions(&self) -> usize

The dimensionality of embedding vectors.

Source

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

Inserts or updates an embedding for a memory.

Uses interior mutability for thread-safe concurrent access.

§Errors

Returns an error if the upsert operation fails.

Source

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

Removes an embedding by memory ID.

Uses interior mutability for thread-safe concurrent access.

§Errors

Returns an error if the removal operation fails.

Source

fn search( &self, query_embedding: &[f32], filter: &VectorFilter, limit: usize, ) -> Result<Vec<(MemoryId, f32)>>

Searches for similar embeddings.

Returns memory IDs with their cosine similarity scores (0.0 to 1.0), ordered by descending similarity.

§Arguments
  • query_embedding - The query vector to find similar embeddings for
  • filter - A VectorFilter for namespace/domain filtering and min score threshold
  • limit - Maximum number of results to return
§Errors

Returns an error if the search operation fails.

Source

fn count(&self) -> Result<usize>

Returns the total count of indexed embeddings.

§Errors

Returns an error if the count operation fails.

Source

fn clear(&self) -> Result<()>

Clears all embeddings.

Uses interior mutability for thread-safe concurrent access.

§Errors

Returns an error if the clear operation fails.

Implementors§