Expand description
§Mnemo
Mnemo is an encrypted, single-file, portable agent-memory engine.
A whole memory store — vectors, content, metadata, and the multi-signal recall machinery an agent needs — lives in one file you can copy, back up, or hand to another process. The file is encrypted at rest with a two-tier key hierarchy: an Argon2id key-encryption key (KEK) derived from a passphrase wraps a random data-encryption key (DEK), and the DEK encrypts every page with AES-256-GCM.
§Quick start
use mnemo_engine::{Mnemo, MnemoConfig, Memory, MemoryType, RecallRequest};
let cfg = MnemoConfig { dimensions: 3, ..Default::default() };
let mut db = Mnemo::create("agent.mnemo", "correct horse battery", cfg)?;
db.remember(
Memory::new("the user prefers dark mode", MemoryType::Semantic, vec![0.1, 0.2, 0.9])
.with_agent("assistant-1")
.with_importance(0.8),
)?;
db.flush()?;
let hits = db.recall(&RecallRequest::new(vec![0.1, 0.2, 0.9]).top_k(5))?;
for h in hits {
println!("{:.3} {}", h.score, h.memory.content);
}§What is and is not built
This crate implements a real, tested core: the encrypted single-file
storage engine, the crypto layer, the agent-memory model, multi-signal
recall, an IVF+PQ approximate-nearest-neighbour index, a write-ahead log,
snapshot-based point-in-time recovery, a bounded LRU page cache, and the
Session conversation wrapper. Exact brute-force search remains
available as the ground-truth baseline; a built index makes
Mnemo::recall sub-linear. Each Mnemo::flush is one atomic,
WAL-committed transaction and a restorable snapshot — Mnemo::restore_to
rewinds the database to any past transaction. Python and TypeScript
language bindings are the one documented roadmap item — see the README.
Modules§
- mcp
- Hand-rolled Model Context Protocol (MCP) stdio server for MNemo.
Structs§
- Build
Info - Build-time cryptographic backend information.
- Cache
Budget - Per-namespace eviction budget.
cache_putenforces both caps: on insert, the LRU is evicted until both live-entry count and live byte total fit under the caps. - Cache
PutOpts - Options accepted by
Mnemo::cache_put. Defaults describe an untyped, never-expiring, non-cost-hinted entry. - Cache
Stats - Summary statistics for a namespace (or the whole cache).
- Cached
Value - A returned cache hit.
accessed_at/access_countare updated on the directory before this is constructed, so the values here reflect the post-touch state (mirroring the recall-time convention). - Compact
Report - Result of a
Mnemo::compact_filerun. - Embed
Cmd - Persistent-child-process adapter for a user-supplied embedder command. See the module docs for the protocol.
- Embedder
Identity - Describe an embedder’s observable identity. Used both in-memory on
an open [
Mnemo] handle and persisted atmetadata.embedderon the scaffold manifest so that reopening with a different embedder is caught atset_embeddertime instead of silently polluting the index. - Index
Config - Tuning knobs for building and querying an [
IvfPqIndex]. - Index
Info - A read-only snapshot of an index’s shape, surfaced via
Mnemo::stats. - KdfParams
- Argon2id cost parameters. Stored (unencrypted) in the file header so the KEK can be re-derived on open.
- Memory
- A single memory entry.
- Mnemo
- An encrypted, single-file agent memory database.
- Mnemo
Config - Configuration for creating a new database.
- Recall
Request - A retrieval request for
Mnemo::recall. - Recall
Result - One scored result from
Mnemo::recall. - Score
Weights - Weights for the multi-signal recall score (scoring v2, shipped in v0.7.0).
- Semantic
Cache PutOpts - Options for
crate::Mnemo::cache_put_semantic. Same asCachePutOptsplus a requiredmodelstring — a hit from a different embedding model’s cache is a semantics bug, not a win, so the engine forces callers to declare the model and matches it on lookup. - Session
- A scoped conversation session over a
Mnemodatabase. - Snapshot
Info - A restorable point in a database’s history — see
Mnemo::snapshots. - Stats
- Summary statistics for a database.
- Turn
- One conversation turn, written to working memory by
Session::add_turn. - Ulid
- Re-export of
ulid::Ulid, the identifier type used for memories. A Ulid is a unique 128-bit lexicographically sortable identifier
Enums§
- Cache
Flush Policy - Per-handle flush policy for cache writes. Memory writes ignore this
and always behave as
Strict. - Memory
Type - The four kinds of agent memory.
- Metric
- Distance/similarity metric for vector comparison.
- Mnemo
Error - All errors the Mnemo engine can produce.
- Role
- Who produced a conversation turn.
- Scope
- Visibility of a memory across agents sharing one
.mnemofile.
Constants§
- DEFAULT_
BATCH_ MAX_ AGE - Default
max_ageforCacheFlushPolicy::Batched. - DEFAULT_
BATCH_ MAX_ DIRTY - Default
max_dirtyforCacheFlushPolicy::Batched. - DEFAULT_
EMBED_ TIMEOUT - Default per-request timeout. Set generously because a cold-start
sentence-transformerscall can genuinely take a few seconds the first time; configurable viaEmbedCmd::with_timeout(Rust API) or the--embed-timeoutCLI flag. - DEFAULT_
MAX_ BYTES - Default per-namespace byte budget (values + directory overhead).
Once exceeded,
cache_putevicts LRU until the total falls back under the cap. - DEFAULT_
MAX_ ENTRIES - Default per-namespace entry-count budget. Once a namespace holds this
many live entries,
cache_putevicts the LRU entry before inserting. - DEFAULT_
SEMANTIC_ THRESHOLD - Default similarity threshold for
crate::Mnemo::cache_get_semantic. Lookups below this are treated as misses. Chosen conservatively to avoid false hits on subtly-different prompts; callers can override per-lookup. Model-dependent — text-embedding-ada-002 and BGE at this threshold rarely surface unrelated content, but if you’re working with a lossier embedder consider raising it.
Traits§
- Embedder
- Minimal trait any embedder implementation must satisfy. Returns
vectors in the same order as the input
texts.
Functions§
- build_
info - Report this build’s cryptographic backend configuration.
Type Aliases§
- Result
- Convenience result alias used throughout the crate.