Skip to main content

VectorStore

Trait VectorStore 

Source
pub trait VectorStore: Send + Sync {
    // Required methods
    fn add_documents<'life0, 'async_trait>(
        &'life0 self,
        documents: Vec<Document>,
        embeddings: Vec<Vec<f32>>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn similarity_search<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query_embedding: &'life1 [f32],
        k: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_document<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Document>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_embedding<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<f32>>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete_document<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn count<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn embed_query(&self) -> Option<&dyn Embeddings> { ... }
    fn similarity_search_text<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
        k: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn similarity_search_with_filter<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        query_embedding: &'life1 [f32],
        k: usize,
        filter: Option<&'life2 MetadataFilter>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn similarity_search_with_min_score<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query_embedding: &'life1 [f32],
        k: usize,
        min_score: Option<f32>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Vector store trait.

Required Methods§

Source

fn add_documents<'life0, 'async_trait>( &'life0 self, documents: Vec<Document>, embeddings: Vec<Vec<f32>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Adds documents.

§Arguments
  • documents - Document list.
  • embeddings - Embedding vectors for documents.
§Returns

Document ID list.

Searches similar documents.

§Arguments
  • query_embedding - Query vector.
  • k - Number of documents to return.
§Returns

Similar document list (sorted by similarity descending).

Source

fn get_document<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Document>, VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets document by ID.

Source

fn get_embedding<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<f32>>, VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Gets document embedding by ID.

Source

fn delete_document<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Deletes document.

Source

fn count<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns document count.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clears store.

Provided Methods§

Source

fn embed_query(&self) -> Option<&dyn Embeddings>

Returns this vector store’s built-in text embedder, if any.

Q1: previously the trait only took query_embedding: &[f32], so callers had to embed the query themselves without a contract saying which embedder to use. With this getter, implementations that embed internally can accept text directly via similarity_search_text; those without one return None, and the caller gets an explicit error instead of silently using the wrong model.

Source

fn similarity_search_text<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, k: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Text similarity search: vectorizes query with the embedder returned by embed_query, then searches.

Returns VectorStoreError::EmbeddingError when no embedder is configured, suggesting similarity_search with a query vector instead.

Source

fn similarity_search_with_filter<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, query_embedding: &'life1 [f32], k: usize, filter: Option<&'life2 MetadataFilter>, ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Similarity search with metadata filtering.

  • filter: None — no filtering, equivalent to similarity_search.
  • filter: Some(f) — returns only documents matching the filter, at most k entries.

Default implementation: delegates to similarity_search when there is no filter; returns VectorStoreError::UnsupportedFilter when a filter is given but the backend does not override it, without silently ignoring the filter. Backends that support filtering should override this method and translate MetadataFilter into their native query syntax (Qdrant payload filter / Pinecone filter / Chroma where / …).

Source

fn similarity_search_with_min_score<'life0, 'life1, 'async_trait>( &'life0 self, query_embedding: &'life1 [f32], k: usize, min_score: Option<f32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, VectorStoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Similarity search with a minimum score threshold.

  • min_score: None — no filtering, returns the store’s full top-k (even negative scores).
  • min_score: Some(t) — returns only results with score >= t, at most k entries.

Q2: the default implementation re-filters the results of similarity_search, the best approximation for backends that cannot threshold directly at retrieval time. Implementations that compute similarity locally should override this method for the precise “filter first, then take top-k” semantics.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§