Author: yevanchen Version: 0.0.1 Type: tool
mem0 is a memory management plugin that enables conversation history storage and retrieval for LLM applications.
- Get your API key from mem0 dashboard
- Install the package:
pip install mem0ai- Initialize the client:
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")Stores conversation history and context for users.
messages = [
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
{"role": "assistant", "content": "Hello Alex! I've noted your dietary preferences."}
]
client.add(messages, user_id="alex")Backend logic:
- Messages are stored in user-specific partitions using
user_id - Supports conversation history and context storage
- Handles message format validation and processing
- Optimizes storage for efficient retrieval
Retrieves relevant conversation history based on queries.
query = "What can I cook for dinner tonight?"
memories = client.search(query, user_id="alex")Backend logic:
- Semantic search across user's memory partition
- Returns relevant conversation snippets
- Handles context ranking and relevance scoring
- Optimizes query performance
- In Dify workflows, place
retrieve_memorybefore LLM calls to provide context - Add
add_memoryafter LLM responses to store new interactions user_idcan be customized in workflow run API- Note: iframe and webapp modes currently don't support user_id due to lack of access control
- Multimodal Support
- Memory Customization
- Custom Categories & Instructions
- Direct Import
- Async Client
- Memory Export
- Webhooks
- Graph Memory
- REST API Server
- OpenAI Compatibility
- Custom Prompts
For feature requests or discussions, contact evanchen@dify.ai

