Skip to main content

VectorStore

Trait VectorStore 

Source
pub trait VectorStore: Send + Sync {
    // Required methods
    fn add_texts<'life0, 'async_trait>(
        &'life0 mut self,
        texts: Vec<String>,
        metadata: Option<Vec<HashMap<String, Value>>>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn add_vectors<'life0, 'async_trait>(
        &'life0 mut self,
        vectors: Vec<Vec<f32>>,
        texts: Vec<String>,
        metadata: Option<Vec<HashMap<String, Value>>>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn similarity_search<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
        k: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn similarity_search_by_vector<'life0, 'async_trait>(
        &'life0 self,
        query_vector: Vec<f32>,
        k: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 mut self,
        ids: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn len(&self) -> usize;

    // Provided methods
    fn similarity_search_with_filter<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
        k: usize,
        filter: &'life2 Filter,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

A vector store: holds documents + their embeddings, supports add + similarity search + delete.

Required Methods§

Source

fn add_texts<'life0, 'async_trait>( &'life0 mut self, texts: Vec<String>, metadata: Option<Vec<HashMap<String, Value>>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add documents (text + optional metadata). The store is responsible for embedding them. Returns the IDs assigned.

Source

fn add_vectors<'life0, 'async_trait>( &'life0 mut self, vectors: Vec<Vec<f32>>, texts: Vec<String>, metadata: Option<Vec<HashMap<String, Value>>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Add pre-embedded vectors directly. Useful when the caller has already paid the embedding cost.

Similarity search: embed the query, return top-k matches.

Source

fn similarity_search_by_vector<'life0, 'async_trait>( &'life0 self, query_vector: Vec<f32>, k: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Similarity search by pre-computed query vector.

Source

fn delete<'life0, 'async_trait>( &'life0 mut self, ids: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete documents by ID. IDs not found are silently ignored.

Source

fn len(&self) -> usize

Number of documents currently stored.

Provided Methods§

Source

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

Similarity search with a metadata filter.

Default impl runs similarity_search with k * 4 candidates and post-filters in the caller. Stores with native filter support (Qdrant, Pinecone, …) override for efficiency.

Source

fn is_empty(&self) -> bool

True if no documents are stored.

Implementors§