[docs] Add memory and v2 docs fixup (#3792)
This commit is contained in:
@@ -44,13 +44,12 @@ Provide at least one message or direct memory string. Most callers supply `messa
|
|||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `user_id` | string | No* | Associates the memory with a user. Provide when you want the memory scoped to a specific identity. |
|
| `user_id` | string | No* | Associates the memory with a user. Provide when you want the memory scoped to a specific identity. |
|
||||||
| `messages` | array | No* | Conversation turns for Mem0 to infer memories from. Each object should include `role` and `content`. |
|
| `messages` | array | No* | Conversation turns for Mem0 to infer memories from. Each object should include `role` and `content`. |
|
||||||
| `memory` | string | No* | Direct memory text when you do not need inference. |
|
|
||||||
| `metadata` | object | Optional | Custom key/value metadata (e.g., `{"topic": "preferences"}`). |
|
| `metadata` | object | Optional | Custom key/value metadata (e.g., `{"topic": "preferences"}`). |
|
||||||
| `infer` | boolean (default `true`) | Optional | Set to `false` to skip inference and store the provided text as-is. |
|
| `infer` | boolean (default `true`) | Optional | Set to `false` to skip inference and store the provided text as-is. |
|
||||||
| `async_mode` | boolean (default `true`) | Optional | Controls asynchronous processing. Most clients leave this enabled. |
|
| `async_mode` | boolean (default `true`) | Optional | Controls asynchronous processing. Most clients leave this enabled. |
|
||||||
| `output_format` | string (default `v1.1`) | Optional | Response format. `v1.1` wraps results in a `results` array. |
|
| `output_format` | string (default `v1.1`) | Optional | Response format. `v1.1` wraps results in a `results` array. |
|
||||||
|
|
||||||
> \* Provide either `messages` or `memory` to describe what you are storing. For scoped memories, include `user_id`. You can also attach `agent_id`, `app_id`, `run_id`, `project_id`, or `org_id` to refine ownership.
|
> \* Provide at least one `messages` entry to describe what you are storing. For scoped memories, include `user_id`. You can also attach `agent_id`, `app_id`, `run_id`, `project_id`, or `org_id` to refine ownership.
|
||||||
|
|
||||||
## Response
|
## Response
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ result = client.add(
|
|||||||
user_id="traveler_cam",
|
user_id="traveler_cam",
|
||||||
agent_id="travel_planner",
|
agent_id="travel_planner",
|
||||||
run_id="tokyo-2025-weekend",
|
run_id="tokyo-2025-weekend",
|
||||||
app_id="concierge_app",
|
app_id="concierge_app"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -105,8 +104,7 @@ client.add(
|
|||||||
user_id="traveler_cam",
|
user_id="traveler_cam",
|
||||||
agent_id="chef_recommender",
|
agent_id="chef_recommender",
|
||||||
run_id="menu-planning-2025-04",
|
run_id="menu-planning-2025-04",
|
||||||
app_id="concierge_app",
|
app_id="concierge_app"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -200,8 +198,7 @@ client.add(
|
|||||||
user_id="exec_123",
|
user_id="exec_123",
|
||||||
agent_id="booking_assistant",
|
agent_id="booking_assistant",
|
||||||
app_id="enterprise_portal",
|
app_id="enterprise_portal",
|
||||||
run_id="trip-2025-03",
|
run_id="trip-2025-03"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Retrieve with the same scope
|
# Retrieve with the same scope
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ messages = [
|
|||||||
client.add(
|
client.add(
|
||||||
messages=messages,
|
messages=messages,
|
||||||
user_id="alice",
|
user_id="alice",
|
||||||
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -87,7 +86,7 @@ const messages = [
|
|||||||
await client.add({
|
await client.add({
|
||||||
messages,
|
messages,
|
||||||
user_id: "alice",
|
user_id: "alice",
|
||||||
version: "v2"
|
version: "v2",
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|||||||
@@ -190,7 +190,6 @@ memory = Mem0MemoryService(
|
|||||||
params={
|
params={
|
||||||
"search_limit": 5, # Retrieve up to 5 memories
|
"search_limit": 5, # Retrieve up to 5 memories
|
||||||
"search_threshold": 0.2, # Higher threshold for more relevant matches
|
"search_threshold": 0.2, # Higher threshold for more relevant matches
|
||||||
"api_version": "v2", # Mem0 API version
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
@@ -219,4 +218,3 @@ memory = Mem0MemoryService(
|
|||||||
Create conversational voice agents
|
Create conversational voice agents
|
||||||
</Card>
|
</Card>
|
||||||
</CardGroup>
|
</CardGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ messages = [
|
|||||||
{"role": "assistant", "content": "Great! I'll remember your preference for Italian cuisine."}
|
{"role": "assistant", "content": "Great! I'll remember your preference for Italian cuisine."}
|
||||||
]
|
]
|
||||||
|
|
||||||
client.add(messages, user_id="user123", version="v2")
|
client.add(messages, user_id="user123")
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript JavaScript
|
```javascript JavaScript
|
||||||
@@ -48,14 +48,14 @@ messages1 = [
|
|||||||
{"role": "user", "content": "Hi, I'm Sarah from New York"},
|
{"role": "user", "content": "Hi, I'm Sarah from New York"},
|
||||||
{"role": "assistant", "content": "Hello Sarah! Nice to meet you."}
|
{"role": "assistant", "content": "Hello Sarah! Nice to meet you."}
|
||||||
]
|
]
|
||||||
client.add(messages1, user_id="sarah", version="v2")
|
client.add(messages1, user_id="sarah")
|
||||||
|
|
||||||
# Later interaction - just send new messages
|
# Later interaction - just send new messages
|
||||||
messages2 = [
|
messages2 = [
|
||||||
{"role": "user", "content": "I'm planning a trip to Italy next month"},
|
{"role": "user", "content": "I'm planning a trip to Italy next month"},
|
||||||
{"role": "assistant", "content": "How exciting! Italy is beautiful this time of year."}
|
{"role": "assistant", "content": "How exciting! Italy is beautiful this time of year."}
|
||||||
]
|
]
|
||||||
client.add(messages2, user_id="sarah", version="v2")
|
client.add(messages2, user_id="sarah")
|
||||||
# Mem0 automatically knows Sarah is from New York and can use this context
|
# Mem0 automatically knows Sarah is from New York and can use this context
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ messages = [
|
|||||||
{"role": "assistant", "content": "I've noted your allergies for future reference."}
|
{"role": "assistant", "content": "I've noted your allergies for future reference."}
|
||||||
]
|
]
|
||||||
|
|
||||||
client.add(messages, user_id="user123", version="v2")
|
client.add(messages, user_id="user123")
|
||||||
# This allergy info will be available in ALL future interactions
|
# This allergy info will be available in ALL future interactions
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -120,21 +120,21 @@ messages1 = [
|
|||||||
{"role": "user", "content": "I want to plan a 5-day trip to Tokyo"},
|
{"role": "user", "content": "I want to plan a 5-day trip to Tokyo"},
|
||||||
{"role": "assistant", "content": "Perfect! Let's plan your Tokyo adventure."}
|
{"role": "assistant", "content": "Perfect! Let's plan your Tokyo adventure."}
|
||||||
]
|
]
|
||||||
client.add(messages1, user_id="user123", run_id="tokyo-trip-2024", version="v2")
|
client.add(messages1, user_id="user123", run_id="tokyo-trip-2024")
|
||||||
|
|
||||||
# Later in the same trip planning session
|
# Later in the same trip planning session
|
||||||
messages2 = [
|
messages2 = [
|
||||||
{"role": "user", "content": "I prefer staying near Shibuya"},
|
{"role": "user", "content": "I prefer staying near Shibuya"},
|
||||||
{"role": "assistant", "content": "Great choice! Shibuya is very convenient."}
|
{"role": "assistant", "content": "Great choice! Shibuya is very convenient."}
|
||||||
]
|
]
|
||||||
client.add(messages2, user_id="user123", run_id="tokyo-trip-2024", version="v2")
|
client.add(messages2, user_id="user123", run_id="tokyo-trip-2024")
|
||||||
|
|
||||||
# Different session for work project (separate context)
|
# Different session for work project (separate context)
|
||||||
work_messages = [
|
work_messages = [
|
||||||
{"role": "user", "content": "Let's discuss the Q4 marketing strategy"},
|
{"role": "user", "content": "Let's discuss the Q4 marketing strategy"},
|
||||||
{"role": "assistant", "content": "Sure! What are your main goals for Q4?"}
|
{"role": "assistant", "content": "Sure! What are your main goals for Q4?"}
|
||||||
]
|
]
|
||||||
client.add(work_messages, user_id="user123", run_id="q4-marketing", version="v2")
|
client.add(work_messages, user_id="user123", run_id="q4-marketing")
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript JavaScript
|
```javascript JavaScript
|
||||||
@@ -176,8 +176,7 @@ messages = [
|
|||||||
# Each support ticket gets its own run_id
|
# Each support ticket gets its own run_id
|
||||||
client.add(messages,
|
client.add(messages,
|
||||||
user_id="customer123",
|
user_id="customer123",
|
||||||
run_id="ticket-2024-001",
|
run_id="ticket-2024-001"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -189,7 +188,7 @@ preference_messages = [
|
|||||||
{"role": "assistant", "content": "Got it! I'll keep your fitness and dietary preferences in mind."}
|
{"role": "assistant", "content": "Got it! I'll keep your fitness and dietary preferences in mind."}
|
||||||
]
|
]
|
||||||
|
|
||||||
client.add(preference_messages, user_id="user456", version="v2")
|
client.add(preference_messages, user_id="user456")
|
||||||
|
|
||||||
# Daily planning session (session-specific)
|
# Daily planning session (session-specific)
|
||||||
planning_messages = [
|
planning_messages = [
|
||||||
@@ -199,8 +198,7 @@ planning_messages = [
|
|||||||
|
|
||||||
client.add(planning_messages,
|
client.add(planning_messages,
|
||||||
user_id="user456",
|
user_id="user456",
|
||||||
run_id="daily-plan-2024-01-15",
|
run_id="daily-plan-2024-01-15"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -212,7 +210,7 @@ profile_messages = [
|
|||||||
{"role": "assistant", "content": "I'll tailor explanations to help with math concepts."}
|
{"role": "assistant", "content": "I'll tailor explanations to help with math concepts."}
|
||||||
]
|
]
|
||||||
|
|
||||||
client.add(profile_messages, user_id="student789", version="v2")
|
client.add(profile_messages, user_id="student789")
|
||||||
|
|
||||||
# Specific lesson session
|
# Specific lesson session
|
||||||
lesson_messages = [
|
lesson_messages = [
|
||||||
@@ -222,8 +220,7 @@ lesson_messages = [
|
|||||||
|
|
||||||
client.add(lesson_messages,
|
client.add(lesson_messages,
|
||||||
user_id="student789",
|
user_id="student789",
|
||||||
run_id="algorithms-lesson-1",
|
run_id="algorithms-lesson-1"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -238,17 +235,17 @@ client.add(lesson_messages,
|
|||||||
|
|
||||||
### ❌ Don't
|
### ❌ Don't
|
||||||
- Send duplicate messages or interaction history
|
- Send duplicate messages or interaction history
|
||||||
- Forget to include `version="v2"` parameter
|
- Skip identifiers like `user_id` or `run_id` that scope the memory
|
||||||
- Mix contextual and non-contextual approaches in the same application
|
- Mix contextual and non-contextual approaches in the same application
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
| Issue | Solution |
|
| Issue | Solution |
|
||||||
|-------|----------|
|
|-------|----------|
|
||||||
| **Context not working** | Ensure you're using `version="v2"` and consistent `user_id` |
|
| **Context not working** | Ensure each call uses the same `user_id` / `run_id` combo; version is automatic |
|
||||||
| **Wrong context retrieved** | Check if you need separate `run_id` values for different interaction topics |
|
| **Wrong context retrieved** | Check if you need separate `run_id` values for different interaction topics |
|
||||||
| **Missing interaction history** | Verify all messages in the interaction thread use the same `user_id` and `run_id` |
|
| **Missing interaction history** | Verify all messages in the interaction thread use the same `user_id` and `run_id` |
|
||||||
| **Too much irrelevant context** | Use more specific `run_id` values to separate different interaction types |
|
| **Too much irrelevant context** | Use more specific `run_id` values to separate different interaction types |
|
||||||
|
|
||||||
|
|
||||||
<Snippet file="get-help.mdx" />
|
<Snippet file="get-help.mdx" />
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ client.add(
|
|||||||
user_id="teacher_872",
|
user_id="teacher_872",
|
||||||
agent_id="study_planner",
|
agent_id="study_planner",
|
||||||
app_id="district_dashboard",
|
app_id="district_dashboard",
|
||||||
run_id="prep-period-2025-09-02",
|
run_id="prep-period-2025-09-02"
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -91,8 +90,7 @@ client.add(
|
|||||||
agent_id="travel_planner",
|
agent_id="travel_planner",
|
||||||
app_id="concierge_portal",
|
app_id="concierge_portal",
|
||||||
run_id="itinerary-2025-apr",
|
run_id="itinerary-2025-apr",
|
||||||
metadata={"category": "preferences"},
|
metadata={"category": "preferences"}
|
||||||
version="v2"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user