pub trait VectorStore: Send + Sync {
// Required methods
fn add_documents<'a>(
&'a self,
documents: &'a [Document],
embeddings: &'a dyn Embeddings,
) -> BoxFuture<'a, Result<Vec<String>, SynwireError>>;
fn similarity_search<'a>(
&'a self,
query: &'a str,
k: usize,
embeddings: &'a dyn Embeddings,
) -> BoxFuture<'a, Result<Vec<Document>, SynwireError>>;
fn similarity_search_with_score<'a>(
&'a self,
query: &'a str,
k: usize,
embeddings: &'a dyn Embeddings,
) -> BoxFuture<'a, Result<Vec<(Document, f32)>, SynwireError>>;
fn delete<'a>(
&'a self,
ids: &'a [String],
) -> BoxFuture<'a, Result<(), SynwireError>>;
}Expand description
Trait for vector stores that persist and query document embeddings.
Implementations manage storage of documents alongside their embedding vectors and support similarity-based retrieval.
§Cancel safety
add_documents is not cancel-safe: dropping
the future mid-write may leave a partial set of documents persisted.
similarity_search and
similarity_search_with_score are
cancel-safe for read-only stores, but dropping mid-query may waste
compute. delete is not cancel-safe: partial
deletions are possible.
Required Methods§
Sourcefn add_documents<'a>(
&'a self,
documents: &'a [Document],
embeddings: &'a dyn Embeddings,
) -> BoxFuture<'a, Result<Vec<String>, SynwireError>>
fn add_documents<'a>( &'a self, documents: &'a [Document], embeddings: &'a dyn Embeddings, ) -> BoxFuture<'a, Result<Vec<String>, SynwireError>>
Add documents to the store, returning their assigned IDs.
Sourcefn similarity_search<'a>(
&'a self,
query: &'a str,
k: usize,
embeddings: &'a dyn Embeddings,
) -> BoxFuture<'a, Result<Vec<Document>, SynwireError>>
fn similarity_search<'a>( &'a self, query: &'a str, k: usize, embeddings: &'a dyn Embeddings, ) -> BoxFuture<'a, Result<Vec<Document>, SynwireError>>
Retrieve the k most similar documents to the query.
Sourcefn similarity_search_with_score<'a>(
&'a self,
query: &'a str,
k: usize,
embeddings: &'a dyn Embeddings,
) -> BoxFuture<'a, Result<Vec<(Document, f32)>, SynwireError>>
fn similarity_search_with_score<'a>( &'a self, query: &'a str, k: usize, embeddings: &'a dyn Embeddings, ) -> BoxFuture<'a, Result<Vec<(Document, f32)>, SynwireError>>
Retrieve the k most similar documents with their similarity scores.