276 lines
12 KiB
Markdown
276 lines
12 KiB
Markdown
<!-- WEHUB_ZH_README -->
|
||
> [!NOTE]
|
||
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
|
||
> [English](./README.en.md) · [原始项目](https://github.com/mem0ai/mem0) · [上游 README](https://github.com/mem0ai/mem0/blob/HEAD/README.md)
|
||
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
|
||
|
||
<p align="center">
|
||
<a href="https://github.com/mem0ai/mem0">
|
||
<img src="docs/images/banner-sm.png" width="800px" alt="Mem0 - 面向个性化 AI 的记忆层">
|
||
</a>
|
||
</p>
|
||
<p align="center" style="display: flex; justify-content: center; gap: 20px; align-items: center;">
|
||
<a href="https://trendshift.io/repositories/11194" target="blank">
|
||
<img src="https://trendshift.io/api/badge/repositories/11194" alt="mem0ai%2Fmem0 | Trendshift" width="250" height="55"/>
|
||
</a>
|
||
</p>
|
||
|
||
<p align="center">
|
||
<a href="https://mem0.ai">了解更多</a>
|
||
·
|
||
<a href="https://mem0.dev/DiG">加入 Discord</a>
|
||
·
|
||
<a href="https://mem0.dev/demo">演示</a>
|
||
</p>
|
||
|
||
<p align="center">
|
||
<a href="https://mem0.dev/DiG">
|
||
<img src="https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white" alt="Mem0 Discord">
|
||
</a>
|
||
<a href="https://pepy.tech/project/mem0ai">
|
||
<img src="https://img.shields.io/pypi/dm/mem0ai" alt="Mem0 PyPI - 下载量">
|
||
</a>
|
||
<a href="https://github.com/mem0ai/mem0">
|
||
<img src="https://img.shields.io/github/commit-activity/m/mem0ai/mem0?style=flat-square" alt="GitHub 提交活动">
|
||
</a>
|
||
<a href="https://pypi.org/project/mem0ai" target="blank">
|
||
<img src="https://img.shields.io/pypi/v/mem0ai?color=%2334D058&label=pypi%20package" alt="包版本">
|
||
</a>
|
||
<a href="https://www.npmjs.com/package/mem0ai" target="blank">
|
||
<img src="https://img.shields.io/npm/v/mem0ai" alt="Npm 包">
|
||
</a>
|
||
<a href="https://www.ycombinator.com/companies/mem0">
|
||
<img src="https://img.shields.io/badge/Y%20Combinator-S24-orange?style=flat-square" alt="Y Combinator S24">
|
||
</a>
|
||
</p>
|
||
|
||
<p align="center">
|
||
<a href="https://mem0.ai/research"><strong>📄 Mem0 高 Token 效率记忆算法基准测试 →</strong></a>
|
||
</p>
|
||
|
||
## 新记忆算法(2026 年 4 月)
|
||
|
||
| 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 中不可用的专有优化;开源用户可预期方向相近的提升,但数值不会完全一致。
|
||
|
||
**主要变更:**
|
||
- **单次 ADD-only 提取** -- 一次 LLM 调用,无 UPDATE/DELETE。记忆持续累积;不会被覆盖。
|
||
- **Agent 生成的事实为一等公民** -- 当 agent 确认某项操作时,该信息现在会以同等权重存储。
|
||
- **实体链接(Entity linking)** -- 提取实体、进行嵌入,并在各条记忆间建立链接以提升检索效果。
|
||
- **多信号检索(Multi-signal retrieval)** -- 语义、BM25 关键词与实体匹配并行评分并融合。
|
||
- **时序推理(Temporal Reasoning)** -- 具备时间感知的检索,针对当前状态、过往事件和即将发生的计划类查询,对正确日期的实例进行排序。
|
||
|
||
升级说明请参阅[迁移指南](https://docs.mem0.ai/migration/oss-v2-to-v3)。[评估框架](https://github.com/mem0ai/memory-benchmarks) 已开源,任何人都可以复现这些数字。
|
||
|
||
## 研究亮点
|
||
- **LoCoMo 得分 92.5** -- 较上一版算法提升 21 分
|
||
- **LongMemEval 得分 94.4** -- 提升 27 分,assistant 记忆召回达 98.2
|
||
- **BEAM (1M) 得分 64.1** -- 在 1M tokens 规模下的生产级记忆评估
|
||
- [阅读完整论文](https://mem0.ai/research)
|
||
|
||
# 简介
|
||
|
||
[Mem0](https://mem0.ai)("mem-zero")通过智能记忆层增强 AI 助手与 agent,实现个性化的 AI 交互。它能记住用户偏好、适应个人需求,并随时间持续学习——非常适合客服聊天机器人、AI 助手和自主系统。
|
||
|
||
### 核心特性与用例
|
||
|
||
**核心能力:**
|
||
- **多级记忆(Multi-Level Memory)**:无缝保留 User、Session 与 Agent 状态,并支持自适应个性化
|
||
- **开发者友好**:直观的 API、跨平台 SDK,以及完全托管的服务选项
|
||
|
||
**应用场景:**
|
||
- **AI 助手**:一致且上下文丰富的对话
|
||
- **客户支持**:回忆历史工单与用户记录,提供定制化帮助
|
||
- **医疗健康**:跟踪患者偏好与病史,实现个性化护理
|
||
- **生产力与游戏**:基于用户行为自适应工作流与环境
|
||
|
||
## 🚀 快速入门指南 <a name="quickstart"></a>
|
||
|
||
### 以 Agent 身份注册
|
||
|
||
AI agent 可在五秒内生成可用的 Mem0 API 密钥 —— 无需邮箱、无需控制台、无需 OTP。端到端只需四条命令:
|
||
|
||
```bash
|
||
# 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 身份注册](https://docs.mem0.ai/platform/agent-signup).
|
||
|
||
| | Library | Self-Hosted Server | Cloud Platform |
|
||
|---|---------|-------------------|----------------|
|
||
| **最适合** | 测试、原型开发 | 在自有基础设施上运行的团队 | 零运维的生产使用 |
|
||
| **设置** | `pip install mem0ai` | `docker compose up` | 在 [app.mem0.ai](https://app.mem0.ai?utm_source=oss&utm_medium=readme) 注册 |
|
||
| **控制台** | -- | [有](https://docs.mem0.ai/open-source/setup) | 有 |
|
||
| **认证与 API 密钥** | -- | 有 | 有 |
|
||
| **高级功能** | -- | 预览 | 全部包含 |
|
||
|
||
只是测试?用 Library。为团队构建?选自托管。想要零运维?选 Cloud。
|
||
|
||
### Library(pip / npm)
|
||
|
||
```bash
|
||
pip install mem0ai
|
||
```
|
||
|
||
如需增强型混合检索(BM25 关键词匹配与实体提取),请安装带 NLP 支持的版本:
|
||
|
||
```bash
|
||
pip install mem0ai[nlp]
|
||
python -m spacy download en_core_web_sm
|
||
```
|
||
|
||
通过 npm 安装 SDK:
|
||
|
||
```bash
|
||
npm install mem0ai
|
||
```
|
||
|
||
### 自托管服务器
|
||
|
||
> **注意:** 自托管认证默认开启。从启用认证前的版本升级?请设置 `ADMIN_API_KEY`,通过向导注册管理员,或仅在本地开发时使用 `AUTH_DISABLED=true`。详见[升级说明](https://docs.mem0.ai/open-source/setup#upgrade-notes).
|
||
|
||
```bash
|
||
# 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
|
||
```
|
||
|
||
配置说明请参阅[自托管文档](https://docs.mem0.ai/open-source/overview)。
|
||
|
||
### 云平台
|
||
|
||
1. 在 [Mem0 Platform](https://app.mem0.ai?utm_source=oss&utm_medium=readme) 注册
|
||
2. 通过 SDK 或 API 密钥嵌入记忆层
|
||
3. 使用托管的 Qdrant 向量?请参阅[平台迁移指南](https://docs.mem0.ai/migration/oss-to-platform),将其导入 Mem0 Platform。
|
||
|
||
### CLI
|
||
|
||
在终端中管理记忆:
|
||
|
||
```bash
|
||
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 文档](https://docs.mem0.ai/platform/cli)。
|
||
|
||
### Agent Skills
|
||
|
||
教会你的 AI 编程助手(Claude Code、Codex、Cursor、Windsurf、OpenCode、OpenClaw,以及任何支持 skills 标准的工具)如何使用 Mem0 进行开发。分为两类:
|
||
|
||
**参考型 skills —— 始终开启**(将 SDK 知识加载到助手上下文中):
|
||
|
||
```bash
|
||
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 —— 按需运行**(在现有仓库中执行端到端工作流):
|
||
|
||
```bash
|
||
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 目录](./skills/) 或 [Vibecoding with Mem0](https://docs.mem0.ai/vibecoding) for the full picture.
|
||
|
||
### Basic Usage
|
||
|
||
Mem0 需要 LLM 才能运行,默认使用来自 OpenAI 的 `gpt-5-mini`。不过它也支持多种 LLM;详情请参阅我们的 [Supported LLMs documentation](https://docs.mem0.ai/components/llms/overview).
|
||
|
||
Mem0 默认使用来自 OpenAI 的 `text-embedding-3-small` 作为嵌入(embedding)模型。要在混合搜索(语义 + 关键词 + 实体加权)中获得最佳效果,我们建议至少使用 [Qwen 600M](https://huggingface.co/Alibaba-NLP/gte-Qwen2-1.5B-instruct) 或同等级别的嵌入模型。配置详情请参阅 [Supported Embeddings](https://docs.mem0.ai/components/embedders/overview)
|
||
|
||
第一步是实例化 memory:
|
||
|
||
```python
|
||
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](https://docs.mem0.ai/quickstart) 和 [API Reference](https://docs.mem0.ai/api-reference).
|
||
|
||
## 🔗 Integrations & Demos
|
||
|
||
- **ChatGPT with Memory**:由 Mem0 驱动的个性化聊天([Live Demo](https://mem0.dev/demo))
|
||
- **Browser Extension**:在 ChatGPT、Perplexity 和 Claude 之间存储记忆([Chrome Extension](https://chromewebstore.google.com/detail/onihkkbipkfeijkadecaafbgagkhglop?utm_source=item-share-cb))
|
||
- **Langgraph Support**:使用 Langgraph + Mem0 构建客服机器人([Guide](https://docs.mem0.ai/integrations/langgraph))
|
||
- **CrewAI Integration**:使用 Mem0 定制 CrewAI 输出([Example](https://docs.mem0.ai/integrations/crewai))
|
||
|
||
## 📚 Documentation & Support
|
||
|
||
- 完整文档:https://docs.mem0.ai
|
||
- 社区:[Discord](https://mem0.dev/DiG) · [X(原 Twitter)](https://x.com/mem0ai)
|
||
- 联系:founders@mem0.ai
|
||
|
||
## Citation
|
||
|
||
我们现在提供一篇可供引用的论文:
|
||
|
||
```bibtex
|
||
@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}
|
||
}
|
||
```
|
||
|
||
## ⚖️ License
|
||
|
||
Apache 2.0 — 详情请参阅 [LICENSE](https://github.com/mem0ai/mem0/blob/main/LICENSE) 文件。
|