adk_rag/vectorstore.rs
1//! Vector store trait for storing and searching vector embeddings.
2
3use async_trait::async_trait;
4
5use crate::document::{Chunk, SearchResult};
6use crate::error::Result;
7
8/// A storage backend for vector embeddings with similarity search.
9///
10/// Implementations manage named collections of [`Chunk`]s and support
11/// upserting, deleting, and searching by vector similarity.
12///
13/// # Example
14///
15/// ```rust,ignore
16/// use adk_rag::{VectorStore, InMemoryVectorStore};
17///
18/// let store = InMemoryVectorStore::new();
19/// store.create_collection("docs", 384).await?;
20/// store.upsert("docs", &chunks).await?;
21/// let results = store.search("docs", &query_embedding, 5).await?;
22/// ```
23#[async_trait]
24pub trait VectorStore: Send + Sync {
25 /// Create a named collection. No-op if it already exists.
26 async fn create_collection(&self, name: &str, dimensions: usize) -> Result<()>;
27
28 /// Delete a named collection and all its data.
29 async fn delete_collection(&self, name: &str) -> Result<()>;
30
31 /// Upsert chunks into a collection. Chunks must have embeddings set.
32 async fn upsert(&self, collection: &str, chunks: &[Chunk]) -> Result<()>;
33
34 /// Delete chunks by their IDs from a collection.
35 async fn delete(&self, collection: &str, ids: &[&str]) -> Result<()>;
36
37 /// Search for the `top_k` most similar chunks to the given embedding.
38 ///
39 /// Returns results ordered by descending similarity score.
40 async fn search(
41 &self,
42 collection: &str,
43 embedding: &[f32],
44 top_k: usize,
45 ) -> Result<Vec<SearchResult>>;
46}