a maintained fork of CozoDB · v0.19.4
An embedded Datalog database for agent memory.
mnestic stores relations, graphs, and vectors in one transactional engine that runs inside your process. It continues CozoDB, which called itself “the hippocampus for AI,” and is tuned for recall: search by meaning, keyword, and link in one query, and keep the history of every fact if you want it.
MPL-2.0 · Rust and Python · RocksDB, SQLite, or in-memory storage
1# every memory reachable from a seed, then the 12 nearest by meaning2recall[to] := *recalls{ from: $seed, to }3recall[to] := recall[via], *recalls{ from: via, to }4 5?[memory, dist] :=6 recall[memory],7 ~memory:embedding{ memory |8 query: $cue, k: 12, ef: 80, bind_distance: dist9 }10:order dist11:limit 12Why a fork
CozoDB has had no release since December 2024. We forked it under the same MPL-2.0 license to keep it maintained and to tune it for agent memory. Every change from upstream is documented, and every original copyright is kept.
Compared with Postgres, DuckDB, and Neo4j.
Each is good at its own job. None of them does all of this inside your process: one request that searches by meaning, keyword, and link; long recursive chains; and a record of what used to be true.
| Postgres | DuckDB | Neo4j | mnestic | |
|---|---|---|---|---|
| Where it runs | Separate server | In your process | Separate server (JVM) | In your process, or as a server |
| Long chains of links | Recursive CTEs, slow as chains grow | Not supported | Good for paths, weaker for general recursive rules | Recursive Datalog rules |
| Meaning, keyword, and link search in one request | pgvector and full-text, combined by you | Vector and full-text extensions, no graph | Vector index, combined with the rest by you | One call, fused and ranked by the engine |
| What used to be true | Build it yourself | Build it yourself | Build it yourself | Built in, on two time axes |
Structural differences, not a speed test. Each column uses that database's official tooling: pgvector and full-text search for Postgres, the vector and full-text extensions for DuckDB, Cypher and the vector index for Neo4j.
What you get from CozoDB.
- Datalog, not SQL
- Queries compose rule by rule, and recursion is built in. A safe subset of aggregations works inside recursion.
- Relational, graph, and vector
- One data model covers all three. Graph structure is just relations and rules, so there is no separate property-graph schema to maintain.
- Embedded like SQLite
- Runs in your process with no server and no setup. It can also run as a server when you need one.
- Vector search
- Disk-resident HNSW indexes join Datalog directly, so a nearest-neighbour search can sit inside a recursive query and be filtered by any other rule.
- Full-text and near-duplicates
- BM25 full-text search and MinHash-LSH near-duplicate detection are part of the engine, not extensions.
- History on two time axes
- A relation can record when a fact was true and when the database learned it. Query either axis, or both.
Upstream measured 100K+ QPS on mixed read and write transactions, 250K+ QPS read-only, and under 1 ms for a two-hop query on a graph of 1.6M vertices and 31M edges (2020 Mac mini, RocksDB).
What the fork adds.
The query language is unchanged. The work has gone into query speed, correctness, and the operations agent memory needs. A few of the measured changes:
- 0.13.1Counts a join without building itLSQB q1 72.4 s → 1.05 s, q6 42.1 s → 0.31 s, same answers
- 0.10.5Reorders naive joins before running them54.5× on the reported query, results unchanged
- 0.11.0Caches a graph once for twelve algorithmsPageRank 15× and connected components 16× at 400k edges
- 0.19.2Faster writes and complete filtered vector searchupdate p50 300 → 20 ms; filtered recall 0.18 → 1.0 (SQLite, 40,000 rows)
- 0.12.0Fills a context window from the graph in one callcheapest-first expansion under a hard node budget, 2–4× faster than a host-side loop
- 0.10.0Returns the evidence behind each answerthe k best derivations per result, each with its chain of facts
- 0.12.1–0.13.0Fixes bugs inherited from upstreama failed commit reported as success, full-text postings leaking on update, timestamps silently stored as 1970, RocksDB options ignored on open
What did we believe in June about September?
Valid time is when a fact holds in the world. Transaction time is when the database learned it, and the engine stamps it at commit. With both, you can reproduce an old answer exactly and tell a change in the world apart from a correction.
- Transaction time is set by the engine, never by the caller, so history cannot be backdated.
- ::history, ::history_gc and ::evict manage the record; garbage collection keeps as-of reads exact.
- Opt-in per relation. Current-value reads run within about 4–12% of a plain relation.
1# opt in: valid time + an engine-stamped transaction time2:create beliefs {claim, vld: Validity, tt: TxTime => conf: Float}3 4# the engine stamps tt at commit; callers never set it5?[c, v, conf] <- [['q3 pipeline is healthy', '2026-09-01', 0.35]]6:put beliefs {c, v => conf}7 8# what did we believe on June 30 about September?9?[conf] := *beliefs{claim: 'q3 pipeline is healthy', conf10 @ (vt: '2026-09-01', tt: '2026-06-30')}11 12# the audit trail: every belief, correction, and cessation13::history beliefs [['q3 pipeline is healthy']]Vector, keyword, and graph search in one call.
hybrid_search runs all three searches in one transaction, merges them with reciprocal rank fusion, and can drop near-duplicates with MMR. Query vectors, text, and seeds go in as parameters, never as interpolated strings.
1use cozo::{DbInstance, GraphLeg, HybridSearch, MmrParams};2 3// HNSW + full-text + graph proximity in one call,4// fused with reciprocal rank fusion, then MMR.5let recalls = db.hybrid_search(&HybridSearch {6 relation: "memory".into(),7 vector_index: "embedding".into(),8 query_vector: cue, // Vec<f32> from your embedder9 vector_k: 24,10 ef: 80,11 fts_index: "summary_fts".into(),12 query_text: "pricing decision",13 fts_k: 24,14 // graph leg: expand 2 hops from a seed over *recalls,15 // ranked by hop distance and fused in the same call.16 graph_legs: vec![GraphLeg {17 edge_relation: "recalls".into(),18 seeds: vec![seed.into()],19 max_hops: 2,20 ..GraphLeg::default()21 }],22 rrf_k: 60.0,23 mmr: Some(MmrParams { lambda: 0.5, k: 12, embedding_col: "embedding".into() }),24 ..HybridSearch::default()25})?;Recall, measured.
On 40,000 chunks and 1,000 queries, mnestic's recall@10 is 0.954, level with DuckDB and far above LanceDB, which has no graph signal. The difference is where the work happens: mnestic fuses all three signals in one call, so a new memory is searchable on every signal the moment it is written.
| Engine | recall@10 | Signals | Fusion | Searchable right after a write |
|---|---|---|---|---|
| mnestic | 0.954 | vector, full-text, graph | in the engine, one call | 100% |
| duckdb 1.5.3 | 0.957 | vector, full-text, graph | in app code | 0% full-text † |
| sqlite 0.1.9 | 1.000* | vector, full-text, graph | in app code | 100% |
| lancedb 0.33 | 0.501 | vector, full-text | in the engine, no graph | n/a, no graph |
The fused call takes about 42 ms at p50, roughly 4× faster than running the same three searches separately. It is not the lowest latency in the table.
† DuckDB's full-text index is built once and misses new rows until it is rebuilt. *SQLite's recall comes from an exact brute-force scan, not an approximate index. 40k chunks, 1,000 queries, k=10, two-hop graph; 2026-05-31, macOS arm64; numbers are hardware-specific. Recall uses synthetic embeddings on the SQLite build; latency was checked separately on RocksDB with real sentence-transformer embeddings. Kùzu is excluded because its extension host has been offline since the project was archived in October 2025. Methodology · raw results
What it's for.
- Agent memory across sessions
- An agent needs to recall last week's decision by meaning, by exact words, and by what it is linked to. In mnestic that is the single query in the hero, and it sees writes from a second ago.
- Audit trails
- A transaction was rated low risk in June and looks wrong in September. With transaction time you can replay exactly what the system knew in June, and nobody can backdate it.
- Graphs without a second database
- Fraud rings share devices, addresses, and cards several hops from the flagged account. Recursive rules find those links in the same database that holds the rest of your data.
Add it to your project.
1# default: in-memory and SQLite storage2cargo add mnestic3 4# or, with RocksDB storage:5# mnestic = { version = "0.19", features = ["storage-rocksdb"] }1use cozo::DbInstance;2 3let db = DbInstance::new("mem", "", "")?;4db.run_default("?[x] := x in [1, 2, 3]")?;1pip install mnestic # the engine (abi3 wheels)2pip install langchain-mnestic # LangChain vector store3pip install llama-index-vector-stores-mnesticThe import name is still cozo
The crate is published as mnestic, but the library name is still cozo, so existing use cozo::… code and downstream crates compile without changes.
Attribution
mnestic is not the official CozoDB and is not affiliated with or endorsed by its authors. The original design is the work of Ziyang Hu and the Cozo Project Authors.