Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
了解更多 · 加入 Discord · 演示
| Benchmark | 旧版 | 新版 | Tokens | 延迟 p50 |
|---|---|---|---|---|
| LoCoMo | 71.4 | 92.5 | 7.0K | 0.88s |
| LongMemEval | 67.8 | 94.4 | 6.8K | 1.09s |
| BEAM (1M) | — | 64.1 | 6.7K | 1.00s |
| BEAM (10M) | — | 48.6 | 6.9K | 1.05s |
所有基准测试均在相同的、具有生产代表性的模型栈上运行。采用单次检索(一次调用,无 agentic 循环),检索预算为 top_200。分数反映的是 Mem0 托管平台的表现,其中包含开源 SDK 中不可用的专有优化;开源用户可预期方向相近的提升,但数值不会完全一致。
主要变更:
升级说明请参阅迁移指南。评估框架 已开源,任何人都可以复现这些数字。
Mem0("mem-zero")通过智能记忆层增强 AI 助手与 agent,实现个性化的 AI 交互。它能记住用户偏好、适应个人需求,并随时间持续学习——非常适合客服聊天机器人、AI 助手和自主系统。
核心能力:
应用场景:
AI agent 可在五秒内生成可用的 Mem0 API 密钥 —— 无需邮箱、无需控制台、无需 OTP。端到端只需四条命令:
# 1. Install
npm install -g @mem0/cli # or: pip install mem0-cli
# 2. Sign up as an agent (replace `claude-code` with your name)
mem0 init --agent --agent-caller claude-code
# 3. Add a memory
mem0 add "I am using mem0"
# 4. Search
mem0 search "am I using mem0"
人类所有者可稍后通过 mem0 init --email <their-email> 认领账户 —— 同一密钥,记忆完整保留。完整指南:以 Agent 身份注册.
| Library | Self-Hosted Server | Cloud Platform | |
|---|---|---|---|
| 最适合 | 测试、原型开发 | 在自有基础设施上运行的团队 | 零运维的生产使用 |
| 设置 | pip install mem0ai |
docker compose up |
在 app.mem0.ai 注册 |
| 控制台 | -- | 有 | 有 |
| 认证与 API 密钥 | -- | 有 | 有 |
| 高级功能 | -- | 预览 | 全部包含 |
只是测试?用 Library。为团队构建?选自托管。想要零运维?选 Cloud。
pip install mem0ai
如需增强型混合检索(BM25 关键词匹配与实体提取),请安装带 NLP 支持的版本:
pip install mem0ai[nlp]
python -m spacy download en_core_web_sm
通过 npm 安装 SDK:
npm install mem0ai
注意: 自托管认证默认开启。从启用认证前的版本升级?请设置
ADMIN_API_KEY,通过向导注册管理员,或仅在本地开发时使用AUTH_DISABLED=true。详见升级说明.
# Recommended: one command — start the stack, create an admin, issue the first API key.
cd server && make bootstrap
# Manual: start the stack and finish setup via the browser wizard.
cd server && docker compose up -d # http://localhost:3000
配置说明请参阅自托管文档。
在终端中管理记忆:
npm install -g @mem0/cli # or: pip install mem0-cli
mem0 init
mem0 add "Prefers dark mode and vim keybindings" --user-id alice
mem0 search "What does Alice prefer?" --user-id alice
完整命令参考请参阅 CLI 文档。
教会你的 AI 编程助手(Claude Code、Codex、Cursor、Windsurf、OpenCode、OpenClaw,以及任何支持 skills 标准的工具)如何使用 Mem0 进行开发。分为两类:
参考型 skills —— 始终开启(将 SDK 知识加载到助手上下文中):
npx skills add https://github.com/mem0ai/mem0 --skill mem0
npx skills add https://github.com/mem0ai/mem0 --skill mem0-cli
npx skills add https://github.com/mem0ai/mem0 --skill mem0-vercel-ai-sdk
流水线型 skills —— 按需运行(在现有仓库中执行端到端工作流):
npx skills add https://github.com/mem0ai/mem0 --skill mem0-integrate
npx skills add https://github.com/mem0ai/mem0 --skill mem0-test-integration
npx skills add https://github.com/mem0ai/mem0 --skill mem0-oss-to-platform
使用 /mem0-integrate 通过测试优先(test-first)流水线将 Mem0 接入现有仓库,然后使用 /mem0-test-integration 进行验证。使用 /mem0-oss-to-platform 将现有项目从 Mem0 OSS 迁移到托管版 Platform SDK。完整说明请参阅 skills 目录 或 Vibecoding with Mem0 for the full picture.
Mem0 需要 LLM 才能运行,默认使用来自 OpenAI 的 gpt-5-mini。不过它也支持多种 LLM;详情请参阅我们的 Supported LLMs documentation.
Mem0 默认使用来自 OpenAI 的 text-embedding-3-small 作为嵌入(embedding)模型。要在混合搜索(语义 + 关键词 + 实体加权)中获得最佳效果,我们建议至少使用 Qwen 600M 或同等级别的嵌入模型。配置详情请参阅 Supported Embeddings
第一步是实例化 memory:
from openai import OpenAI
from mem0 import Memory
openai_client = OpenAI()
memory = Memory()
def chat_with_memories(message: str, user_id: str = "default_user") -> str:
# Retrieve relevant memories
relevant_memories = memory.search(query=message, filters={"user_id": user_id}, top_k=3)
memories_str = "\n".join(f"- {entry['memory']}" for entry in relevant_memories["results"])
# Generate Assistant response
system_prompt = f"You are a helpful AI. Answer the question based on query and memories.\nUser Memories:\n{memories_str}"
messages = [{"role": "system", "content": system_prompt}, {"role": "user", "content": message}]
response = openai_client.chat.completions.create(model="gpt-5-mini", messages=messages)
assistant_response = response.choices[0].message.content
# Create new memories from the conversation
messages.append({"role": "assistant", "content": assistant_response})
memory.add(messages, user_id=user_id)
return assistant_response
def main():
print("Chat with AI (type 'exit' to quit)")
while True:
user_input = input("You: ").strip()
if user_input.lower() == 'exit':
print("Goodbye!")
break
print(f"AI: {chat_with_memories(user_input)}")
if __name__ == "__main__":
main()
详细的集成步骤请参阅 Quickstart 和 API Reference.
我们现在提供一篇可供引用的论文:
@article{mem0,
title={Mem0: Building Production-Ready AI Agents with Scalable Long-Term Memory},
author={Chhikara, Prateek and Khant, Dev and Aryan, Saket and Singh, Taranjeet and Yadav, Deshraj},
journal={arXiv preprint arXiv:2504.19413},
year={2025}
}
Apache 2.0 — 详情请参阅 LICENSE 文件。