Expand description
§adk-memory
Semantic memory and search for ADK agents.
§Overview
This crate provides long-term memory capabilities:
InMemoryMemoryService- Simple in-memory memory storageMemoryService- Trait for custom backendsMemoryEntry- Structured memory with metadataMemoryServiceAdapter- Bridge toadk_core::Memorywith optional project scopevalidate_project_id- Project identifier validation
§Quick Start
use adk_core::Content;
use adk_memory::{InMemoryMemoryService, MemoryEntry, MemoryService, SearchRequest};
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);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.
ⓘ
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
EmbeddingProvideron 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_userandexport_useracross all projects, andMemorySubjectDataforadk_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(seeexpiry), andMemoryService::delete_memoryby 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 |
Re-exports§
pub use adapter::MemoryServiceAdapter;pub use consent_gate::ConsentGatedMemoryService;pub use inmemory::InMemoryMemoryService;pub use service::MemoryEntry;pub use service::MemoryService;pub use service::SearchRequest;pub use service::SearchResponse;pub use service::UserMemory;pub use service::validate_project_id;pub use subject::MemorySubjectData;pub use embedding::EmbeddingProvider;pub use graph::CreateEntityInput;pub use graph::CreateRelationInput;pub use graph::Entity;pub use graph::GraphMemoryService;pub use graph::GraphSearchResult;pub use graph::Observation;pub use graph::Relation;pub use mongodb::MongoMemoryService;pub use neo4j::Neo4jMemoryService;pub use postgres::PostgresMemoryService;pub use postgres::PostgresMemoryServiceBuilder;pub use postgres::VectorIndexType;pub use redis::RedisMemoryConfig;pub use redis::RedisMemoryService;pub use sqlite::SqliteMemoryService;pub use vertex::VertexAiMemoryBankService;pub use vertex::VertexAiMemoryConfig;
Modules§
- adapter
- Adapter bridging
MemoryServicetoadk_core::Memory. - conformance
- The
MemoryServiceconformance suite for memory ids and expiry. - consent_
gate - A memory service that remembers nothing about a subject without its consent.
- embedding
- Embedding provider trait for vector-based memory search.
- expiry
- Memory expiry: the one rule every backend applies.
- graph
- Knowledge-graph-backed memory service.
- inmemory
- migration
- Lightweight, embedded migration runner for SQL-backed memory services.
- mongodb
- MongoDB memory service backed by MongoDB Atlas Vector Search.
- neo4j
- Neo4j memory service with graph-based contextual retrieval.
- postgres
- PostgreSQL memory service implementation with pgvector.
- redis
- Redis-backed memory service.
- service
- sqlite
- SQLite-backed memory service.
- subject
- Memory as a
SubjectDataStoreforadk_core::subject::SubjectRights. - text
- Shared text extraction utilities for memory backends.
- vertex
- Vertex AI Agent Engine Memory Bank backend.
Macros§
- memory_
conformance_ tests - Expands to one
#[tokio::test]per check of the suite, each opening the backend withharness.