docs(cookbooks): fix v3 filters & update() in companions/essentials (#5844)
This commit is contained in:
@@ -31,7 +31,7 @@ const openaiClient = new OpenAI();
|
|||||||
const memory = new Memory();
|
const memory = new Memory();
|
||||||
|
|
||||||
async function chatWithMemories(message, userId = "default_user") {
|
async function chatWithMemories(message, userId = "default_user") {
|
||||||
const relevantMemories = await memory.search(message, { userId: userId });
|
const relevantMemories = await memory.search(message, { filters: { user_id: userId } });
|
||||||
|
|
||||||
const memoriesStr = relevantMemories.results
|
const memoriesStr = relevantMemories.results
|
||||||
.map(entry => `- ${entry.memory}`)
|
.map(entry => `- ${entry.memory}`)
|
||||||
|
|||||||
@@ -289,8 +289,7 @@ print([m["memory"] for m in constraints["results"]])
|
|||||||
```python
|
```python
|
||||||
constraints = memory.search(
|
constraints = memory.search(
|
||||||
query="injury concerns",
|
query="injury concerns",
|
||||||
user_id="max",
|
filters={"user_id": "max", "memory_bucket": {"in": ["constraints"]}},
|
||||||
filters={"memory_bucket": {"in": ["constraints"]}},
|
|
||||||
threshold=0.0 # optional: widen recall for short phrases
|
threshold=0.0 # optional: widen recall for short phrases
|
||||||
)
|
)
|
||||||
print([m["memory"] for m in constraints["results"]])
|
print([m["memory"] for m in constraints["results"]])
|
||||||
@@ -736,8 +735,7 @@ mem0_client.add(messages, user_id="max", run_id="nyc-2025")
|
|||||||
# Retrieve only Boston memories
|
# Retrieve only Boston memories
|
||||||
boston_memories = mem0_client.search(
|
boston_memories = mem0_client.search(
|
||||||
"training plan",
|
"training plan",
|
||||||
user_id="max",
|
filters={"user_id": "max", "run_id": "boston-2025"}
|
||||||
run_id="boston-2025"
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -749,8 +747,7 @@ memory.add(messages, user_id="max", run_id="nyc-2025")
|
|||||||
# Retrieve only Boston memories
|
# Retrieve only Boston memories
|
||||||
boston_memories = memory.search(
|
boston_memories = memory.search(
|
||||||
"training plan",
|
"training plan",
|
||||||
user_id="max",
|
filters={"user_id": "max", "run_id": "boston-2025"},
|
||||||
run_id="boston-2025",
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -846,8 +843,7 @@ Prioritize recent training over old data:
|
|||||||
```python
|
```python
|
||||||
recent = mem0_client.search(
|
recent = mem0_client.search(
|
||||||
"training progress",
|
"training progress",
|
||||||
user_id="max",
|
filters={"user_id": "max", "created_at": {"gte": "2025-10-01"}}
|
||||||
filters={"created_at": {"gte": "2025-10-01"}}
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -866,8 +862,7 @@ memory.add(
|
|||||||
cutoff = int(datetime(2025, 10, 1).timestamp())
|
cutoff = int(datetime(2025, 10, 1).timestamp())
|
||||||
recent = memory.search(
|
recent = memory.search(
|
||||||
"training progress",
|
"training progress",
|
||||||
user_id="max",
|
filters={"user_id": "max", "logged_epoch": {"gte": cutoff}},
|
||||||
filters={"logged_epoch": {"gte": cutoff}},
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -889,8 +884,7 @@ mem0_client.add(
|
|||||||
# Later, find all speed workouts
|
# Later, find all speed workouts
|
||||||
speed_sessions = mem0_client.search(
|
speed_sessions = mem0_client.search(
|
||||||
"speed work",
|
"speed work",
|
||||||
user_id="max",
|
filters={"user_id": "max", "metadata": {"workout_type": "speed"}}
|
||||||
filters={"metadata": {"workout_type": "speed"}}
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
@@ -905,8 +899,7 @@ memory.add(
|
|||||||
# Later, find all speed workouts
|
# Later, find all speed workouts
|
||||||
speed_sessions = memory.search(
|
speed_sessions = memory.search(
|
||||||
"speed work",
|
"speed work",
|
||||||
user_id="max",
|
filters={"user_id": "max", "workout_type": "speed"},
|
||||||
filters={"workout_type": "speed"},
|
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ Use `get_all()` with filters to retrieve everything for a specific user:
|
|||||||
```python
|
```python
|
||||||
dev_memories = client.get_all(
|
dev_memories = client.get_all(
|
||||||
filters={"user_id": "dev"},
|
filters={"user_id": "dev"},
|
||||||
|
page=1,
|
||||||
page_size=50
|
page_size=50
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user