使用说明
Engram——克劳德代码的持久记忆
你的AI会跨会话进行记忆。
会话结束时,Claude Code会忘记一切。 印迹 使用SQLite、局部语义嵌入和置信度加权检索在会话之间为其提供持久内存。API调用为零。一切都在本地运行。
建造于 Genesis平台 --与为我们的生产AI代理提供动力的内存架构相同。
它的作用
- 跨会话记忆 --事实、模式、教训、身份、项目背景
- 带背景的靴子 --一个调用在会话开始时加载所有相关内容
- 语义搜索 --通过意义而不仅仅是关键字来查找记忆
- 从反馈中学习 --告诉它什么有用,随着时间的推移,它会变得更聪明
- 基于标签的过滤 --按域(身份验证、后端、部署等)组织内存
- SQLite持久性 --快速、可靠,可处理数千个内存
- 本地嵌入 -MiniLM 384-dim矢量,零API调用,零成本
快速开始
1.克隆和安装
git clone https://github.com/bmbnexus/engram.git
cd engram
npm install
第一次运行下载嵌入模型(~100MB)。后续启动是即时的。
2.用克劳德代码注册
claude mcp add engram -- node /full/path/to/engram/server.js
3.验证
claude mcp list
# engram: connected
4.教克劳德代码使用它
打开Claude Code会话并说:
Add the following to your MEMORY.md file:
## Engram Memory
You have persistent memory via MCP server `engram` with 6 tools:
- `boot(topic)` — Run FIRST every session. Loads identity + context + health.
- `recall(query, tag)` — Search memory by meaning. Filter by tag.
- `store(content, layer, tags)` — Save to memory. L3=pattern, L5=fact, L6=identity.
- `learn(context_id, was_helpful)` — Give feedback after recalls.
- `introspect()` — Check memory health.
- `consolidate()` — Promote + prune + save. Run at session end.
On session start: boot(topic). During work: recall before decisions, store new knowledge.
After recalls: learn(contextId, true/false). Session end: consolidate.
Claude Code会将此添加到其MEMORY.md中,该文件会自动加载每个会话。
6工具
boot --用上下文唤醒
boot("auth system")
在一次调用中加载您的身份(L6)、最近的模式(L3)、与主题相关的记忆和系统健康状况。每次会话都先运行此程序。
recall --搜索你的记忆
recall("how does authentication work")
recall("deployment process", tag="devops")
recall("database schema", layer="L5", top_k=5)
返回带有置信度得分的排名结果。支持标签过滤和图层过滤。
store --保存内存
store("API uses JWT tokens with 24h expiry", layer="L5", tags=["auth", "backend"])
store("Always run migrations before deploying", layer="L3", tags=["deployment"])
store("I am the backend engineer for Team Alpha", layer="L6")
learn --训练系统
learn(context_id="ctx_abc123", was_helpful=true)
每次召回后,使用返回的 context_id 提供反馈。下次,有益的记忆会浮出水面。无用的会消失。
introspect --检查健康状况
introspect()
显示总内存、层分解、置信度平均值、检索统计数据。
consolidate --清理干净
consolidate()
促进高置信度模式(L3→ L5).删除旧的低置信度项目。在会话结束时运行。
内存层
| 图层 | 名称 | 此处内容 | 最大值 |
|---|---|---|---|
| L6 | 身份 | 你是谁,核心价值观,人际关系 | 100 |
| 第五层 | 事实 | 文件路径、体系结构、API合同、决策 | 2000 |
| 三级 | 模式 | 经验教训、陷阱、调试模式 | 500 |
标签
标签允许您按域组织记忆并过滤回忆:
store("Redis cache TTL is 300s", layer="L5", tags=["cache", "redis", "backend"])
recall("caching strategy", tag="redis")
好标签: auth, backend, frontend, database, deployment, testing, api, config
运作原理
Session Start
│
▼
┌─────────┐ ┌──────────────────────────────┐
│ boot() │────▶│ Load L6 identity │
└─────────┘ │ Load topic-relevant memories │
│ Load recent patterns │
│ Return everything in one call │
└──────────────────────────────┘
│
▼
During Session
│
▼
┌──────────┐ ┌──────────────────────────────┐
│ recall() │────▶│ Embed query (MiniLM 384-dim) │
└──────────┘ │ Score: similarity × recency │
│ × confidence × layer │
│ Return top K + context ID │
└──────────────────────────────┘
│
▼
┌──────────┐ ┌──────────────────────────────┐
│ learn() │────▶│ Adjust confidence up/down │
└──────────┘ │ Better results next time │
└──────────────────────────────┘
│
▼
┌──────────┐ ┌──────────────────────────────┐
│ store() │────▶│ Embed content + save to DB │
└──────────┘ │ Tagged, layered, searchable │
└──────────────────────────────┘
│
▼
Session End
│
▼
┌──────────────┐ ┌────────────────────────────┐
│ consolidate()│─▶│ Promote strong patterns │
└──────────────┘ │ Prune weak old memories │
│ Optimize database │
└────────────────────────────┘
所有数据都保存在本地SQLite数据库中(data/engram.db).没有API调用,没有云,没有遥测。
配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
ENGRAM_DATA_PATH |
./data |
SQLite数据库的目录 |
使用环境变量注册
claude mcp add engram -e ENGRAM_DATA_PATH=/custom/path -- node /path/to/engram/server.js
数据和备份
所有的记忆都存在 data/engram.db (SQLite)。
# Backup
cp data/engram.db data/engram.backup.db
# Restore
cp data/engram.backup.db data/engram.db
# Start fresh
rm data/engram.db
从v1(JSON)迁移
如果你使用了JSON存储的早期版本,你的记忆在 data/memory.json.Englam v2使用SQLite(data/engram.db).第一次运行时,v2会重新开始。要迁移旧记忆,请打开Claude Code会话并要求其阅读 data/memory.json 并使用 store 工具。
故障排除
“engram未连接”
使用绝对路径: claude mcp add engram -- node /home/you/engram/server.js
Recall返回0个结果
先储存一些记忆。系统开始为空。跑 introspect() 检查。
Claude Code不会自动使用内存 向MEMORY.md添加说明(请参阅快速入门步骤4)。
第一轮跑得很慢 嵌入模型下载一次(~100MB)。在那之后,开始是瞬间的。
需求
- Node.js >= 18
- 克劳德代码 支持MCP的CLI
- 磁盘: ~200MB(模型缓存+数据库)
- 猛撞: ~30MB(内存中的型号)
许可证
麻省理工学院——随心所欲地使用它。
建造于 Genesis平台 --本地第一AI代理。一次性购买,永远拥有。