Long-term Memory: mem0

Mem0 is an open-source memory layer designed specifically for LLMs and AI agents. It gives AI applications the ability to remember, learn from, and personalize interactions across sessions—much like a human would.

CN: Mem0 是一个专为 LLM 和 AI Agent 设计的开源记忆层。它让 AI 应用能够像人一样,跨会话记住、学习并个性化交互

 Imagine your AI agent is a personal assistant. Without Mem0, every time you walk into the office, the assistant has no idea who you are, what you like, or what you talked about yesterday. You have to reintroduce yourself every single time. With Mem0, the assistant has a notebook that automatically writes down important things about you—your name, preferences, past requests—and reads the relevant notes before every conversation.

CN: 想象你的 AI Agent 是一个私人助理。没有 Mem0,每次你走进办公室,助理都不知道你是谁、喜欢什么、昨天聊了什么。你每次都要重新介绍自己。有了 Mem0,助理有一本笔记本,自动记录关于你的重要信息——你的名字、偏好、过去的请求——并在每次对话前阅读相关笔记。

Core Concepts of Mem0

2.1 Memory Lifecycle (记忆的生命周期)

EN: Mem0 handles memories through a complete lifecycle:

  • Extract (提取): Identifies important information from conversations
  • Store (存储): Saves structured memories with embeddings in a vector database
  • Retrieve (检索): Uses semantic search to find relevant memories
  • Update (更新): Smartly updates memories over time, resolving contradictions

CN: Mem0 通过完整的生命周期管理记忆:

  • 提取: 从对话中识别重要信息
  • 存储: 将结构化记忆连同向量嵌入保存到向量数据库
  • 检索: 使用语义搜索查找相关记忆
  • 更新: 智能地随时间更新记忆,解决矛盾

2.2 Memory Scopes (记忆的作用域)

EN: Mem0 associates each memory with an identifier, allowing organization by:

  • User ID: Personal memories for a specific user
  • Agent ID: Memories for a specific agent
  • Session: Short-term context within a session
  • Organization: Shared memories across an organization

CN: Mem0 将每个记忆与一个标识符关联,允许按以下维度组织:

  • User ID: 特定用户的个人记忆
  • Agent ID: 特定 Agent 的记忆
  • Session: 会话内的短期上下文
  • Organization: 跨组织的共享记忆

2.3 Mem0 vs RAG

EN: RAG is for static facts—documents, knowledge bases. AI Memory is for dynamic state—user preferences that evolve, change, and contradict over time. Mem0 is specialized for the memory use case, not a general-purpose RAG tool.

CN: RAG 针对静态事实——文档、知识库。AI Memory 针对动态状态——用户偏好会随时间演变、变化甚至自相矛盾。Mem0 是专门为记忆场景设计的,不是通用 RAG 工具

Mem0 Architecture

 Mem0 uses a hybrid approach:

ComponentENCN
LLM (e.g., GPT-4o-mini)Extracts facts and updates memories提取事实和更新记忆
Embedding Model (e.g., text-embedding-3-small)Converts text to vectors (1536 dims)将文本转换为向量
Vector Database (e.g., Qdrant)Stores and searches memory vectors存储和搜索记忆向量
History DB (SQLite)Tracks all memory operations追踪所有记忆操作
Reranker (optional)Re-ranks retrieved memories for relevance对检索结果重新排序

Key Takeaways

要点ENCN
Mem0 是 LLM 的记忆层,非 RAGMem0 is a memory layer for LLMs, not RAGMem0 是 LLM 的记忆层,不是 RAG
LLM 无状态,Mem0 提供跨会话记忆LLMs are stateless; Mem0 provides cross-session memoryLLM 无状态;Mem0 提供跨会话记忆
核心操作:m.add() 存储,m.search() 检索Core ops: m.add() to store, m.search() to retrieve核心操作:m.add() 存储,m.search() 检索
记忆通过 user_id/agent_id 作用域隔离Memories scoped by user_id/agent_id记忆通过 user_id/agent_id 作用域隔离
默认使用 OpenAI (gpt-4o-mini + text-embedding-3-small)Default: OpenAI (gpt-4o-mini + text-embedding-3-small)默认使用 OpenAI (gpt-4o-mini + text-embedding-3-small)
LangGraph 中作为 retrieval + update 两个节点In LangGraph: retrieval + update nodesLangGraph 中作为 retrieval + update 两个节点
生产环境需显式配置 LLM/向量库Production: explicit LLM/vector DB config生产环境需显式配置 LLM/向量库