开源项目 GitHub Topic rag 2026-07-06T12:02 正文 ok 1239 words

Mem0:为 AI Agent 打造的通用记忆层

英文标题:📦 mem0ai/mem0

Mem0(“mem-zero”)是一个为 AI 助手和智能体提供智能记忆层的开源项目,支持多级记忆管理,能让 AI 记住用户偏好并持续学习。 项目公布了新的记忆算法,在 LoCoMo、LongMemEval 和 BEAM 等基准上大幅超越旧版,其中 LongMemEval 得分达 94.8,提升了 27 分。 Mem0 提供了命令行工具、Python/Node SDK 及自托管与云平台等灵活部署方式,并且支持 AI Agent 在 5 秒内自动创建 API 密钥。 对于开发者而言,这意味着可以更轻松地为对话式 AI、客服、医疗等应用赋予持久、个性化的记忆能力。
打开原文相关 2.1 · 机会 3
media138.6 KB media5.1 KB media2.9 KB media1.3 KB media597 B media1.3 KB media1.2 KB media569 B media47.6 KB

中文

Mem0 - 个性化 AI 的记忆层

mem0ai%2Fmem0 | Trendshift

了解更多 · 加入 Discord · 演示

Mem0 Discord Mem0 PyPI - 下载量 GitHub 提交活跃度 包版本 Npm 包版本 Y Combinator S24

📄 基准测试 Mem0 的高效 token 记忆算法 →

新记忆算法(2026年4月)

基准测试 旧算法 新算法 消耗 Token 延迟 p50
LoCoMo 71.4 91.6 7.0K 0.88s
LongMemEval 67.8 94.8 6.8K 1.09s
BEAM (1M) — 64.1 6.7K 1.00s
BEAM (10M) — 48.6 6.9K 1.05s

所有基准测试均在相同的生产代表性模型栈上运行。采用单次检索(一次调用,无 agent 循环)。

主要变化:

  • 仅添加(ADD)的单次提取 —— 一次 LLM 调用,不执行 UPDATE/DELETE。记忆不断累积;不会覆盖任何内容。
  • Agent 生成的事实成为一等公民 —— 当 agent 确认某个操作时,该信息现在以等权重被存储。
  • 实体链接 —— 抽取实体并进行嵌入,跨记忆链接以提升检索。
  • 多信号检索 —— 语义、BM25 关键词和实体匹配并行评分并融合。
  • 时间推理 —— 具备时间感知的检索,针对当前状态、过去事件和未来计划的查询,能对正确的时间实例进行排序。

请参阅迁移指南了解升级说明。评估框架已开源,任何人都可以复现这些数据。

  • LoCoMo 上达到 91.6 —— 比旧算法提升 20 分
  • LongMemEval 上达到 94.8 —— 提升 27 分,助理记忆召回率提升 +53.6
  • BEAM (1M) 上达到 64.1 —— 在 100 万 token 规模下的生产级记忆评估
  • 阅读完整论文

Mem0(读作 “mem-zero”)通过智能记忆层增强 AI 助手和智能体,实现个性化 AI 交互。它能记住用户偏好、适应个体需求并随时间持续学习,非常适合客户支持聊天机器人、AI 助手和自主系统。

核心能力:

  • 多级记忆:无缝保留用户、会话和 Agent 状态,并具备自适应个性化能力
  • 开发者友好:直观的 API、跨平台 SDK 以及完全托管服务选项

应用场景:

  • AI 助手:进行连贯、上下文丰富的对话
  • 客户支持:回忆历史工单和用户记录,提供量身定制的帮助
  • 医疗健康:跟踪患者偏好和历史,实现个性化护理
  • 生产力与游戏:根据用户行为实现自适应工作流和环境

AI agent 可以在五秒内创建一个有效的 Mem0 API 密钥——无需邮箱、无需仪表板、无需一次性验证码。通过四条命令即可完成端到端流程:

1. 安装

npm install -g @mem0/cli # 或: pip install mem0-cli

2. 以 agent 身份注册(将 claude-code 替换为你的名称)

mem0 init --agent --agent-caller claude-code

3. 添加记忆

mem0 add "I am using mem0"

4. 搜索

mem0 search "am I using mem0"

人类所有者可以稍后通过 mem0 init --email <their-email> 认领账户——密钥不变,记忆保留。完整指南:以 agent 身份注册。

| 库 | 自托管服务器 | 云平台
---|---|---|---
最适合 | 测试、原型开发 | 团队在自己基础设施上运行 | 零运维生产使用
设置 | pip install mem0ai | docker compose up | 在 app.mem0.ai 注册
仪表板 | -- | 有 | 有
认证与 API 密钥 | -- | 有 | 有
高级功能 | -- | 预览功能 | 全部包含

刚在测试阶段?使用库。为团队构建?自托管。想零运维?选云平台。

如需增强的混合搜索,即包含 BM25 关键词匹配和实体抽取,可安装 NLP 扩展支持:

pip install mem0ai[nlp] python -m spacy download en_core_web_sm

通过 npm 安装 SDK:

注意: 自托管认证默认开启。从旧的无认证版本升级?请设置 ADMIN_API_KEY,通过配置向导注册管理员,或设置 AUTH_DISABLED=true(仅限本地开发)。详见升级说明。

推荐:一条命令 —— 启动所有服务、创建管理员、签发第一个 API 密钥。

cd server && make bootstrap

手动方式:启动所有服务,然后通过浏览器向导完成设置。

cd server && docker compose up -d # http://localhost:3000

有关配置,请参阅自托管文档。

  1. 在 Mem0 平台 注册
  2. 通过 SDK 或 API 密钥嵌入记忆层
  3. 正在使用托管的 Qdrant 向量数据库?请参阅平台迁移指南将其导入 Mem0 平台。

通过终端管理记忆:

npm install -g @mem0/cli # 或: 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 通过测试优先的流水线将 Mem0 接入现有仓库,然后用 /mem0-test-integration 验证。使用 /mem0-oss-to-platform 将现有项目从 Mem0 OSS 迁移到托管平台 SDK。更多内容请查看 skills 目录 或 使用 Mem0 进行 Vibecoding。

Mem0 需要 LLM 才能运行,默认使用 OpenAI 的 gpt-5-mini。不过,它支持多种 LLM;详情请参阅我们的支持的 LLM 文档。

Mem0 使用 OpenAI 的 text-embedding-3-small 作为默认嵌入模型。为获得最佳混合搜索效果(语义 + 关键词 + 实体增强),建议至少使用 Qwen 600M 或同等水平的嵌入模型。配置详情请参见支持的嵌入模型。

第一步是初始化记忆:

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: # 检索相关记忆 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"])

# 生成助手回复
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

# 从对话中创建新记忆
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()

详细集成步骤请参见快速入门和API 参考。

  • 带记忆的 ChatGPT : 基于 Mem0 的个性化聊天(在线演示)
  • 浏览器扩展 : 在 ChatGPT、Perplexity 和 Claude 之间存储记忆(Chrome 扩展)
  • Langgraph 支持 : 使用 Langgraph + Mem0 构建客服机器人(指南)
  • CrewAI 集成 : 用 Mem0 定制 CrewAI 输出(示例)

📚 文档与支持

现在你可以通过以下方式引用我们的论文:

@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 文件。

English / 原文

Mem0 - The Memory Layer for Personalized AI

mem0ai%2Fmem0 | Trendshift

Learn more · Join Discord · Demo

Mem0 Discord Mem0 PyPI - Downloads GitHub commit activity Package version Npm package Y Combinator S24

📄 Benchmarking Mem0's token-efficient memory algorithm →

New Memory Algorithm (April 2026)

Benchmark Old New Tokens Latency p50
LoCoMo 71.4 91.6 7.0K 0.88s
LongMemEval 67.8 94.8 6.8K 1.09s
BEAM (1M) — 64.1 6.7K 1.00s
BEAM (10M) — 48.6 6.9K 1.05s

All benchmarks run on the same production-representative model stack. Single-pass retrieval (one call, no agentic loops).

What changed:

  • Single-pass ADD-only extraction -- one LLM call, no UPDATE/DELETE. Memories accumulate; nothing is overwritten.
  • Agent-generated facts are first-class -- when an agent confirms an action, that information is now stored with equal weight.
  • Entity linking -- entities are extracted, embedded, and linked across memories for retrieval boosting.
  • Multi-signal retrieval -- semantic, BM25 keyword, and entity matching scored in parallel and fused.
  • Temporal Reasoning -- time-aware retrieval that ranks the right dated instance for queries about current state, past events, and upcoming plans.

See the migration guide for upgrade instructions. The evaluation framework is open-sourced so anyone can reproduce the numbers.

  • 91.6 on LoCoMo -- +20 points over the previous algorithm
  • 94.8 on LongMemEval -- +27 points, with +53.6 on assistant memory recall
  • 64.1 on BEAM (1M) -- production-scale memory evaluation at 1M tokens
  • Read the full paper

Mem0 ("mem-zero") enhances AI assistants and agents with an intelligent memory layer, enabling personalized AI interactions. It remembers user preferences, adapts to individual needs, and continuously learns over time—ideal for customer support chatbots, AI assistants, and autonomous systems.

Core Capabilities:

  • Multi-Level Memory : Seamlessly retains User, Session, and Agent state with adaptive personalization
  • Developer-Friendly : Intuitive API, cross-platform SDKs, and a fully managed service option

Applications:

  • AI Assistants : Consistent, context-rich conversations
  • Customer Support : Recall past tickets and user history for tailored help
  • Healthcare : Track patient preferences and history for personalized care
  • Productivity & Gaming: Adaptive workflows and environments based on user behavior

AI agents can mint a working Mem0 API key in under five seconds — no email, no dashboard, no OTP. Four commands end-to-end:

# 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"

The human owner can claim the account later with mem0 init --email <their-email> — same key, memories preserved. Full guide: Sign up as an agent.

| Library | Self-Hosted Server | Cloud Platform
---|---|---|---
Best for | Testing, prototyping | Teams running on their own infrastructure | Zero-ops production use
Setup | pip install mem0ai | docker compose up | Sign up at app.mem0.ai
Dashboard | -- | Yes | Yes
Auth & API Keys | -- | Yes | Yes
Advanced Features | -- | Teasers | All included

Just testing? Use the library. Building for a team? Self-hosted. Want zero ops? Cloud.

For enhanced hybrid search with BM25 keyword matching and entity extraction, install with NLP support:

pip install mem0ai[nlp]
python -m spacy download en_core_web_sm

Install sdk via npm:

Note: Self-hosted auth is on by default. Upgrading from a pre-auth build? Set ADMIN_API_KEY, register an admin through the wizard, or AUTH_DISABLED=true for local dev only. See upgrade notes.

# 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

See the self-hosted docs for configuration.

  1. Sign up on Mem0 Platform
  2. Embed the memory layer via SDK or API keys
  3. Using hosted Qdrant vectors? See the Platform migration guide to import them into Mem0 Platform.

Manage memories from your terminal:

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

See the CLI documentation for the full command reference.

Teach your AI coding assistant (Claude Code, Codex, Cursor, Windsurf, OpenCode, OpenClaw, and any tool that supports the skills standard) how to build with Mem0. Two categories:

Reference skills — always on (SDK knowledge loaded into the assistant's context):

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

Pipeline skills — run on demand (execute an end-to-end workflow in an existing repo):

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

Use /mem0-integrate to wire Mem0 into an existing repo via a test-first pipeline, then /mem0-test-integration to verify. Use /mem0-oss-to-platform to migrate an existing project from Mem0 OSS to the hosted Platform SDK. See the skills catalog or Vibecoding with Mem0 for the full picture.

Mem0 requires an LLM to function, with gpt-5-mini from OpenAI as the default. However, it supports a variety of LLMs; for details, refer to our Supported LLMs documentation.

Mem0 uses text-embedding-3-small from OpenAI as the default embedding model. For best results with hybrid search (semantic + keyword + entity boosting), we recommend using at least Qwen 600M or a comparable embedding model. See Supported Embeddings for configuration details.

First step is to instantiate the 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()

For detailed integration steps, see the Quickstart and API Reference.

  • ChatGPT with Memory : Personalized chat powered by Mem0 (Live Demo)
  • Browser Extension : Store memories across ChatGPT, Perplexity, and Claude (Chrome Extension)
  • Langgraph Support : Build a customer bot with Langgraph + Mem0 (Guide)
  • CrewAI Integration : Tailor CrewAI outputs with Mem0 (Example)

📚 Documentation & Support

We now have a paper you can cite:

@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 — see the LICENSE file for details.