cel-memory
Backend-agnostic memory traits and value types for AI agents.
cel-memory is the contract between an agent and an arbitrary persistence
layer. The trait is small enough to drop in your own backend (file, SQLite,
Redis, Mem0, Hindsight, etc.) without changing agent code. The companion
cel-memory-sqlite crate provides a local SQLite
implementation.
Purpose
Use cel-memory when agent code needs durable, scoped retrieval but should not
depend on a storage engine. Callers depend on MemoryProvider; backends decide
how chunks are stored, embedded, indexed, summarized, and aged. Attach a
Summarizer
with [BasicMemoryProvider::with_summarizer] to enable session summaries and rollups.
Status: v0.2.0 on crates.io — the MemoryProvider trait surface is stable. Two implementations ship against it: BasicMemoryProvider (in-crate, in-memory reference) and cel-memory-sqlite (SQLite + vector + FTS, hybrid retrieval). LLM summarizers live in cel-summarizer.
What's Included
MemoryProvidertrait — async interface every backend implements.- Value types:
MemoryChunk,ChunkKind,MemoryTier,MemoryQuery,MemorySession, etc. BasicMemoryProvider— in-memory reference impl. Useful for tests and as the conformance reference for new backends.MemoryWriteHooktrait — governance hook every backend should consult before persisting (lets a rule engine redact or veto writes).MemoryError— self-contained error type.
Out Of Scope
- Storage. See
cel-memory-sqlitefor SQLite + vector retrieval. - Embedding runtimes. The [
Embedder] trait is defined here; ONNX/fastembed backends ship in companion crates. - LLM-call retrieval logic. See
cel-brieffor "retrieve memory + assemble into an LLM prompt."
Example
use ;
use json;
let memory = new;
memory.write.await?;
let hits = memory.retrieve.await?;
Runnable examples:
basicuses the in-memory reference provider end to end.backend_swapshows application code written againstMemoryProvider.write_hookshows policy/redaction before persistence.custom_providershows a provider wrapper that implements the trait.
Implementing another backend
Storage engines (PostgreSQL, DuckDB, Redis, hosted vector DBs, etc.) belong in
separate crates that implement MemoryProvider.
Do not add drivers or SQL to this repo.
See BACKENDS.md for a phased implementation guide, schema
mapping from cel-memory-sqlite, retrieval expectations, and conformance
testing. Published community backends can be listed there and in the table below.
| Backend | Crate | Status |
|---|---|---|
| In-memory (reference) | cel-memory (BasicMemoryProvider) |
maintained here |
| SQLite + vector + FTS | cel-memory-sqlite |
maintained |
| PostgreSQL + pgvector | cel-memory-postgres |
starter (Phase 0–1) |
| your engine | your crate | community |
Upgrading from 0.1.x
0.2.0 moves Embedder
into this crate and removes the ChunkSource::Cortex alias. See the
0.2 migration guide.
Comparable libraries
| cel-memory | Hindsight | Mem0 | Letta | |
|---|---|---|---|---|
| Language | Rust | Python | Python | Python |
| Local-first | ✓ | ✓ | partial | ✓ |
| Pluggable backend | ✓ (trait) | partial | ✗ | ✗ |
| Governance hooks | ✓ | ✗ | ✗ | partial |
| Per-caller scoping | ✓ | ✗ | partial | partial |
| Sessions | ✓ | ✓ | ✓ | ✓ |
License
Apache-2.0