aagt_core/knowledge/rag.rs
1//! RAG (Retrieval-Augmented Generation) Interfaces
2//!
3//! This module defines the standard interface for vector stores.
4//! Implementations (like Qdrant, Pinecone, Postgres) should be handled
5//! in the application layer (e.g. `listen-memory`), not here.
6
7use crate::error::Result;
8use async_trait::async_trait;
9use std::collections::HashMap;
10
11/// A document retrieved from the vector store
12#[derive(Debug, Clone)]
13pub struct Document {
14 /// Unique identifier
15 pub id: String,
16 /// The title or mnemonic for the document
17 pub title: String,
18 /// The full text content
19 pub content: String,
20 /// A shorter summary of the content (Tiered RAG)
21 pub summary: Option<String>,
22 /// The collection it belongs to
23 pub collection: Option<String>,
24 /// The virtual path/source
25 pub path: Option<String>,
26 /// Metadata associated with the document
27 pub metadata: HashMap<String, String>,
28 /// Similarity score (0.0 to 1.0)
29 pub score: f32,
30}
31
32/// Interface for vector stores
33#[async_trait]
34pub trait VectorStore: Send + Sync {
35 /// Store a text with metadata
36 /// Returns the ID of the stored document
37 async fn store(&self, content: &str, metadata: HashMap<String, String>) -> Result<String>;
38
39 /// Search for similar documents
40 async fn search(&self, query: &str, limit: usize) -> Result<Vec<Document>>;
41
42 /// Delete a document by ID
43 async fn delete(&self, id: &str) -> Result<()>;
44}
45
46/// Interface for embeddings providers
47/// (Optional: Application might handle embeddings manually)
48#[async_trait]
49pub trait Embeddings: Send + Sync {
50 /// Generate embedding vector for text
51 async fn embed(&self, text: &str) -> Result<Vec<f32>>;
52}