将 CozoDB 分叉,为代理提供认知原语
1 分•作者: shanrizvi•大约 19 小时前
CozoDB 是由 Ziyang Hu 和 Cozo 项目作者创建的一个嵌入式关系-图-向量数据库。它在一个嵌入式引擎中集成了 Datalog、向量搜索(HNSW)和全文搜索,其愿景是成为“AI 的海马体”。不幸的是,该项目在 2024 年 12 月后便沉寂下来。KuzuDB,另一个具有类似 Cozo 的向量和全文索引的嵌入式图数据库,于 2025 年 10 月被归档。
我决定继续这一愿景,利用 Cozo 构建一个受神经科学启发的认知本体的记忆和推理基础。它涵盖了事件、认识结构、意图和行动,并支持多代理。一个使用您选择的 LLM 的提取管道,可以从文档和会话记录中提取这些信息,进行去重,并检测跨文档的矛盾。所有内容都经过版本控制,并可追溯到源文本块,支持时间旅行。
但是,我们最依赖的功能需要改进,所以我以相同的 MPL-2.0 许可证对 Cozo 进行硬分叉,创建了 MnesticDB,并进行了改进。
通过将 HNSW 索引从逐行构建改为扁平化并行构建,我在一个包含 40,000 个文本块和真实 384 维嵌入的语料库上,将索引构建时间从 89 秒减少到 8 秒,同时没有影响召回率。
我解决了索引重建期间的读取阻塞问题,以前重建一个包含 151,000 个 1536 维索引需要一个多小时;现在它可以在解锁状态下构建,在一个测试中,一个 40,000 向量的索引在 6 秒内完成构建,同时有 90,000 个并发读取。
我添加了跨语义(HNSW)、关键词(BM25)和图邻近信号的倒数排名融合,耗时约 42 毫秒,比单独运行三个查询快 4 倍。
在将默认全文评分器从 tf-idf 切换到 Okapi BM25 后,在一个 40,000 文本块的语料库上,融合召回率从 0.75 提高到 0.954,与 DuckDB 的 0.957 相当。
MnesticDB:https://www.mnesticdb.com https://www.github.com/shuruheel/mnestic
回到记忆和推理基础,我增加了对结构化数据的支持,允许用户连接 Postgres 数据库,从模式中起草一个操作本体,并将行同步为类型化图节点,带有溯源和按需实时字段,并与从文档中提取的认知本体融合到同一个图中。这使得代理可以通过一个接口查询业务表和从文档中提炼的知识,同时处理两者的矛盾和历史。
MindGraph:https://mindgraph.cloud/ https://www.github.com/shuruheel/mindgraph-rs
在 LongMemEval 的 60 个分层问题试点中,我们获得了 87% 的分数,零检索错误,强大的事实回忆(100%),以及强大的时间推理(90%)。遗漏集中在偏好问题(70%),我随后进行了修复,但尚未重新运行基准测试。计划是最终运行完整的 500 个问题测试,因为在当前样本量下置信区间相当宽。
我一直独自构建这个项目,这不是最优的,所以如果这引起了您的兴趣,请考虑成为 MnesticDB 项目的贡献者,或 MindGraph(代理的认知图基础)的联合创始人。
您可以在这里问我任何问题,或发送电子邮件至 shan@rizvi.nu。
查看原文
CozoDB is an embedded relational-graph-vector database created by Ziyang Hu and the Cozo Project authors. It does Datalog, vector search (HNSW), and full-text search in a single embedded engine and was created with the vision to be the “Hippocampus for AI”. Unfortunately, the project went quiet after December 2024. KuzuDB, another embedded graph database with vector and full-text indexes similar to Cozo, was archived in October 2025.<p>I decided to continue the vision by using Cozo to build a memory and reasoning substrate with a cognitive ontology inspired by neuroscience. It covers events, epistemic structure, intent, and action, with multi-agent support. An extraction pipeline using an LLM of your choice to extract these from documents and session transcripts, deduplicates them, and detects cross-document contradictions. Everything is versioned and provenanced back to source chunks, with time travel.<p>But the features we rely on most needed work, so I hard-forked Cozo as MnesticDB under the same MPL-2.0 license, and made improvements.<p>I reduced index build time from 89s to 8s on a 40,000 chunk corpus with real 384-dimension embeddings without affecting recall by rebuilding the HNSW index flat-and-parallel rather than row-by-row.<p>I unblocked reads during index rebuilds, which would take more than an hour for a 151,000 index with 1536 dimensions; it now builds off-lock, with a 40,000 vector index building under 6 seconds with 90,000 concurrent reads in one test.<p>I added reciprocal-rank fusion across semantic (HNSW), keyword (BM25), and graph proximity signals at around 42ms, 4x faster than the three queries running separately.<p>After switching the default full-text scorer from tf-idf to Okapi BM25, fused recall improved from 0.75 to 0.954 on a 40,000 chunk corpus, on par with DuckDB’s 0.957.<p>MnesticDB: https://www.mnesticdb.com https://www.github.com/shuruheel/mnestic<p>Returning to the memory and reasoning substrate, I added support for structured data, allowing users to connect a Postgres database, draft an operational ontology from the schema, and sync rows in as typed graph nodes, with provenance and on-demand live fields, fused into the same graph extracted as the cognitive ontology. This allows an agent to query business tables and knowledge distilled from documents through one interface, with contradictions and history on both.<p>MindGraph: https://mindgraph.cloud/ https://www.github.com/shuruheel/mindgraph-rs<p>In a 60-question stratified pilot of LongMemEval, we scored 87% with zero retrieval errors, strong factual recall (100%), and strong temporal reasoning (90%). The misses clustered in preference questions (70%), which I subsequently fixed, but haven’t re-run the benchmark yet. The plan is to eventually run the full 500-question run as the confidence interval is quite wide at the current sample size.<p>I’ve been building this solo, which is not optimal, so if this piques your interest, please consider becoming a contributor to the MnesticDB project, or a co-founder of MindGraph (the cognitive graph substrate for agents).<p>Ask me anything here, or email shan@rizvi.nu.