Engram: Persistent Memory for AI Agents
Engram gives you durable semantic memory that survives sessions, compaction, crashes. All local, no cloud, no token cost.
Boot Sequence (MANDATORY)
On every session start, run:
CODEBLOCK0
Example: INLINECODE0
This recalls relevant memories from previous sessions before you start work.
Storing Memories
5 memory types: fact | decision | preference | event | INLINECODE5
CODEBLOCK1
When to store:
- - Client status changes (churn risk, upsell opportunity, complaints)
- Important decisions made about projects/clients
- Facts learned during work (credentials, preferences, dates)
- Milestones completed (onboarding steps, launches)
Searching
Semantic search (finds meaning, not just keywords):
CODEBLOCK2
Context-Aware Recall
Recall ranks by: semantic similarity × recency × salience × access frequency
CODEBLOCK3
Better than search when you need the most relevant memories for a specific context.
Memory Relationships
7 relation types: related_to | supports | contradicts | caused_by | supersedes | part_of | INLINECODE12
CODEBLOCK4
Relations boost recall scoring — well-connected memories rank higher.
Auto-Extract from Text
Ingest extracts memories from raw text (rules-based by default, optionally LLM):
CODEBLOCK5
Uses memory types, tags, confidence scoring automatically.
Management
CODEBLOCK6
Memory Decay
Inspired by biological memory:
- - Every memory has salience (0.0 → 1.0)
- Daily decay:
salience *= 0.99 (configurable) - Accessing a memory boosts salience
- Low-salience memories fade from search results
- Nothing deleted — archived memories can be recovered
Agent Scoping
4 scope levels: global → agent → user → INLINECODE17
By default:
- - Agents see their own memories + global memories
- INLINECODE18 filters to specific agent
- Scope isolation prevents memory bleed between agents
REST API
Server runs at http://localhost:3400 (start with engram serve).
CODEBLOCK7
Dashboard: http://localhost:3400/dashboard (visual search, browse, delete, export)
MCP Integration
Engram works as an MCP server. Add to your MCP client config:
CODEBLOCK8
MCP tools: engram_add, engram_search, engram_recall, INLINECODE25
Configuration
INLINECODE26 :
CODEBLOCK9
Best Practices
- 1. Boot with recall — Always
engram search "<context>" --limit 10 at session start - Type everything — Use correct memory types for better recall ranking
- Tag generously — Tags enable filtering and cross-referencing
- Ingest conversations — Use
engram ingest after important exchanges - Let decay work — Don't store trivial facts; let important memories naturally stay salient
- Use relations —
auto-relate after adding interconnected memories - Scope by agent — Keep agent memories separate for clean context
Troubleshooting
Server not running?
CODEBLOCK10
Embeddings failing?
CODEBLOCK11
Want to reset?
rm -rf ~/.engram/memories.db ~/.engram/vectors.lance
engram serve # rebuilds from scratch
Created by: Danny Veiga (
@dannyveigatx)
Source: https://github.com/Dannydvm/engram-memory
Docs: https://github.com/Dannydvm/engram-memory/blob/main/README.md
Engram:AI代理的持久记忆
Engram为您提供持久的语义记忆,可跨越会话、压缩和崩溃而持续存在。完全本地运行,无需云端,无令牌成本。
启动序列(必读)
每次会话开始时,运行:
bash
engram search <当前任务上下文> --limit 10
示例:engram search 客户入职状态 流失风险 --limit 10
这会在您开始工作前,从之前的会话中调取相关记忆。
存储记忆
5种记忆类型: 事实 | 决策 | 偏好 | 事件 | 关系
bash
事实 — 客观信息
engram add API速率限制为100次/分钟 --type fact --tags api,limits
决策 — 已做出的选择
engram add 我们选择PostgreSQL而非MongoDB以获得更好的ACID支持 --type decision --tags database
偏好 — 用户/客户的喜好
engram add Steph博士更喜欢文字而非电话 --type preference --tags dr-steph,communication
事件 — 里程碑、日期
engram add 于2026年1月15日发布v2.0版本 --type event --tags launch,milestone
关系 — 人员、角色、联系
engram add Mia是客户经理,向Danny汇报 --type relationship --tags team,roles
何时存储:
- - 客户状态变化(流失风险、追加销售机会、投诉)
- 关于项目/客户的重要决策
- 工作中了解到的事实(凭证、偏好、日期)
- 完成的里程碑(入职步骤、发布)
搜索
语义搜索(寻找含义,而非仅关键词):
bash
基础搜索
engram search 数据库选择 --limit 5
按类型筛选
engram search 用户偏好 --type preference --limit 10
按代理筛选(仅查看您的记忆+全局记忆)
engram search 项目状态 --agent theo --limit 10
上下文感知召回
召回按以下维度排序:语义相似度 × 时效性 × 显著性 × 访问频率
bash
engram recall 设置新客户部署 --limit 10
当您需要特定上下文中最相关的记忆时,此功能优于搜索。
记忆关系
7种关系类型: 相关于 | 支持 | 矛盾 | 由...引起 | 取代 | 是...的一部分 | 引用
bash
手动建立关系
engram relate <记忆ID-1> <记忆ID-2> --type supports
通过语义相似度自动检测关系
engram auto-relate <记忆ID>
列出某个记忆的关系
engram relations <记忆ID>
关系可提升召回评分——关联性强的记忆排名更高。
从文本自动提取
摄取可从原始文本中提取记忆(默认基于规则,可选LLM):
bash
从标准输入
echo Mia确认客户满意。我们决定追加销售SEO服务。 | engram ingest
从命令
engram extract Sarah上周二加入担任CTO。偏好异步沟通。
自动使用记忆类型、标签和置信度评分。
管理
bash
统计信息(记忆数量、类型、存储大小)
engram stats
导出备份
engram export -o backup.json
导入备份
engram import backup.json
查看特定记忆
engram get <记忆ID>
软删除(保留用于审计)
engram forget <记忆ID> --reason 已过时
手动应用衰减(通常每日自动运行)
engram decay
记忆衰减
受生物记忆启发:
- - 每条记忆都有显著性(0.0 → 1.0)
- 每日衰减:显著性 *= 0.99(可配置)
- 访问记忆可提升显著性
- 低显著性记忆从搜索结果中淡出
- 不删除任何内容——归档的记忆可恢复
代理范围
4个范围级别: 全局 → 代理 → 用户 → 会话
默认情况下:
- - 代理可查看自己的记忆 + 全局记忆
- --agent <代理ID> 可筛选特定代理
- 范围隔离防止代理间记忆混淆
REST API
服务器运行在 http://localhost:3400(使用 engram serve 启动)。
bash
添加记忆
curl -X POST http://localhost:3400/api/memories \
-H Content-Type: application/json \
-d {content: ..., type: fact, tags: [x,y]}
搜索
curl http://localhost:3400/api/memories/search?q=query&limit=5
带上下文的召回
curl -X POST http://localhost:3400/api/recall \
-H Content-Type: application/json \
-d {context: ..., limit: 10}
统计信息
curl http://localhost:3400/api/stats
仪表盘: http://localhost:3400/dashboard(可视化搜索、浏览、删除、导出)
MCP集成
Engram可作为MCP服务器运行。添加到您的MCP客户端配置:
json
{
mcpServers: {
engram: {
command: engram-mcp
}
}
}
MCP工具: engramadd、engramsearch、engramrecall、engramforget
配置
~/.engram/config.yaml:
yaml
storage:
path: ~/.engram
embeddings:
provider: ollama # 或 openai
model: nomic-embed-text
ollama_url: http://localhost:11434
server:
port: 3400
host: localhost
decay:
enabled: true
rate: 0.99 # 每日衰减1%
archive_threshold: 0.1
dedup:
enabled: true
threshold: 0.95 # 去重的余弦相似度阈值
最佳实践
- 1. 启动时召回 — 会话开始时始终执行 engram search <上下文> --limit 10
- 正确分类 — 使用正确的记忆类型以获得更好的召回排名
- 充分添加标签 — 标签支持筛选和交叉引用
- 摄取对话 — 重要交流后使用 engram ingest
- 让衰减发挥作用 — 不存储琐碎事实;让重要记忆自然保持显著
- 使用关系 — 添加相互关联的记忆后执行 auto-relate
- 按代理划分范围 — 保持代理记忆分离以获得清晰上下文
故障排除
服务器未运行?
bash
engram serve &
或安装为守护进程:参见 ~/.engram/daemon/install.sh
嵌入失败?
bash
ollama pull nomic-embed-text
curl http://localhost:11434/api/tags # 验证Ollama是否运行
想要重置?
bash
rm -rf ~/.engram/memories.db ~/.engram/vectors.lance
engram serve # 从头重建
创建者: Danny Veiga (
@dannyveigatx)
来源: https://github.com/Dannydvm/engram-memory
文档: https://github.com/Dannydvm/engram-memory/blob/main/README.md