1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//! # adk-memory
//!
//! Semantic memory and search for ADK agents.
//!
//! ## Overview
//!
//! This crate provides long-term memory capabilities:
//!
//! - [`InMemoryMemoryService`] - Simple in-memory memory storage
//! - [`MemoryService`] - Trait for custom backends
//! - [`MemoryEntry`] - Structured memory with metadata
//! - [`MemoryServiceAdapter`] - Bridge to [`adk_core::Memory`] with optional project scope
//! - [`validate_project_id`] - Project identifier validation
//!
//! ## Quick Start
//!
//! ```rust
//! use adk_core::Content;
//! use adk_memory::{InMemoryMemoryService, MemoryEntry, MemoryService, SearchRequest};
//!
//! # #[tokio::main(flavor = "current_thread")]
//! # async fn main() -> adk_core::Result<()> {
//! let service = InMemoryMemoryService::new();
//! let entry = MemoryEntry::new(Content::new("user").with_text("Hometown: Nairobi."), "user");
//! service.add_session("app", "user", "session", vec![entry]).await?;
//!
//! let found = service
//! .search(SearchRequest {
//! query: "hometown".into(),
//! user_id: "user".into(),
//! app_name: "app".into(),
//! limit: None,
//! min_score: None,
//! project_id: None,
//! })
//! .await?;
//! assert_eq!(found.memories.len(), 1);
//! # Ok(())
//! # }
//! ```
//!
//! The runner attaches a memory service to each invocation (`ToolContext::search_memory`);
//! `adk-tool`'s `LoadMemoryTool` and `PreloadMemoryTool` (feature `memory-tools`) expose it
//! to the model.
//!
//! ## Project-Scoped Memory
//!
//! Memories can be isolated by project within a user. The isolation key is
//! `(app_name, user_id, project_id?)`:
//!
//! - **Global entries** (`project_id = None`): visible in all contexts.
//! - **Project entries** (`project_id = Some(id)`): visible only within that project.
//! - **Project search**: returns global + matching project entries.
//! - **Global search**: returns only global entries.
//!
//! ```rust,ignore
//! use adk_memory::{InMemoryMemoryService, MemoryService, MemoryServiceAdapter};
//! use std::sync::Arc;
//!
//! let service = Arc::new(InMemoryMemoryService::new());
//!
//! // Store entries in a project
//! service.add_session_to_project("app", "user", "sess", "my-project", entries).await?;
//!
//! // Adapter scoped to a project
//! let adapter = MemoryServiceAdapter::new(service, "app", "user")
//! .with_project_id("my-project");
//! ```
//!
//! ## Features
//!
//! - Per-user and per-project memory isolation
//! - Keyword search, and vector search with an `EmbeddingProvider` on PostgreSQL, MongoDB,
//! and Neo4j
//! - Backends: InMemory, SQLite, PostgreSQL, Redis, MongoDB, Neo4j, Vertex AI Memory Bank,
//! and the SQLite knowledge graph `GraphMemoryService`
//! - Versioned schema migrations
//! - `delete_user` and `export_user` across all projects, and [`MemorySubjectData`] for
//! `adk_core::subject::SubjectRights`
//! - Expiry on every backend: a per-entry expiry or a per-service default TTL, enforced on
//! read, purged by [`MemoryService::purge_expired`] (see [`expiry`]), and
//! [`MemoryService::delete_memory`] by id
//!
//! ## Feature flags
//!
//! The in-memory backend is always compiled; no feature is on by default.
//!
//! | Feature | Enables |
//! |---------|---------|
//! | `sqlite-memory` | The SQLite backend |
//! | `database-memory` | The PostgreSQL backend, with pgvector semantic search |
//! | `redis-memory` | The Redis backend |
//! | `mongodb-memory` | The MongoDB backend |
//! | `neo4j-memory` | The Neo4j backend |
//! | `vertex-memory` | Vertex AI Memory Bank on the Gemini Enterprise Agent Platform |
//! | `graph-memory` | `GraphMemoryService`, the SQLite knowledge graph; implies `sqlite-memory` |
//! | `embedding-trait` | The `EmbeddingProvider` trait without a vector backend |
//! | `conformance` | The `conformance` module and `memory_conformance_tests!`, the id and expiry suite for a backend's tests |
pub use MemoryServiceAdapter;
pub use ConsentGatedMemoryService;
pub use InMemoryMemoryService;
pub use ;
pub use MemorySubjectData;
pub use EmbeddingProvider;
pub use ;
pub use MongoMemoryService;
pub use Neo4jMemoryService;
pub use ;
pub use ;
pub use SqliteMemoryService;
pub use ;