Skip to main content

VectorStore

Trait VectorStore 

Source
pub trait VectorStore: Send + Sync {
    // Required methods
    fn create_collection<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        name: &'life1 str,
        spec: &'life2 CollectionSpec,
    ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn delete_collection<'life0, 'life1, 'async_trait>(
        &'life0 self,
        name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn upsert<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        scope: &'life2 Scope,
        chunks: &'life3 [Chunk],
    ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn delete<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        scope: &'life2 Scope,
        ids: &'life3 [&'life4 str],
    ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             Self: 'async_trait;
    fn search<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        scope: &'life2 Scope,
        query: &'life3 VectorQuery<'life4>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             Self: 'async_trait;
    fn count<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        scope: &'life2 Scope,
        filter: Option<&'life3 Filter>,
    ) -> Pin<Box<dyn Future<Output = Result<u64, RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn delete_where<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        scope: &'life2 Scope,
        filter: &'life3 Filter,
    ) -> Pin<Box<dyn Future<Output = Result<u64, RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn purge_scope<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        scope: &'life2 Scope,
    ) -> Pin<Box<dyn Future<Output = Result<u64, RagError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
}
Available on crate feature rag only.
Expand description

A storage backend for vector embeddings with similarity search.

Implementations manage named collections of Chunks. Every operation on stored chunks names a Scope, and a stored chunk is identified by its collection, its scope, and its chunk ID together:

  • upsert replaces a chunk with the same ID in the same scope and never touches another scope’s chunk with that ID.
  • search considers only the scope’s chunks, applying the scope inside the backend’s search before the top k are chosen, so a small scope beside a large one still gets its nearest chunks.
  • delete, delete_where, count, and purge_scope act on the scope’s chunks only.

No operation reads, writes, or deletes across scopes, apart from delete_collection.

search, count, and delete_where take a Filter, which the backend compiles into its own query language with bound parameters or typed expressions and applies with the scope, before the top k are chosen. A backend that cannot express a filter returns RagError::UnsupportedFilter before any I/O, and so does every backend for a filter that fails Filter::validate.

§Example

use adk_rag::{Chunk, CollectionSpec, InMemoryVectorStore, Scope, VectorQuery, VectorStore};

let store = InMemoryVectorStore::new();
store.create_collection("docs", &CollectionSpec::new(2)).await?;

let tenant_a = Scope::new("tenant-a")?;
let tenant_b = Scope::new("tenant-b")?;
let chunk = Chunk::new("doc_0", "doc", "tenant a's text").with_embedding(vec![1.0, 0.0]);
store.upsert("docs", &tenant_a, &[chunk]).await?;

let query = VectorQuery::new(&[1.0, 0.0], 5);
assert_eq!(store.search("docs", &tenant_a, &query).await?.len(), 1);
assert!(store.search("docs", &tenant_b, &query).await?.is_empty());

Required Methods§

Source

fn create_collection<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, spec: &'life2 CollectionSpec, ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Create a named collection. No-op if it already exists.

Source

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

Delete a named collection and every scope’s data in it.

Source

fn upsert<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, collection: &'life1 str, scope: &'life2 Scope, chunks: &'life3 [Chunk], ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Upsert chunks into a scope of a collection. Chunks must have embeddings set.

Source

fn delete<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, collection: &'life1 str, scope: &'life2 Scope, ids: &'life3 [&'life4 str], ) -> Pin<Box<dyn Future<Output = Result<(), RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, Self: 'async_trait,

Delete a scope’s chunks by their IDs. Unknown IDs are ignored.

Source

fn search<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, collection: &'life1 str, scope: &'life2 Scope, query: &'life3 VectorQuery<'life4>, ) -> Pin<Box<dyn Future<Output = Result<Vec<SearchResult>, RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, Self: 'async_trait,

Search a scope for the query.top_k chunks most similar to query.embedding among those query.filter matches.

Returns results ordered by descending similarity score.

Source

fn count<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, collection: &'life1 str, scope: &'life2 Scope, filter: Option<&'life3 Filter>, ) -> Pin<Box<dyn Future<Output = Result<u64, RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

The number of chunks a scope holds in a collection, or of those filter matches.

Source

fn delete_where<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, collection: &'life1 str, scope: &'life2 Scope, filter: &'life3 Filter, ) -> Pin<Box<dyn Future<Output = Result<u64, RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Delete the scope’s chunks that filter matches, returning how many were deleted.

The count is taken as the delete starts on backends whose delete reports no count. purge_scope is the only way to delete a whole scope.

Source

fn purge_scope<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, collection: &'life1 str, scope: &'life2 Scope, ) -> Pin<Box<dyn Future<Output = Result<u64, RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Delete every chunk of a scope in a collection, returning how many it held.

The count is taken as the purge starts on backends whose delete reports no count.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§