Skip to main content

rs_adk/memory/
vertex_ai_memory_bank.rs

1//! Vertex AI Memory Bank service — stores and retrieves memories via Vertex AI Memory Bank.
2//!
3//! Mirrors ADK-Python's `vertex_ai_memory_bank_service`.
4
5use async_trait::async_trait;
6
7use super::{MemoryEntry, MemoryError, MemoryService};
8
9/// Configuration for Vertex AI Memory Bank service.
10#[derive(Debug, Clone)]
11pub struct VertexAiMemoryBankConfig {
12    /// Google Cloud project ID.
13    pub project: String,
14    /// Google Cloud location.
15    pub location: String,
16    /// Memory bank resource name.
17    pub memory_bank: String,
18}
19
20/// Memory service backed by Vertex AI Memory Bank.
21///
22/// Uses the Vertex AI Memory Bank API for structured memory
23/// storage and retrieval with automatic summarization.
24#[derive(Debug, Clone)]
25pub struct VertexAiMemoryBankService {
26    config: VertexAiMemoryBankConfig,
27}
28
29impl VertexAiMemoryBankService {
30    /// Create a new Vertex AI Memory Bank service.
31    pub fn new(config: VertexAiMemoryBankConfig) -> Self {
32        Self { config }
33    }
34
35    /// Returns the configured memory bank resource.
36    pub fn memory_bank(&self) -> &str {
37        &self.config.memory_bank
38    }
39}
40
41#[async_trait]
42impl MemoryService for VertexAiMemoryBankService {
43    async fn store(&self, _session_id: &str, _entry: MemoryEntry) -> Result<(), MemoryError> {
44        // In a real integration, calls the Memory Bank API to store.
45        Ok(())
46    }
47
48    async fn get(&self, _session_id: &str, _key: &str) -> Result<Option<MemoryEntry>, MemoryError> {
49        Ok(None)
50    }
51
52    async fn list(&self, _session_id: &str) -> Result<Vec<MemoryEntry>, MemoryError> {
53        Ok(vec![])
54    }
55
56    async fn search(
57        &self,
58        _session_id: &str,
59        _query: &str,
60    ) -> Result<Vec<MemoryEntry>, MemoryError> {
61        Ok(vec![])
62    }
63
64    async fn delete(&self, _session_id: &str, _key: &str) -> Result<(), MemoryError> {
65        Ok(())
66    }
67
68    async fn clear(&self, _session_id: &str) -> Result<(), MemoryError> {
69        Ok(())
70    }
71}
72
73#[cfg(test)]
74mod tests {
75    use super::*;
76
77    #[test]
78    fn service_metadata() {
79        let svc = VertexAiMemoryBankService::new(VertexAiMemoryBankConfig {
80            project: "test-project".into(),
81            location: "us-central1".into(),
82            memory_bank: "test-bank".into(),
83        });
84        assert_eq!(svc.memory_bank(), "test-bank");
85    }
86}