Skip to main content

graphrag_core/vector/
store.rs

1use crate::core::Result;
2use async_trait::async_trait;
3use std::collections::HashMap;
4
5/// Result of a vector search
6#[derive(Debug, Clone)]
7pub struct SearchResult {
8    /// ID of the vector/document
9    pub id: String,
10    /// Similarity score (higher is better)
11    pub score: f32,
12    /// Metadata associated with the vector
13    pub metadata: HashMap<String, String>,
14}
15
16/// Abstract interface for vector storage backends
17#[async_trait]
18pub trait VectorStore: Send + Sync {
19    /// Initialize the collection/table
20    async fn initialize(&self) -> Result<()>;
21
22    /// Add a single vector with ID and metadata
23    async fn add_vector(
24        &self,
25        id: &str,
26        embedding: Vec<f32>,
27        metadata: HashMap<String, String>,
28    ) -> Result<()>;
29
30    /// Add multiple vectors in batch
31    async fn add_vectors_batch(
32        &self,
33        vectors: Vec<(&str, Vec<f32>, HashMap<String, String>)>,
34    ) -> Result<()>;
35
36    /// Search for nearest neighbors
37    async fn search(&self, query_embedding: &[f32], top_k: usize) -> Result<Vec<SearchResult>>;
38
39    /// Delete a vector by ID
40    async fn delete(&self, id: &str) -> Result<()>;
41}