16 unstable releases (3 breaking)
Uses new Rust 2024
| new 0.4.0 | Mar 16, 2026 |
|---|---|
| 0.3.2 | Feb 21, 2026 |
| 0.2.1 | Jan 22, 2026 |
| 0.1.9 | Jan 3, 2026 |
| 0.1.1 | Nov 30, 2025 |
#2669 in Asynchronous
255 downloads per month
Used in adk-rust
245KB
4K
SLoC
adk-memory
Semantic memory and search for Rust Agent Development Kit (ADK-Rust) agents.
Overview
adk-memory provides long-term memory capabilities for the Rust Agent Development Kit (ADK-Rust):
- InMemoryMemoryService - Simple in-memory memory storage
- SqliteMemoryService - SQLite-backed persistence (
sqlite-memoryfeature) - PostgresMemoryService - PostgreSQL + pgvector persistence (
database-memoryfeature) - MongoMemoryService - MongoDB-backed persistence (
mongodb-memoryfeature) - Neo4jMemoryService - Neo4j-backed persistence (
neo4j-memoryfeature) - RedisMemoryService - Redis-backed persistence (
redis-memoryfeature) - MemoryService - Trait for custom storage backends
- Semantic Search - Query memories by content similarity
- Schema Migrations - Versioned, forward-only migrations for all database backends
Installation
[dependencies]
adk-memory = "0.4"
Or use the meta-crate:
[dependencies]
adk-rust = { version = "0.4", features = ["memory"] }
Quick Start
use adk_memory::{InMemoryMemoryService, MemoryService, MemoryEntry, SearchRequest};
use adk_core::Content;
use chrono::Utc;
let service = InMemoryMemoryService::new();
let entries = vec![
MemoryEntry {
content: Content::new("user").with_text("User prefers dark mode"),
author: "system".to_string(),
timestamp: Utc::now(),
},
];
service.add_session("my_app", "user_123", "session_456", entries).await?;
let response = service.search(SearchRequest {
query: "what theme does the user like?".to_string(),
user_id: "user_123".to_string(),
app_name: "my_app".to_string(),
}).await?;
for memory in response.memories {
println!("Found: {:?}", memory.content);
}
Feature Flags
| Feature | Backend | Description |
|---|---|---|
sqlite-memory |
SQLite | Single-node persistence via sqlx |
database-memory |
PostgreSQL | pgvector-backed semantic search |
redis-memory |
Redis | Low-latency in-memory persistence via fred |
mongodb-memory |
MongoDB | Document-oriented persistence |
neo4j-memory |
Neo4j | Graph database persistence |
# SQLite
adk-memory = { version = "0.4", features = ["sqlite-memory"] }
# PostgreSQL + pgvector
adk-memory = { version = "0.4", features = ["database-memory"] }
Schema Migrations
All database backends (SQLite, PostgreSQL, MongoDB, Neo4j) include a versioned migration system. Migrations are forward-only, idempotent, and tracked in a _schema_migrations registry table.
use adk_memory::SqliteMemoryService;
let service = SqliteMemoryService::new("sqlite:memory.db").await?;
// Run all pending migrations
service.migrate().await?;
// Check current schema version
let version = service.schema_version().await?;
println!("Schema version: {version}");
MemoryService Trait
#[async_trait]
pub trait MemoryService: Send + Sync {
async fn add_session(
&self,
app_name: &str,
user_id: &str,
session_id: &str,
entries: Vec<MemoryEntry>,
) -> Result<()>;
async fn search(&self, req: SearchRequest) -> Result<SearchResponse>;
}
Related Crates
- adk-rust - Meta-crate with all components
- adk-core - Core
Memorytrait - adk-runner - Memory injection during execution
- adk-rag - RAG pipeline with vector stores
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.
Dependencies
~7–30MB
~340K SLoC