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§
Sourcefn 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 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,
Sourcefn 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 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,
Sourcefn 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_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.
Sourcefn 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 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.
Sourcefn 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 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.
Provided Methods§
Sourcefn embed_query(&self) -> Option<&dyn Embeddings>
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.
Sourcefn 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_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.
Sourcefn 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_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 tosimilarity_search.filter: Some(f)— returns only documents matching the filter, at mostkentries.
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 / …).
Sourcefn 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,
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 withscore >= t, at mostkentries.
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".