Skip to main content

synaptic_vectorstores/
lib.rs

1mod in_memory;
2mod multi_vector;
3
4pub use in_memory::{InMemoryVectorStore, VectorStoreRetriever};
5pub use multi_vector::MultiVectorRetriever;
6
7use async_trait::async_trait;
8use synaptic_core::SynapticError;
9use synaptic_embeddings::Embeddings;
10use synaptic_retrieval::Document;
11
12/// Trait for vector storage backends.
13#[async_trait]
14pub trait VectorStore: Send + Sync {
15    /// Add documents to the store, computing their embeddings.
16    async fn add_documents(
17        &self,
18        docs: Vec<Document>,
19        embeddings: &dyn Embeddings,
20    ) -> Result<Vec<String>, SynapticError>;
21
22    /// Search for similar documents by query string.
23    async fn similarity_search(
24        &self,
25        query: &str,
26        k: usize,
27        embeddings: &dyn Embeddings,
28    ) -> Result<Vec<Document>, SynapticError>;
29
30    /// Search with similarity scores (higher = more similar).
31    async fn similarity_search_with_score(
32        &self,
33        query: &str,
34        k: usize,
35        embeddings: &dyn Embeddings,
36    ) -> Result<Vec<(Document, f32)>, SynapticError>;
37
38    /// Search by pre-computed embedding vector instead of text query.
39    async fn similarity_search_by_vector(
40        &self,
41        embedding: &[f32],
42        k: usize,
43    ) -> Result<Vec<Document>, SynapticError>;
44
45    /// Delete documents by ID.
46    async fn delete(&self, ids: &[&str]) -> Result<(), SynapticError>;
47}