YourMemory
YourMemory
在 LoCoMo 上的召回率比 Mem0 高出 16pp。100% 的陈旧记忆精确度。为 AI 智能体提供受生物学启发的记忆衰减机制。
为 Claude 和任何兼容 MCP 的 AI 提供持久化记忆——其工作方式类似于人类记忆。重要的事物会留存,被遗忘的事物会消退,过时的信息会被自动清理。相关的记忆通过一个理解它们之间联系的图层保持更长时间的活跃。
处于早期阶段——欢迎提供反馈和建议。
基准测试
在公开的 LoCoMo 数据集(Snap Research)上与 Mem0(免费版)进行了对比评估——共 10 组对话,总计 200 组问答对。
指标 | YourMemory | Mem0 | 差距 |
LoCoMo Recall@5 (200 组问答对) | 34% | 18% | +16pp |
陈旧记忆精确度 (5 组矛盾对) | 100% | 0% | +100pp |
已清理记忆 (噪声减少) | 20% | 0% | — |
完整的评估方法和各样本结果请见 BENCHMARKS.md。 阅读文章:我使用艾宾浩斯遗忘曲线为 AI 智能体构建了记忆衰减机制
工作原理
艾宾浩斯遗忘曲线
base_λ = DECAY_RATES[category]
effective_λ = base_λ × (1 - importance × 0.8)
strength = importance × e^(-effective_λ × days) × (1 + recall_count × 0.2)
score = cosine_similarity × strength衰减率因类别而异——失败记忆消退得快,策略记忆留存更久:
类别 | 基础 λ | 无召回存活时间 | 用例 |
| 0.10 | ~38 天 | 有效的方法——成功的模式 |
| 0.16 | ~24 天 | 用户偏好、身份信息 |
| 0.20 | ~19 天 | 推断出的上下文 |
| 0.35 | ~11 天 | 出错的地方——特定环境下的错误 |
重要性会进一步调节每个类别内的衰减率。频繁召回的记忆会获得 recall_count 提升,从而抵消衰减。强度低于 0.05 的记忆会被自动清理。
混合向量 + 图引擎 (v1.3.0)
检索分为两轮运行:
第一轮 — 向量搜索: 对所有记忆进行余弦相似度计算。返回高于相似度阈值的 top-k 结果。
第二轮 — 图扩展: 从第一轮的种子节点开始进行 BFS 遍历。浮现出与顶级结果相关但相似度得分低于阈值的记忆——即那些共享上下文但不共享词汇的记忆。
recall("Python backend")
Round 1 → [1] Python/MongoDB (sim=0.61), [2] DuckDB/spaCy (sim=0.19)
Round 2 → [5] Docker/Kubernetes (sim=0.29, below cut-off but graph neighbour of [1])
surfaced via graph even though vector search missed it链式感知清理: 如果记忆的任何图邻居仍高于清理阈值,则该记忆会被保留。相关记忆共同老化——一个强大的记忆可以保护整个关联集群免于被删除。
召回传播: 召回一个记忆会自动提升其图邻居的 recall_count。频繁访问的记忆能保持其相关上下文的新鲜度。
语义边: 图的边是基于余弦相似度(阈值 ≥ 0.4)创建的,而不是基于插入顺序。边权重 = 由 spaCy 提取的 SVO 谓词的 similarity × verb_weight。
设置
无需基础设施——开箱即用,使用 DuckDB。两条命令即可完成。
支持 Python 3.11, 3.12, 3.13 和 3.14。
1. 安装
pip install yourmemory所有依赖项自动安装。无需克隆,无需 Docker,无需数据库设置。
2. 运行设置(仅一次)
yourmemory-setup下载 spaCy 语言模型并初始化数据库。安装后运行一次即可。
3. 获取配置
yourmemory-path打印您的完整可执行文件路径以及适用于任何 MCP 客户端的配置。复制它。
4. 连接到您的 AI 客户端
数据库会在首次使用时自动创建于 ~/.yourmemory/memories.duckdb。
Claude Code
添加到 ~/.claude/settings.json:
{
"mcpServers": {
"yourmemory": {
"command": "yourmemory"
}
}
}重新加载 Claude Code (Cmd+Shift+P → Developer: Reload Window)。
Cline (VS Code)
VS Code 不会继承您的 shell PATH。在终端运行此命令以获取要粘贴的确切配置:
yourmemory-path然后在 Cline → MCP Servers → Edit MCP Settings 中粘贴输出内容。它看起来像这样:
{
"mcpServers": {
"yourmemory": {
"command": "/full/path/to/yourmemory",
"args": [],
"env": {
"YOURMEMORY_USER": "your_name",
"DATABASE_URL": ""
}
}
}
}保存后重启 Cline。
Cursor
添加到 ~/.cursor/mcp.json:
{
"mcpServers": {
"yourmemory": {
"command": "/full/path/to/yourmemory",
"args": [],
"env": {
"YOURMEMORY_USER": "your_name",
"DATABASE_URL": ""
}
}
}
}Claude Desktop
添加到 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) 或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"yourmemory": {
"command": "yourmemory"
}
}
}重启 Claude Desktop。
任何兼容 MCP 的客户端
YourMemory 是一个标准的 stdio MCP 服务器。适用于 Claude Code, Claude Desktop, Cline, Cursor, Windsurf, Continue 和 Zed。如果客户端不继承 shell PATH,请使用 yourmemory-path 中的完整路径。
5. 将记忆指令添加到您的项目
将 sample_CLAUDE.md 复制到您的项目根目录并重命名为 CLAUDE.md,然后替换:
YOUR_NAME— 您的名字 (例如Alice)YOUR_USER_ID— 用于命名空间记忆 (例如alice)
Claude 现在将在每个任务中自动遵循“召回 → 存储 → 更新”的工作流程。
多智能体共享与私有记忆
多个 AI 智能体可以共享同一个 YourMemory 实例——每个智能体都有自己的身份、隔离的私有记忆以及对共享上下文的受控访问权限。
工作原理
每个记忆都有两个控制可见性的字段:
字段 | 值 | 含义 |
|
| 任何智能体(或用户)都可以召回此记忆 |
|
| 只有存储它的智能体才能召回它 |
| 例如 | 哪个智能体拥有此记忆 |
智能体使用 API 密钥(前缀 ym_)进行身份验证。如果没有密钥,调用者将被视为用户,并且只能读取/写入 shared 记忆。
注册智能体
from src.services.api_keys import register_agent
result = register_agent(
agent_id="coding-agent",
user_id="sachit",
description="Handles code review and refactoring tasks",
can_read=["shared", "private"], # what this agent can read
can_write=["shared", "private"], # what it can write
)
print(result["api_key"]) # ym_xxxx — save this, shown once only密钥在存储前会经过 SHA-256 哈希处理。明文永远不会被存储——如果丢失,请撤销并重新注册。
在 MCP 调用中使用 API 密钥
将 api_key 传递给任何 MCP 工具调用:
# Store a private memory — only this agent can recall it
store_memory(
content="The auth service on staging uses a self-signed cert — skip SSL verify",
importance=0.7,
category="failure",
api_key="ym_xxxx",
visibility="private"
)
# Store shared context — any agent can recall it
store_memory(
content="Production database is on PostgreSQL 16, us-east-1",
importance=0.8,
category="fact",
api_key="ym_xxxx",
visibility="shared"
)
# Recall — returns shared memories + this agent's private memories
recall_memory(
query="database production",
api_key="ym_xxxx"
)如果没有 api_key,召回操作将仅返回共享记忆。
访问控制
注册智能体时,can_read 控制智能体可以访问哪些可见性层级:
# Read-only agent — can see shared context but cannot store private memories
register_agent(
agent_id="readonly-summarizer",
user_id="sachit",
can_read=["shared"],
can_write=["shared"],
)
# Isolated agent — private memory only, cannot read shared context
register_agent(
agent_id="isolated-agent",
user_id="sachit",
can_read=["private"],
can_write=["private"],
)示例:两个智能体共享上下文
coding-agent stores:
→ "Sachit uses pytest for all Python tests" (shared, importance=0.8)
→ "Staging API key is sk-staging-xxx" (private, importance=0.9)
review-agent recalls "Python testing":
← "Sachit uses pytest for all Python tests" ✓ (shared — visible)
← "Staging API key is sk-staging-xxx" ✗ (private — hidden)
coding-agent recalls "Python testing":
← "Sachit uses pytest for all Python tests" ✓ (shared)
← "Staging API key is sk-staging-xxx" ✓ (private — owns it)撤销智能体
from src.services.api_keys import revoke_agent
revoke_agent(agent_id="coding-agent", user_id="sachit")
# Key is invalidated immediately — all future calls with it return 401MCP 工具
工具 | 调用时机 |
| 每个任务开始时——浮现相关上下文 |
| 学习到新的偏好、事实、失败或策略后 |
| 当召回的记忆过时或需要合并时 |
store_memory 接受一个可选的 category 参数来控制衰减率:
# Failure — decays in ~11 days (environment changes fast)
store_memory(
content="OAuth for client X fails — redirect URI must be app.example.com",
importance=0.6,
category="failure"
)
# Strategy — decays in ~38 days (successful patterns stay relevant)
store_memory(
content="Cursor pagination fixed the 30s timeout on large user queries",
importance=0.7,
category="strategy"
)示例会话
User: "I prefer tabs over spaces in all my Python projects"
Claude:
→ recall_memory("tabs spaces Python preferences") # nothing found
→ store_memory("Sachit prefers tabs over spaces in Python", importance=0.9, category="fact")
Next session:
→ recall_memory("Python formatting")
← {"content": "Sachit prefers tabs over spaces in Python", "strength": 0.87}
→ Claude now knows without being told again衰减作业
在启动时每 24 小时自动运行一次——无需 cron。强度低于 0.05 的记忆会被清理。
链式感知清理 (v1.3.0): 在删除衰减的记忆之前,衰减作业会检查其图邻居。如果任何邻居仍高于清理阈值,则该记忆会被保留。这防止了作为相关集群一部分的事实被孤立删除。
技术栈
DuckDB — 默认后端,零设置,原生向量相似度(质量与 pgvector 相同)
NetworkX — 默认图后端,零设置,持久化于
~/.yourmemory/graph.pklNeo4j — 可选的图后端,用于扩展:
pip install 'yourmemory[neo4j]',设置GRAPH_BACKEND=neo4jsentence-transformers — 本地嵌入 (
all-mpnet-base-v2, 768 维,无需外部服务)spaCy 3.8.13+ — 用于去重、分类和 SVO 三元组提取的本地 NLP(兼容 Python 3.11–3.14)
APScheduler — 自动 24 小时衰减作业
MCP — 通过模型上下文协议与 Claude 集成
PostgreSQL + pgvector — 可选,适用于团队/大型数据集
架构
Claude / Cline / Cursor / Any MCP client
│
├── recall_memory(query, api_key?)
│ └── embed → cosine similarity (Round 1)
│ → graph BFS expansion (Round 2)
│ → score = sim × strength → top-k
│ → recall propagation → boost graph neighbours
│
├── store_memory(content, importance, category?, api_key?, visibility?)
│ └── is_question? → reject
│ contradiction check → update existing if conflict
│ embed() → INSERT memories
│ → index_memory() → upsert graph node + semantic edges
│
└── update_memory(id, new_content, importance)
└── embed(new_content) → UPDATE memories
→ update graph node strength
Vector DB (Round 1) Graph DB (Round 2)
DuckDB (default) NetworkX (default)
memories.duckdb graph.pkl
├── embedding FLOAT[768] ├── nodes: memory_id, strength
├── importance FLOAT └── edges: sim × verb_weight ≥ 0.4
├── recall_count INTEGER
├── visibility VARCHAR Neo4j (opt-in, GRAPH_BACKEND=neo4j)
└── agent_id VARCHAR └── bolt://localhost:7687
Agent Registry
agent_registrations
├── agent_id VARCHAR
├── api_key_hash VARCHAR ← SHA-256, plaintext never stored
├── can_read [] ← ["shared"] | ["private"] | both
├── can_write []
└── revoked_at TIMESTAMPPostgreSQL (可选 — 适用于团队或大型数据集)
安装 Postgres 支持:
pip install yourmemory[postgres]然后创建一个 .env 文件:
DATABASE_URL=postgresql://YOUR_USER@localhost:5432/yourmemory后端会自动选择——DATABASE_URL 中为 postgresql:// → Postgres + pgvector,否则 → DuckDB。
macOS
brew install postgresql@16 pgvector && brew services start postgresql@16
createdb yourmemoryUbuntu / Debian
sudo apt install postgresql postgresql-contrib postgresql-16-pgvector
createdb yourmemory数据集参考
基准测试使用了 Snap Research 的 LoCoMo 数据集——这是一个用于多会话对话的公共长上下文记忆基准测试。
Maharana et al. (2024). LoCoMo: Long Context Multimodal Benchmark for Dialogue. Snap Research.
许可证
版权所有 2026 Sachit Misra
根据 CC-BY-NC-4.0 (知识共享署名-非商业性使用 4.0) 许可。
免费用于: 个人使用、教育、学术研究、开源项目。
不允许: 任何形式的商业用途——包括 SaaS、营利性公司的内部工具或付费服务——除非另有书面协议。
商业授权请联系:mishrasachit1@gmail.com
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sachitrafa/cognitive-ai-memory'
If you have feedback or need assistance with the MCP directory API, please join our Discord server