Skip to main content
Glama
Smriti-AA

smriti

by Smriti-AA

Smriti

一个自托管的知识图谱与 AI 智能体记忆层 —— 单个二进制文件,单个 SQLite 文件,零云依赖。

LLM 维基的 Git。 原子化多写入事务、对每条声明强制执行来源追踪、带有哈希链的仅追加事件日志,以及完整性验证器 —— 确保智能体编写的知识在构建时即可审计。

2.5µs KV 检索 · 235ns 图遍历 · 0 云依赖

[screenshot: web-ui-dashboard.gif]

cargo install smriti

为什么选择 Smriti(对比 Obsidian / Zep / Mem0 / Letta / Neo4j)

特性

Obsidian

Zep

Mem0 / Letta

Neo4j / Graphiti

Smriti

单二进制,单文件,无服务器

✓*

✗

✗

✗

✓

完全本地 / 离线

✓

✗

✗

部分

✓

双时态边 (valid_from / valid_until)

✗

✓

✗

✓

✓

原子化多写入事务 (SAVEPOINT)

✗

✗

✗

✓ (服务器)

✓

对每条声明强制执行来源追踪

✗

✗

✗

✗

✓

仅追加事件日志 + 哈希链

✗

✓

✗

✗

✓

smriti verify 完整性扫描

✗

✗

✗

✗

✓

矛盾收件箱(从不自动解决)

✗

部分

✗

✗

✓

原生支持智能体 MCP

插件

✗

✗

✗

✓

* Obsidian 是一个没有事务保证的文件系统。Smriti 的护城河不是创新,而是在本地优先的 Rust 运行时中实现的写入时纪律。

研究基础

每一项完整性功能都引用了 arXiv 论文,以便您可以追溯设计至相关文献:

  • 双时态边与事件日志 T / T′ — Zep / Graphiti, arXiv:2501.13956

  • 结构重叠验证 (声明 ↔ 来源) — FACTUM, arXiv:2601.05866 和 Citation-Grounded Code Comprehension, arXiv:2512.12117

  • 矛盾置信度评分 — MemoTime, arXiv:2510.13614 和 EvoReasoner / EvoKG, arXiv:2509.15464

  • 信念修正与 memory_store 冲突策略 — AGM 公设, arXiv:2603.17244

  • 图 + BM25 混合检索 — Graph-Based Memory Survey, arXiv:2602.05665

  • 类型化图层 (语义/时间/因果) — MAGMA, arXiv:2601.03236

  • Zettelkasten 风格的智能体记忆 — A-MEM, arXiv:2502.12110 (NeurIPS 2025)

  • 幻觉归因要求 — arXiv:2510.24476

完整性层 (v0.2)

四个 MCP 工具将 Smriti 从一个 CRUD 存储转变为一个具有不变性的维基:

  • wiki_transaction_submit — 在 SQLite SAVEPOINT 内原子化应用一批创建/更新/链接/来源操作。每次内容写入必须携带 claim_spans 数组,否则将被拒绝(默认强制执行来源追踪)。

  • wiki_verify — 运行参照完整性检查 + 重新验证每条存储声明的重叠分数 + 遍历事件日志哈希链。返回通过/失败。从不修改数据。

  • contradictions_detect — 使用 w1·语义 + w2·时效性 + w3·权威性 加权评分对近期笔记进行两两扫描。候选矛盾进入审查收件箱 —— Smriti 从不自动解决。

  • contradictions_list — 审查收件箱。

CLI 镜像了所有这些功能:

smriti verify                    # integrity sweep
smriti pending-tx                # list transactions awaiting review
smriti commit-tx <id>            # commit a pending transaction
smriti reject-tx <id> -r "..."   # reject with reason
smriti detect-contradictions     # scan for candidates
smriti contradictions            # show review inbox

什么是 Smriti?

Smriti (梵语: स्मृति, 记忆) 是一个单一的 Rust 二进制文件,它在单个 SQLite 文件之上运行知识图谱、全文+语义搜索索引以及 MCP 服务器。它专为两类用户设计:希望拥有一个 AI 助手可以读取的私有“第二大脑”的知识工作者,以及需要为 AI 智能体提供持久化、结构化记忆层的开发者。

笔记通过类型化的维基链接相互连接 —— 在笔记中写入 [[rel:causal|决策 X]],Smriti 会自动在知识图谱中记录一条有向的 causal 边。智能体随后可以遍历该图来回答诸如“是什么导致了这个决策?”之类的问题,而无需重新阅读每一篇笔记。


快速开始

# Install
cargo install smriti

# Create your first notes — links and tags are extracted automatically
smriti new                    # interactive guided prompt
smriti create "Acme Corp" --content "Key client. Met via [[Sarah Chen]]." --tags client

# Search
smriti search "Acme"

# Open the web dashboard
smriti serve
# → http://localhost:3000

您的笔记、图谱和搜索索引位于 ~/.local/share/smriti/smriti.db。使用 cp 进行备份。


使用场景

客户知识图谱

将每个客户、联系人和互动记录为链接笔记。当您在通话前向 Claude 简要介绍时,它会读取完整的上下文 —— 历史记录、决策、待办事项 —— 而无需您重新解释任何内容。

smriti create "Acme Corp Q2 Review" \
  --content "Next steps: [[rel:temporal|Budget approval]] by June. Owner: [[Sarah Chen]]." \
  --tags client decision

决策日志

记录带有上下文和后果的决策。rel:causal 链接类型让智能体能够追踪决策背后的原因。

smriti create "Switched to Rust" \
  --content "Replaced Python service. Reason: [[rel:causal|Memory leak in prod]]." \
  --tags decision

每日 AI 上下文

将您当前的关注点存储在 KV 存储中。Claude 在每次会话开始时通过 MCP 读取它。

smriti serve   # then ask Claude: "what's my current focus?" — Smriti answers via MCP

SOP 与手册

将可重复的流程记录为链接笔记。通过一条命令导入现有的 Markdown 文件。

smriti import ./playbooks --recursive

MCP 集成

Smriti 作为 stdio 上的 MCP 服务器运行。将其添加到 claude_desktop_config.json 中:

{
  "mcpServers": {
    "smriti": {
      "command": "smriti",
      "args": ["mcp", "--db", "/path/to/smriti.db"]
    }
  }
}

对于 claude.ai 远程 MCP,启动 smriti serve 并将 MCP 客户端指向 http://localhost:3000/mcp。

MCP 工具

工具

功能

notes_create

创建笔记;自动提取 [[wiki-links]] 和 #tags

notes_read

按 ID 或标题读取笔记

notes_search

跨所有笔记进行全文 BM25 搜索

notes_list

列出近期笔记,按标签过滤

notes_graph

返回笔记周围的子图 (BFS,类型化边过滤)

notes_search_semantic

结合倒数排名融合 (RRF) 的向量 + FTS5 混合搜索

memory_store

存储键值对;支持 TTL 和冲突策略

memory_retrieve

按智能体 ID + 键检索存储的值

memory_list

列出智能体的所有记忆条目

memory_history

检索键的被覆盖值 (版本化记忆)

完整 MCP 参考:docs/mcp.md


性能

在 Apple Silicon 上使用 Criterion 在内存 SQLite 中测量。运行:cargo bench

操作

p50

插入 1 条笔记

32.5 µs

插入 100 条笔记

2.0 ms

插入 1,000 条笔记

23.1 ms

FTS5 搜索 — 1k 笔记

331 µs

FTS5 搜索 — 10k 笔记

2.86 ms

图构建 — 1k 节点

216 µs

BFS 深度-2 (缓存)

235 ns

BFS 深度-3 (缓存)

410 ns

内存 KV 存储 — 100 键

513 µs

内存 KV 检索 (命中)

2.48 µs

内存 KV 检索 (未命中)

2.25 µs

Smriti 与替代方案对比

Smriti

Mem0

Letta

Zep

自托管

是

否

是

部分

知识图谱

是 (petgraph)

否

否

是 (Neo4j)

类型化边

是

否

否

是

双时态边

是

否

否

是

信念修正

是 (AGM)

否

否

否

原生 MCP

是

否

否

否

全文搜索

FTS5 (BM25)

仅向量

仅向量

向量 + 关键词

混合搜索

是 (RRF)

否

否

否

KV 记忆 + TTL

是

否

是

是

语言

Rust

Python

Python

Python/Go

部署

单二进制

SaaS

Docker + Postgres

Docker + Neo4j + Redis

KV 检索延迟

~2.5 µs

~50–200 ms

~10–50 ms

~5–20 ms


架构

src/
├── models/     Note, Link, AgentMemory, ToolLog — Serde on every type
├── storage/    SQLite + FTS5 + sqlite-vec; WAL mode; single connection pool
├── parser/     [[wiki-link]] and #tag extraction via regex; no runtime deps
├── graph/      petgraph DiGraph; lazy GraphCache (Arc<RwLock>); typed BFS
├── mcp/        JSON-RPC 2.0 over stdio; dispatches to same handlers as REST
├── web/        Axum router; localhost-only CORS; embedded React SPA
├── cli/        clap v4 derive; 11 commands; shell completions; interactive new
├── sync/       WebDAV + filesystem sync with per-device conflict tracking
└── features/   Smart link suggestions; daily digest

设计决策

为什么选择 SQLite 而不是 Postgres。 个人或小团队的知识库不应需要运行数据库服务器。WAL 模式下的 SQLite 每秒可处理数百次并发读取 —— 对于任何个人知识图谱来说绰绰有余。整个数据库就是一个文件:备份就是 cp,迁移就是 mv。

为什么选择 Rust 而不是 Python。 智能体记忆位于每个工具调用的关键路径上。Python MCP 服务器通常会因序列化开销和 GIL 争用而增加每次往返 50–200 ms 的延迟。Smriti 的 Rust 实现可在 2.5 µs 内检索 KV 条目,使记忆操作对智能体的响应延迟不可见。

为什么选择 FTS5 + 向量,而不是二选一。 关键词搜索 (BM25) 对于已知术语非常精确;向量搜索可以召回用户未曾想到搜索的语义相关内容。两者单独使用都不够。Smriti 在查询时通过倒数排名融合将两者结合,并进行加权 —— 这符合 arXiv:2602.05665 的发现,即混合检索在多跳推理任务中优于纯向量检索。

memory_store 上的信念修正。 当智能体存储一个已存在的键时,简单的覆盖会丢弃历史记录。Smriti 实现了四种 AGM 冲突解决策略 (arXiv:2603.17244):overwrite (默认)、reject (如果存在则失败)、version_and_keep (归档旧值) 和 invalidate (标记旧值为被取代)。被取代的值可通过 memory_history 查询。

研究基础

论文

arXiv

在 Smriti 中的落地

Zep / Graphiti

2501.13956

links 表上的双时态边;LongMemEval 提升 18.5%

MAGMA

2601.03236

类型化图层;按 link_type 过滤的 BFS;Token 减少 95%

Graph-Native Belief Revision

2603.17244

memory_store 上的 ConflictPolicy 枚举

Graph-Based Memory Survey

2602.05665

带有倒数排名融合的 FTS5 + sqlite-vec 混合搜索


贡献

git clone https://github.com/smriti-AA/smriti.git
cd smriti
cargo test --all-features   # should be green
cargo bench                 # performance baseline

请参阅 CONTRIBUTING.md 了解开发工作流程。标记为 good first issue 的问题是独立的存储或 CLI 更改,不需要理解整个代码库。

在提交 PR 之前:运行 cargo clippy --all-features -- -D warnings 和 cargo fmt --check。


许可证

MIT

Related MCP Connectors