docs(cookbooks): fix v3 filters, response shapes & dead snippet in cookbooks (#5841)

This commit is contained in:
Kartik
2026-06-27 18:55:08 +05:30
committed by GitHub
parent e9c930c430
commit b44ce4dcc3
7 changed files with 17 additions and 45 deletions
@@ -211,8 +211,8 @@ class MultiAgentLearningSystem:
try:
# Search memory for learning patterns
memories = self.memory.search(
user_id=self.student_id,
query="learning machine learning"
query="learning machine learning",
filters={"user_id": self.student_id}
)
if memories and memories.get('results'):
@@ -50,7 +50,7 @@ load_dotenv()
USER_ID = "Alex"
# Initialize Mem0 client
mem0 = MemoryClient()
mem0_client = MemoryClient()
```
## Define Memory Tools
@@ -76,7 +76,7 @@ def retrieve_patient_info(query: str) -> dict:
# Search Mem0
results = mem0_client.search(
query,
user_id=USER_ID,
filters={"user_id": USER_ID},
top_k=5,
threshold=0.7 # Higher threshold for more relevant results
)
@@ -53,34 +53,12 @@ async function addUserPreferences() {
await addUserPreferences();
```
```json Output (Memories)
[
{
"id": "ff9f3367-9e83-415d-b9c5-dc8befd9a4b4",
"data": { "memory": "Loves BMW, Audi, and Porsche" },
"event": "ADD"
},
{
"id": "04172ce6-3d7b-45a3-b4a1-ee9798593cb4",
"data": { "memory": "Hates Mercedes" },
"event": "ADD"
},
{
"id": "db363a5d-d258-4953-9e4c-777c120de34d",
"data": { "memory": "Loves red cars and maroon cars" },
"event": "ADD"
},
{
"id": "5519aaad-a2ac-4c0d-81d7-0d55c6ecdba8",
"data": { "memory": "Has a budget of 120K to 150K USD" },
"event": "ADD"
},
{
"id": "523b7693-7344-4563-922f-5db08edc8634",
"data": { "memory": "Likes Audi the most" },
"event": "ADD"
}
]
```json Output
{
"message": "Memory processing has been queued for background execution",
"status": "PENDING",
"event_id": "9f8c2b1a-4e7d-4c3a-9b21-1a2b3c4d5e6f"
}
```
</CodeGroup>
## Retrieving Memories
@@ -88,7 +66,7 @@ await addUserPreferences();
Search for relevant memories based on the current user input:
```javascript
const relevantMemories = await mem0Client.search(userInput, { userId: USER_ID });
const relevantMemories = await mem0Client.search(userInput, { filters: { user_id: USER_ID } });
```
## Structured Responses with Zod
@@ -194,7 +172,7 @@ async function main(memory = false) {
// Search for relevant memories
let relevantMemories = []
if (memory) {
relevantMemories = await mem0Client.search(input, { userId: USER_ID });
relevantMemories = await mem0Client.search(input, { filters: { user_id: USER_ID } });
}
const response = await openAIClient.responses.create({
@@ -4,8 +4,6 @@ description: "Blend Tavily's realtime results with personal context stored in Me
---
<Snippet file="security-compliance.mdx" />
Imagine asking a search assistant for "coffee shops nearby" and instead of generic results, it shows remote-work-friendly cafes with great WiFi in your city because it remembers you mentioned working remotely before. Or when you search for "lunchbox ideas for kids" it knows you have a 7-year-old daughter and recommends peanut-free options that align with her allergy.
That's what we are going to build today, a Personalized Search Assistant powered by Mem0 for memory and [Tavily](https://tavily.com) for real-time search.
@@ -217,8 +217,7 @@ def apply_writing_style(original_content):
results = memory.search(
query="What are my writing style preferences?",
user_id=USER_ID,
run_id=RUN_ID,
filters={"user_id": USER_ID, "run_id": RUN_ID},
)
if not results:
@@ -314,18 +314,16 @@ class EmailProcessor:
user_id (str): User identifier
sender (str, optional): Filter by sender email address
"""
# In OSS, user_id is an explicit parameter (not inside filters)
if not sender:
results = self.memory.search(
query=query,
user_id=user_id,
filters={"memory_category": "email"},
filters={"user_id": user_id, "memory_category": "email"},
)
else:
results = self.memory.search(
query=query,
user_id=user_id,
filters={
"user_id": user_id,
"AND": [
{"memory_category": "email"},
{"sender": sender},
@@ -343,10 +341,9 @@ class EmailProcessor:
subject (str): Email subject to match
user_id (str): User identifier
"""
# In OSS, user_id is an explicit parameter
thread = self.memory.get_all(
user_id=user_id,
filters={
"user_id": user_id,
"AND": [
{"memory_category": "email"},
{"subject": {"icontains": subject}},
+1 -1
View File
@@ -57,7 +57,7 @@ class CustomerSupportAIAgent:
"""
# Start a streaming chat completion request to the AI
stream = self.client.chat.completions.create(
model="gpt-4",
model="gpt-5-mini",
stream=True,
messages=[
{"role": "system", "content": "You are a customer support AI agent."},