Mem0 1.0.0 (#3545)
This commit is contained in:
@@ -81,7 +81,7 @@ Once defined, register the criteria to your project:
|
||||
client.project.update(retrieval_criteria=retrieval_criteria)
|
||||
```
|
||||
|
||||
Criteria apply project-wide. Once set, they affect all searches using `version="v2"`.
|
||||
Criteria apply project-wide. Once set, they affect all searches automatically.
|
||||
|
||||
|
||||
## Example Walkthrough
|
||||
@@ -104,22 +104,18 @@ client.add(messages, user_id="alice")
|
||||
### Run Standard vs. Criteria-Based Search
|
||||
|
||||
```python
|
||||
# With criteria
|
||||
filters = {
|
||||
"AND": [
|
||||
{"user_id": "alice"}
|
||||
]
|
||||
}
|
||||
# Search with criteria enabled
|
||||
filters = {"user_id": "alice"}
|
||||
results_with_criteria = client.search(
|
||||
query="Why I am feeling happy today?",
|
||||
filters=filters,
|
||||
version="v2"
|
||||
filters=filters
|
||||
)
|
||||
|
||||
# Without criteria
|
||||
# To disable criteria for a specific search
|
||||
results_without_criteria = client.search(
|
||||
query="Why I am feeling happy today?",
|
||||
user_id="alice"
|
||||
filters=filters,
|
||||
use_criteria=False # Disable criteria-based scoring
|
||||
)
|
||||
```
|
||||
|
||||
@@ -163,10 +159,10 @@ results_without_criteria = client.search(
|
||||
| Control Over Relevance | None | Fully customizable with weighted criteria |
|
||||
| Memory Reordering | Static based on similarity | Dynamically re-ranked by intent alignment |
|
||||
| Emotional Sensitivity | No tone or trait awareness | Incorporates emotion, tone, or custom behaviors |
|
||||
| Version Required | Defaults | `search(version="v2")` |
|
||||
| Activation | Default (no criteria defined) | Enabled when criteria are defined in project |
|
||||
|
||||
<Note>
|
||||
If no criteria are defined for a project, `version="v2"` behaves like normal search.
|
||||
If no criteria are defined for a project, search behaves normally based on semantic similarity only.
|
||||
</Note>
|
||||
|
||||
|
||||
@@ -184,23 +180,23 @@ If no criteria are defined for a project, `version="v2"` behaves like normal sea
|
||||
## How It Works
|
||||
|
||||
1. **Criteria Definition**: Define custom criteria with a name, description, and weight. These describe what matters in a memory (e.g., joy, urgency, empathy).
|
||||
2. **Project Configuration**: Register these criteria using `project.update()`. They apply at the project level and influence all searches using `version="v2"`.
|
||||
3. **Memory Retrieval**: When you perform a search with `version="v2"`, Mem0 first retrieves relevant memories based on the query and your defined criteria.
|
||||
4. **Weighted Scoring**: Each retrieved memory is evaluated and scored against the defined criteria and weights.
|
||||
2. **Project Configuration**: Register these criteria using `project.update()`. They apply at the project level and automatically influence all searches.
|
||||
3. **Memory Retrieval**: When you perform a search, Mem0 first retrieves relevant memories based on the query.
|
||||
4. **Weighted Scoring**: Each retrieved memory is evaluated and scored against your defined criteria and weights.
|
||||
|
||||
This lets you prioritize memories that align with your agent’s goals and not just those that look similar to the query.
|
||||
This lets you prioritize memories that align with your agent's goals and not just those that look similar to the query.
|
||||
|
||||
<Note>
|
||||
Criteria retrieval is currently supported only in search v2. Make sure to use `version="v2"` when performing searches with custom criteria.
|
||||
Criteria retrieval is automatically enabled when criteria are defined in your project. Use `use_criteria=False` in search to temporarily disable it for a specific query.
|
||||
</Note>
|
||||
|
||||
|
||||
|
||||
## Summary
|
||||
|
||||
- Define what “relevant” means using criteria
|
||||
- Define what "relevant" means using criteria
|
||||
- Apply them per project via `project.update()`
|
||||
- Use `version="v2"` to activate criteria-aware search
|
||||
- Criteria-aware search activates automatically when criteria are configured
|
||||
- Build agents that reason not just with relevance, but **contextual importance**
|
||||
|
||||
---
|
||||
|
||||
@@ -68,7 +68,7 @@ You can retrieve all memories using the `get_all` method.
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
client.get_all(query="What is Alice's favorite sport?", user_id="alice", output_format="v1.1")
|
||||
client.get_all(query="What is Alice's favorite sport?", user_id="alice")
|
||||
```
|
||||
|
||||
```json Output
|
||||
|
||||
@@ -21,7 +21,7 @@ The Graph Memory feature analyzes how each entity connects and relates to each o
|
||||
|
||||
## Using Graph Memory
|
||||
|
||||
To use Graph Memory, you need to enable it in your API calls by setting the `enable_graph=True` parameter. You'll also need to specify `output_format="v1.1"` to receive the enriched response format.
|
||||
To use Graph Memory, you need to enable it in your API calls by setting the `enable_graph=True` parameter.
|
||||
|
||||
### Adding Memories with Graph Memory
|
||||
|
||||
@@ -46,11 +46,9 @@ messages = [
|
||||
|
||||
# Enable graph memory when adding
|
||||
client.add(
|
||||
messages,
|
||||
user_id="joseph",
|
||||
version="v1",
|
||||
enable_graph=True,
|
||||
output_format="v1.1"
|
||||
messages,
|
||||
user_id="joseph",
|
||||
enable_graph=True
|
||||
)
|
||||
```
|
||||
|
||||
@@ -73,9 +71,7 @@ const messages = [
|
||||
await client.add({
|
||||
messages,
|
||||
user_id: "joseph",
|
||||
version: "v1",
|
||||
enable_graph: true,
|
||||
output_format: "v1.1"
|
||||
enable_graph: true
|
||||
});
|
||||
```
|
||||
|
||||
@@ -125,10 +121,9 @@ When searching memories, Graph Memory helps retrieve entities that are contextua
|
||||
```python Python
|
||||
# Search with graph memory enabled
|
||||
results = client.search(
|
||||
"what is my name?",
|
||||
user_id="joseph",
|
||||
enable_graph=True,
|
||||
output_format="v1.1"
|
||||
"what is my name?",
|
||||
user_id="joseph",
|
||||
enable_graph=True
|
||||
)
|
||||
|
||||
print(results)
|
||||
@@ -139,8 +134,7 @@ print(results)
|
||||
const results = await client.search({
|
||||
query: "what is my name?",
|
||||
user_id: "joseph",
|
||||
enable_graph: true,
|
||||
output_format: "v1.1"
|
||||
enable_graph: true
|
||||
});
|
||||
|
||||
console.log(results);
|
||||
@@ -196,9 +190,8 @@ When retrieving all memories, Graph Memory provides additional relationship cont
|
||||
```python Python
|
||||
# Get all memories with graph context
|
||||
memories = client.get_all(
|
||||
user_id="joseph",
|
||||
enable_graph=True,
|
||||
output_format="v1.1"
|
||||
user_id="joseph",
|
||||
enable_graph=True
|
||||
)
|
||||
|
||||
print(memories)
|
||||
@@ -208,8 +201,7 @@ print(memories)
|
||||
// Get all memories with graph context
|
||||
const memories = await client.getAll({
|
||||
user_id: "joseph",
|
||||
enable_graph: true,
|
||||
output_format: "v1.1"
|
||||
enable_graph: true
|
||||
});
|
||||
|
||||
console.log(memories);
|
||||
@@ -304,8 +296,7 @@ messages = [
|
||||
|
||||
client.add(
|
||||
messages,
|
||||
user_id="joseph",
|
||||
output_format="v1.1"
|
||||
user_id="joseph"
|
||||
)
|
||||
```
|
||||
|
||||
@@ -319,7 +310,7 @@ const client = new MemoryClient({
|
||||
});
|
||||
|
||||
// Enable graph memory for all operations in this project
|
||||
await client.updateProject({ enable_graph: true, version: "v1" });
|
||||
await client.project.update({ enable_graph: true });
|
||||
|
||||
// Now all add operations will use graph memory by default
|
||||
const messages = [
|
||||
@@ -330,8 +321,7 @@ const messages = [
|
||||
|
||||
await client.add({
|
||||
messages,
|
||||
user_id: "joseph",
|
||||
output_format: "v1.1"
|
||||
user_id: "joseph"
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@@ -63,7 +63,6 @@ messages = [
|
||||
response = client.add(
|
||||
messages,
|
||||
run_id="group_chat_1",
|
||||
output_format="v1.1",
|
||||
infer=True
|
||||
)
|
||||
print(response)
|
||||
@@ -103,6 +102,7 @@ Retrieve all memories from a specific group chat session:
|
||||
|
||||
```python Python
|
||||
# Get all memories for a specific run_id
|
||||
# Use wildcard "*" for user_id to match all participants
|
||||
filters = {
|
||||
"AND": [
|
||||
{"user_id": "*"},
|
||||
@@ -110,7 +110,7 @@ filters = {
|
||||
]
|
||||
}
|
||||
|
||||
all_memories = client.get_all(version="v2", filters=filters, page=1)
|
||||
all_memories = client.get_all(filters=filters, page=1)
|
||||
print(all_memories)
|
||||
```
|
||||
|
||||
@@ -160,7 +160,7 @@ filters = {
|
||||
]
|
||||
}
|
||||
|
||||
charlie_memories = client.get_all(version="v2", filters=filters, page=1)
|
||||
charlie_memories = client.get_all(filters=filters, page=1)
|
||||
print(charlie_memories)
|
||||
```
|
||||
|
||||
@@ -197,8 +197,7 @@ filters = {
|
||||
|
||||
search_response = client.search(
|
||||
query="What are the tasks?",
|
||||
filters=filters,
|
||||
version="v2"
|
||||
filters=filters
|
||||
)
|
||||
print(search_response)
|
||||
```
|
||||
@@ -229,7 +228,6 @@ Group chat also supports async processing for improved performance:
|
||||
response = client.add(
|
||||
messages,
|
||||
run_id="groupchat_async",
|
||||
output_format="v1.1",
|
||||
infer=True,
|
||||
async_mode=True
|
||||
)
|
||||
|
||||
@@ -77,12 +77,13 @@ You can optionally provide additional instructions to guide how memories are pro
|
||||
|
||||
```python Python
|
||||
# Basic export request
|
||||
filters = {"user_id": "alice"}
|
||||
response = client.create_memory_export(
|
||||
schema=json_schema,
|
||||
user_id="alice"
|
||||
filters=filters
|
||||
)
|
||||
|
||||
# Export with custom instructions
|
||||
# Export with custom instructions and additional filters
|
||||
export_instructions = """
|
||||
1. Create a comprehensive profile with detailed information in each category
|
||||
2. Only mark fields as "None" when absolutely no relevant information exists
|
||||
@@ -91,10 +92,10 @@ export_instructions = """
|
||||
5. Clearly distinguish between factual statements and inferences
|
||||
"""
|
||||
|
||||
# For create operation, using only user_id filter as requested
|
||||
filters = {
|
||||
"AND": [
|
||||
{"user_id": "alex"}
|
||||
{"user_id": "alex"},
|
||||
{"created_at": {"gte": "2024-01-01"}}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -109,12 +110,13 @@ print(response)
|
||||
|
||||
```javascript JavaScript
|
||||
// Basic Export request
|
||||
const filters = {"user_id": "alice"};
|
||||
const response = await client.createMemoryExport({
|
||||
schema: json_schema,
|
||||
user_id: "alice"
|
||||
filters: filters
|
||||
});
|
||||
|
||||
// Export with custom instructions
|
||||
// Export with custom instructions and additional filters
|
||||
const export_instructions = `
|
||||
1. Create a comprehensive profile with detailed information in each category
|
||||
2. Only mark fields as "None" when absolutely no relevant information exists
|
||||
@@ -126,7 +128,8 @@ const export_instructions = `
|
||||
// For create operation, using only user_id filter as requested
|
||||
const filters = {
|
||||
"AND": [
|
||||
{"user_id": "alex"}
|
||||
{"user_id": "alex"},
|
||||
{"created_at": {"gte": "2024-01-01"}}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -145,7 +148,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/export/" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"schema": {json_schema},
|
||||
"user_id": "alice",
|
||||
"filters": {"user_id": "alice"},
|
||||
"export_instructions": "1. Create a comprehensive profile with detailed information\n2. Only mark fields as \"None\" when absolutely no relevant information exists"
|
||||
}'
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user