Skip to main content

adk_memory/
service.rs

1use adk_core::{Content, Result};
2use async_trait::async_trait;
3use chrono::{DateTime, Utc};
4
5#[derive(Debug, Clone)]
6pub struct MemoryEntry {
7    pub content: Content,
8    pub author: String,
9    pub timestamp: DateTime<Utc>,
10}
11
12#[derive(Debug, Clone)]
13pub struct SearchRequest {
14    pub query: String,
15    pub user_id: String,
16    pub app_name: String,
17    /// Maximum number of results to return. `None` defaults to 10.
18    pub limit: Option<usize>,
19    /// Minimum similarity score threshold (0.0–1.0). Results below this
20    /// score are excluded. `None` means no threshold.
21    pub min_score: Option<f32>,
22}
23
24#[derive(Debug, Clone)]
25pub struct SearchResponse {
26    pub memories: Vec<MemoryEntry>,
27}
28
29#[async_trait]
30pub trait MemoryService: Send + Sync {
31    async fn add_session(
32        &self,
33        app_name: &str,
34        user_id: &str,
35        session_id: &str,
36        entries: Vec<MemoryEntry>,
37    ) -> Result<()>;
38    async fn search(&self, req: SearchRequest) -> Result<SearchResponse>;
39
40    /// Delete all memory entries for a specific user.
41    ///
42    /// Required for GDPR right-to-erasure compliance. Removes all stored
43    /// memories (including embeddings) for the given app and user.
44    async fn delete_user(&self, app_name: &str, user_id: &str) -> Result<()> {
45        let _ = (app_name, user_id);
46        Err(adk_core::AdkError::memory("delete_user not implemented"))
47    }
48
49    /// Delete all memory entries for a specific session.
50    async fn delete_session(&self, app_name: &str, user_id: &str, session_id: &str) -> Result<()> {
51        let _ = (app_name, user_id, session_id);
52        Err(adk_core::AdkError::memory("delete_session not implemented"))
53    }
54
55    /// Add a single memory entry directly (not tied to a session).
56    async fn add_entry(&self, app_name: &str, user_id: &str, entry: MemoryEntry) -> Result<()> {
57        let _ = (app_name, user_id, entry);
58        Err(adk_core::AdkError::memory("add_entry not implemented"))
59    }
60
61    /// Delete entries matching a query. Returns count of deleted entries.
62    async fn delete_entries(&self, app_name: &str, user_id: &str, query: &str) -> Result<u64> {
63        let _ = (app_name, user_id, query);
64        Err(adk_core::AdkError::memory("delete_entries not implemented"))
65    }
66
67    /// Verify backend connectivity.
68    ///
69    /// Returns `Ok(())` if the backend is reachable and responsive.
70    /// The default implementation always succeeds (suitable for in-memory).
71    async fn health_check(&self) -> Result<()> {
72        Ok(())
73    }
74}