# Mem0 — Memory Layer for AI Applications > Add persistent, personalized memory to AI agents and assistants. Mem0 stores user preferences, past interactions, and learned context across sessions. ## Install Copy the content below into your project: ## Quick Use ```bash pip install mem0ai ``` ```python from mem0 import Memory m = Memory() # Add memories m.add("I prefer Python over JavaScript", user_id="alice") m.add("My project uses PostgreSQL and Redis", user_id="alice") # Search memories results = m.search("what database does alice use?", user_id="alice") print(results) # [{'memory': 'Uses PostgreSQL and Redis', 'score': 0.95}] ``` ## What is Mem0? Mem0 (pronounced "memo") is a memory layer for AI applications. It automatically extracts, stores, and retrieves relevant memories from conversations — giving AI agents persistent context across sessions without manual prompt engineering. **Answer-Ready**: Mem0 is a memory infrastructure for AI apps that stores user preferences, facts, and context across sessions, enabling personalized AI experiences with simple add/search APIs. ## Core Features ### 1. Automatic Memory Extraction Mem0 identifies and stores key facts from conversations: ```python m.add("I'm allergic to peanuts and I live in SF", user_id="bob") # Stores: ["Allergic to peanuts", "Lives in San Francisco"] ``` ### 2. Multi-Level Memory ```python # User-level: personal preferences m.add("Dark mode preferred", user_id="alice") # Agent-level: learned behaviors m.add("Always check tests before committing", agent_id="dev-bot") # Session-level: conversation context m.add("Working on the auth refactor", user_id="alice", run_id="session-42") ``` ### 3. Memory Management ```python # Get all memories for a user all_memories = m.get_all(user_id="alice") # Update a specific memory m.update(memory_id="mem-123", data="Prefers dark mode in all apps") # Delete m.delete(memory_id="mem-123") # Memory history history = m.history(memory_id="mem-123") ``` ### 4. Graph Memory (Beta) Store relationships between entities: ```python from mem0 import Memory config = {"graph_store": {"provider": "neo4j", "config": {...}}} m = Memory.from_config(config) m.add("Alice manages the payments team", user_id="org") # Creates: Alice --manages--> Payments Team ``` ### 5. Platform Integrations ```python # With OpenAI from mem0 import MemoryClient client = MemoryClient(api_key="mem0-key") # With LangChain from langchain.memory import Mem0Memory memory = Mem0Memory(mem0_api_key="...") ``` ## FAQ **Q: Where are memories stored?** A: Local mode uses Qdrant (embedded). Cloud mode uses Mem0 managed infra. **Q: How is it different from RAG?** A: RAG retrieves from static documents. Mem0 learns and updates from conversations dynamically. **Q: Is it free?** A: Open-source for self-hosting. Cloud platform has a free tier. ## Source & Thanks - GitHub: [mem0ai/mem0](https://github.com/mem0ai/mem0) (25k+ stars) - Docs: [docs.mem0.ai](https://docs.mem0.ai) ## 快速使用 ```bash pip install mem0ai ``` 三行代码为 AI 应用添加持久记忆层。 ## 什么是 Mem0? Mem0 是 AI 应用的记忆基础设施。自动从对话中提取、存储和检索相关记忆,让 AI 代理跨会话保持上下文。 **一句话总结**:Mem0 为 AI 应用存储用户偏好、事实和上下文,通过简单的 add/search API 实现个性化体验。 ## 核心功能 ### 1. 自动记忆提取 从对话中识别关键事实并存储。 ### 2. 多层记忆 用户级、代理级、会话级三层记忆体系。 ### 3. 图记忆(Beta) 存储实体间关系,构建知识图谱。 ## 常见问题 **Q: 和 RAG 有什么区别?** A: RAG 从静态文档检索,Mem0 从对话中动态学习和更新。 **Q: 免费吗?** A: 自托管开源免费,云平台有免费层。 ## 来源与致谢 - GitHub: [mem0ai/mem0](https://github.com/mem0ai/mem0) (25k+ stars) --- Source: https://tokrepo.com/en/workflows/96da1f40-1823-4d87-a84f-7d8269edeb24 Author: Agent Toolkit