Updated docs for agent_id and run_id (#3294)

This commit is contained in:
Parshva Daftari
2025-08-13 01:33:39 +05:30
committed by GitHub
parent 23d31a830b
commit 2145ffdb1c
5 changed files with 152 additions and 74 deletions
+1
View File
@@ -85,6 +85,7 @@
"group": "Features",
"icon": "star",
"pages": [
"open-source/features/overview",
"open-source/features/async-memory",
"open-source/features/openai_compatibility",
"open-source/features/custom-fact-extraction-prompt",
+35 -1
View File
@@ -68,10 +68,15 @@ await memory.search(
#### List memories
List all memories for a `user_id`, `agent_id`, or `run_id`:
List all memories for a `user_id`, `agent_id`, and/or `run_id`:
```python Python
await memory.get_all(user_id="alice")
# Get memories with agent and run context
await memory.get_all(user_id="alice", agent_id="assistant")
await memory.get_all(user_id="alice", run_id="session-001")
await memory.get_all(user_id="alice", agent_id="assistant", run_id="session-001")
```
#### Get specific memory
@@ -111,6 +116,35 @@ await memory.delete_all(user_id="alice")
Note: At least one filter (user_id, agent_id, or run_id) is required when using delete_all.
### Advanced Memory Organization
AsyncMemory supports the same three-parameter organization system as the synchronous Memory class:
```python Python
# Store memories with full context
await memory.add(
messages=[{"role": "user", "content": "I prefer vegetarian food"}],
user_id="alice",
agent_id="diet-assistant",
run_id="consultation-001"
)
# Retrieve memories with different scopes
all_user_memories = await memory.get_all(user_id="alice")
agent_memories = await memory.get_all(user_id="alice", agent_id="diet-assistant")
session_memories = await memory.get_all(user_id="alice", run_id="consultation-001")
specific_memories = await memory.get_all(
user_id="alice",
agent_id="diet-assistant",
run_id="consultation-001"
)
# Search with context
general_search = await memory.search("What do you know about me?", user_id="alice")
agent_search = await memory.search("What do you know about me?", user_id="alice", agent_id="diet-assistant")
session_search = await memory.search("What do you know about me?", user_id="alice", run_id="consultation-001")
```
#### Memory History
Get the history of changes for a specific memory:
+57
View File
@@ -0,0 +1,57 @@
---
title: Overview
description: 'Build powerful AI applications with self-improving memory using Mem0 open-source'
icon: "eye"
iconType: "solid"
---
## Welcome to Mem0 Open Source
Mem0 is a self-improving memory layer for LLM applications that enables personalized AI experiences while saving costs and delighting users. The open-source version gives you complete control over your memory infrastructure.
## Why Choose Mem0 Open Source?
Mem0 open-source provides a powerful, flexible foundation for AI memory management with these key advantages:
1. **Complete Control**: Deploy and manage your own memory infrastructure with full customization capabilities. Perfect for organizations that need data sovereignty and custom integrations.
2. **Flexible Architecture**: Choose from multiple vector databases (Pinecone, Qdrant, Weaviate, Chroma, PGVector), graph stores (Neo4j, Memgraph), and embedding models to fit your specific needs.
3. **Advanced Memory Organization**: Organize memories using `user_id`, `agent_id`, and `run_id` parameters for sophisticated multi-agent, multi-session applications with precise context control.
4. **Rich Integration Ecosystem**: Seamlessly integrate with popular frameworks like LangChain, LlamaIndex, AutoGen, CrewAI, and Vercel AI SDK.
## Core Features
### Memory Management
- **Synchronous & Asynchronous Operations**: Choose between sync and async memory operations based on your application needs
- **Smart Memory Retrieval**: Intelligent search and retrieval with semantic understanding
- **Memory Persistence**: Long-term storage with automatic optimization and cleanup
### Advanced Organization
- **User Context**: Organize memories by user for personalized experiences
- **Agent Isolation**: Separate memories by AI agent for specialized knowledge domains
- **Session Tracking**: Use run IDs to maintain context across different conversation sessions
### Flexible Storage
- **Vector Databases**: Support for Pinecone, Qdrant, Weaviate, Chroma, and PGVector
- **Graph Stores**: Neo4j and Memgraph integration for relationship-based memory
- **Embedding Models**: Multiple embedding providers for optimal performance
## Getting Started
Choose your preferred approach:
- **[Python Quickstart](../python-quickstart)**: Get started with Python SDK
- **[Node.js Quickstart](../node-quickstart)**: Use Mem0 with Node.js/TypeScript
- **[Examples](../examples)**: Explore real-world use cases and implementations
## Next Steps
- Explore [specific features](./async-memory) in detail
- Learn about [graph memory](../graph_memory/overview) capabilities
- Set up [vector databases](../components/vectordbs/overview) and [LLM integrations](../components/llms/overview)
- Check out our [examples](../examples) for practical implementations
- Join our [Discord community](https://mem0.dev/DiD) for support
We're excited to see what you'll build with Mem0 open-source. Let's create smarter, more personalized AI experiences together!
+26 -3
View File
@@ -296,7 +296,7 @@ The Mem0's graph supports the following operations:
### Add Memories
<Note>
Mem0 with Graph Memory supports both "user_id" and "agent_id" parameters. You can use either or both to organize your memories. Use "userId" and "agentId" in NodeSDK.
Mem0 with Graph Memory supports "user_id", "agent_id", and "run_id" parameters. You can use any combination of these to organize your memories. Use "userId", "agentId", and "runId" in NodeSDK.
</Note>
<CodeGroup>
@@ -306,6 +306,9 @@ m.add("I like pizza", user_id="alice")
# Using both user_id and agent_id
m.add("I like pizza", user_id="alice", agent_id="food-assistant")
# Using all three parameters for maximum organization
m.add("I like pizza", user_id="alice", agent_id="food-assistant", run_id="session-123")
```
```typescript TypeScript
@@ -331,6 +334,12 @@ m.get_all(user_id="alice")
# Get all memories for a specific agent belonging to a user
m.get_all(user_id="alice", agent_id="food-assistant")
# Get all memories for a specific run/session
m.get_all(user_id="alice", run_id="session-123")
# Get all memories for a specific agent and run combination
m.get_all(user_id="alice", agent_id="food-assistant", run_id="session-123")
```
```typescript TypeScript
@@ -375,6 +384,12 @@ m.search("tell me my name.", user_id="alice")
# Search memories for a specific agent belonging to a user
m.search("tell me my name.", user_id="alice", agent_id="food-assistant")
# Search memories for a specific run/session
m.search("tell me my name.", user_id="alice", run_id="session-123")
# Search memories for a specific agent and run combination
m.search("tell me my name.", user_id="alice", agent_id="food-assistant", run_id="session-123")
```
```typescript TypeScript
@@ -611,12 +626,13 @@ memory.search("Who is spiderman?", { userId: "alice123" });
## Using Multiple Agents with Graph Memory
When working with multiple agents, you can use the "agent_id" parameter to organize memories by both user and agent. This allows you to:
When working with multiple agents and sessions, you can use the "agent_id" and "run_id" parameters to organize memories by user, agent, and run context. This allows you to:
1. Create agent-specific knowledge graphs
2. Share common knowledge between agents
3. Isolate sensitive or specialized information to specific agents
4. Track conversation sessions and runs separately
5. Maintain context across different execution contexts
### Example: Multi-Agent Setup
@@ -627,10 +643,17 @@ m.add("I prefer Italian cuisine", user_id="bob", agent_id="food-assistant")
m.add("I'm allergic to peanuts", user_id="bob", agent_id="health-assistant")
m.add("I live in Seattle", user_id="bob") # Shared across all agents
# Add memories for specific runs/sessions
m.add("Current session: discussing dinner plans", user_id="bob", agent_id="food-assistant", run_id="dinner-session-001")
m.add("Previous session: allergy consultation", user_id="bob", agent_id="health-assistant", run_id="health-session-001")
# Search within specific agent context
food_preferences = m.search("What food do I like?", user_id="bob", agent_id="food-assistant")
health_info = m.search("What are my allergies?", user_id="bob", agent_id="health-assistant")
location = m.search("Where do I live?", user_id="bob") # Searches across all agents
# Search within specific run context
current_session = m.search("What are we discussing?", user_id="bob", run_id="dinner-session-001")
```
```typescript TypeScript
+33 -70
View File
@@ -117,6 +117,9 @@ messages = [
# Store inferred memories (default behavior)
result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})
# Store memories with agent and run context
result = m.add(messages, user_id="alice", agent_id="movie-assistant", run_id="session-001", metadata={"category": "movie_recommendations"})
# Store raw messages without inference
# result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"}, infer=False)
```
@@ -337,6 +340,35 @@ m.delete_all(user_id="alice")
m.reset() # Reset all memories
```
## Advanced Memory Organization
Mem0 supports three key parameters for organizing memories:
- **`user_id`**: Organize memories by user identity
- **`agent_id`**: Organize memories by AI agent or assistant
- **`run_id`**: Organize memories by session, workflow, or execution context
### Using All Three Parameters
```python
# Store memories with full context
m.add("User prefers vegetarian food",
user_id="alice",
agent_id="diet-assistant",
run_id="consultation-001")
# Retrieve memories with different scopes
all_user_memories = m.get_all(user_id="alice")
agent_memories = m.get_all(user_id="alice", agent_id="diet-assistant")
session_memories = m.get_all(user_id="alice", run_id="consultation-001")
specific_memories = m.get_all(user_id="alice", agent_id="diet-assistant", run_id="consultation-001")
# Search with context
general_search = m.search("What do you know about me?", user_id="alice")
agent_search = m.search("What do you know about me?", user_id="alice", agent_id="diet-assistant")
session_search = m.search("What do you know about me?", user_id="alice", run_id="consultation-001")
```
## Configuration Parameters
Mem0 offers extensive configuration options to customize its behavior according to your needs. These configurations span across different components like vector stores, language models, embedders, and graph stores.
@@ -452,40 +484,7 @@ If you have a `Mem0 API key`, you can use it to initialize the client. Alternati
Mem0 supports several language models (LLMs) through integration with various [providers](https://litellm.vercel.app/docs/providers).
## Use Mem0 Platform
```python
from mem0.proxy.main import Mem0
client = Mem0(api_key="m0-xxx")
# First interaction: Storing user preferences
messages = [
{
"role": "user",
"content": "I love indian food but I cannot eat pizza since allergic to cheese."
},
]
user_id = "alice"
chat_completion = client.chat.completions.create(messages=messages, model="gpt-4o-mini", user_id=user_id)
# Memory saved after this will look like: "Loves Indian food. Allergic to cheese and cannot eat pizza."
# Second interaction: Leveraging stored memory
messages = [
{
"role": "user",
"content": "Suggest restaurants in San Francisco to eat.",
}
]
chat_completion = client.chat.completions.create(messages=messages, model="gpt-4o-mini", user_id=user_id)
print(chat_completion.choices[0].message.content)
# Answer: You might enjoy Indian restaurants in San Francisco, such as Amber India, Dosa, or Curry Up Now, which offer delicious options without cheese.
```
In this example, you can see how the second response is tailored based on the information provided in the first interaction. Mem0 remembers the user's preference for Indian food and their cheese allergy, using this information to provide more relevant and personalized restaurant suggestions in San Francisco.
### Use Mem0 OSS
## Use Mem0 OSS
```python
config = {
@@ -511,42 +510,6 @@ chat_completion = client.chat.completions.create(
)
```
## APIs
Get started with using Mem0 APIs in your applications. For more details, refer to the [Platform](../platform/quickstart).
Here is an example of how to use Mem0 APIs:
```python
import os
from mem0 import MemoryClient
os.environ["MEM0_API_KEY"] = "your-api-key"
client = MemoryClient() # get api_key from https://app.mem0.ai/
# Store messages
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 that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
]
result = client.add(messages, user_id="alex")
print(result)
# Retrieve memories
all_memories = client.get_all(user_id="alex")
print(all_memories)
# Search memories
query = "What do you know about me?"
related_memories = client.search(query, user_id="alex")
# Get memory history
history = client.history(memory_id="m1")
print(history)
```
## Contributing
We welcome contributions to Mem0! Here's how you can contribute: