Skip to main content

Crate adk_memory

Crate adk_memory 

Source
Expand description

§adk-memory

Semantic memory and search for ADK agents.

§Overview

This crate provides long-term memory capabilities:

§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 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.

FeatureEnables
sqlite-memoryThe SQLite backend
database-memoryThe PostgreSQL backend, with pgvector semantic search
redis-memoryThe Redis backend
mongodb-memoryThe MongoDB backend
neo4j-memoryThe Neo4j backend
vertex-memoryVertex AI Memory Bank on the Gemini Enterprise Agent Platform
graph-memoryGraphMemoryService, the SQLite knowledge graph; implies sqlite-memory
embedding-traitThe EmbeddingProvider trait without a vector backend
conformanceThe 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 MemoryService to adk_core::Memory.
conformance
The MemoryService conformance 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 SubjectDataStore for adk_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 with harness.