Doc: Update add memories (#2306)

This commit is contained in:
Dev Khant
2025-03-05 15:27:44 +05:30
committed by GitHub
parent 2611343cbe
commit eca1e06711

View File

@@ -352,6 +352,65 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
The `agent_id` retains memories exclusively based on messages generated by the assistant or those explicitly provided as input to the assistant. Messages outside these criteria are not stored as memory.
</Note>
#### Long-term memory for both users and agents
When you provide both `user_id` and `agent_id`, Mem0 will store memories separately for each:
- User messages are stored under the specified `user_id`
- Assistant messages are stored under the specified `agent_id`
This allows both the user and agent to maintain their own consistent memory across sessions.
<CodeGroup>
```python Python
messages = [
{"role": "user", "content": "I'm travelling to San Francisco"},
{"role": "assistant", "content": "That's great! I'm going to Dubai next month."},
]
client.add(messages=messages, user_id="user1", agent_id="agent1")
```
```javascript JavaScript
const messages = [
{"role": "user", "content": "I'm travelling to San Francisco"},
{"role": "assistant", "content": "That's great! I'm going to Dubai next month."},
]
client.add(messages, { user_id: "user1", agent_id: "agent1" })
.then(response => console.log(response))
.catch(error => console.error(error));
```
```bash cURL
curl -X POST "https://api.mem0.ai/v1/memories/" \
-H "Authorization: Token your-api-key" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{"role": "user", "content": "I'm travelling to San Francisco"},
{"role": "assistant", "content": "That's great! I'm going to Dubai next month."},
],
"user_id": "user1",
"agent_id": "agent1"
}'
```
```json Output
[
{
'id': 'c57abfa2-f0ac-48af-896a-21728dbcecee0',
'data': {'memory': 'Travelling to San Francisco'},
'event': 'ADD'
},
{ 'id': '0e8c003f-7db7-426a-9fdc-a46f9331a0c2',
'data': {'memory': 'Going to Dubai next month'},
'event': 'ADD'
}
]
```
</CodeGroup>
#### Monitor Memories
@@ -1230,11 +1289,6 @@ const filters = {
"categories":{
"contains": "food_preferences"
}
},
{
"keywords":{
"contains": "to play"
}
}
]
};
@@ -1258,20 +1312,14 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2" \
-d '{
"filters": {
"AND": [
{
"user_id": "alex"
},
{
"created_at": {
"gte": "2024-07-01",
"lte": "2024-07-31"
}
},
{
"categories":{
{"user_id":"alex"},
{"created_at":{
"gte":"2024-07-01",
"lte":"2024-07-31"
}},
{"categories":{
"contains": "food_preferences"
}
}
}}
]
}
}'
@@ -1283,15 +1331,14 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \
-d '{
"filters": {
"AND": [
{
"user_id": "alex"
},
{
"created_at": {
"gte": "2024-07-01",
"lte": "2024-07-31"
}
}
{"user_id":"alex"},
{"created_at":{
"gte":"2024-07-01",
"lte":"2024-07-31"
}},
{"categories":{
"contains": "food_preferences"
}}
]
}
}'
@@ -1392,7 +1439,7 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2" \
"categories": {
"contains": "food_preferences"
}
}
}}
]
}
}'
@@ -1409,7 +1456,7 @@ curl -X GET "https://api.mem0.ai/v1/memories/?version=v2&page=1&page_size=50" \
"categories": {
"contains": "food_preferences"
}
}
}}
]
}
}'
@@ -1767,12 +1814,10 @@ print(response)
```
```javascript JavaScript
const updateMemories = [
{
memoryId: "285ed74b-6e05-4043-b16b-3abd5b533496",
{"memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496",
text: "Watches football"
},
{
memoryId: "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07",
{"memory_id": "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07",
text: "Loves to travel"
}
];
@@ -1817,8 +1862,7 @@ response = client.batch_delete(delete_memories)
print(response)
```
```javascript JavaScript
const deleteMemories = [
{"memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496"},
const deleteMemories = [{"memory_id": "285ed74b-6e05-4043-b16b-3abd5b533496"},
{"memory_id": "2c9bd859-d1b7-4d33-a6b8-94e0147c4f07"}
];