pub trait VectorStore: Send + Sync {
// Required methods
fn add<'life0, 'async_trait>(
&'life0 self,
id: String,
vector: Vec<f32>,
metadata: Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn query<'life0, 'life1, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ScoredDoc>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
A store of dense vectors that supports nearest-neighbour search.
Implementations associate an id and arbitrary metadata with each vector,
and answer top-k similarity queries. This module’s InMemoryVectorStore
ranks results by cosine similarity.
Implementations must be Send + Sync so they can be shared behind an
Arc.
Required Methods§
Sourcefn add<'life0, 'async_trait>(
&'life0 self,
id: String,
vector: Vec<f32>,
metadata: Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn add<'life0, 'async_trait>(
&'life0 self,
id: String,
vector: Vec<f32>,
metadata: Value,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Adds (or overwrites, when id already exists) a vector with associated
metadata.
Implementations should reject vectors whose dimensionality does not
match the vectors already stored (and zero-length vectors) with
TinyAgentsError::Validation,
so a store never mixes incomparable vectors.
Sourcefn query<'life0, 'life1, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ScoredDoc>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn query<'life0, 'life1, 'async_trait>(
&'life0 self,
vector: &'life1 [f32],
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<ScoredDoc>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Returns up to top_k documents most similar to vector, sorted by
descending similarity score.
Returns fewer than top_k documents when the store holds fewer entries,
and an empty Vec when top_k is 0 or the store is empty (an empty
store has no dimensionality to validate against, so any query vector is
answered with no hits). Implementations should reject a query vector
whose dimensionality does not match the stored vectors with
TinyAgentsError::Validation
instead of returning meaningless scores.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".