feat(oss): accept text in Memory.update(), deprecate data (#6044)
This commit is contained in:
@@ -15,6 +15,7 @@ Adding memory is how Mem0 captures useful details from a conversation so your ag
|
||||
- **Infer**: Controls whether Mem0 extracts structured memories (`infer=True`, default) or stores raw messages.
|
||||
- **Metadata**: Optional filters (e.g., `{"category": "movie_recommendations"}`) that improve retrieval later.
|
||||
- **User / Session identifiers**: `user_id`, `agent_id`, `app_id`, or `run_id` that scope the memory for future searches.
|
||||
- **expiration_date**: Optional `YYYY-MM-DD` date after which the memory is treated as expired. Use `expirationDate` in the JavaScript SDKs. Expired memories are hidden from `search` and `get_all` unless you pass `show_expired` (`showExpired` in JavaScript); fetching by ID still returns them.
|
||||
|
||||
## How does it work?
|
||||
|
||||
@@ -105,6 +106,9 @@ result = m.add(messages, user_id="alice", metadata={"category": "movie_recommend
|
||||
|
||||
# Optionally store raw messages without inference
|
||||
result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"}, infer=False)
|
||||
|
||||
# Optionally set an expiration date (YYYY-MM-DD)
|
||||
result = m.add(messages, user_id="alice", expiration_date="2030-01-31")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
@@ -123,6 +127,12 @@ const result = memory.add(messages, {
|
||||
userId: "alice",
|
||||
metadata: { category: "preferences" }
|
||||
});
|
||||
|
||||
// Optionally set an expiration date (YYYY-MM-DD)
|
||||
const expiring = memory.add(messages, {
|
||||
userId: "alice",
|
||||
expirationDate: "2030-01-31",
|
||||
});
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Mem0’s update operation lets you fix or enrich an existing memory without dele
|
||||
## Key terms
|
||||
|
||||
- **memory_id**: Unique identifier returned by `add` or `search` results.
|
||||
- **text** / **data**: New content that replaces the stored memory value.
|
||||
- **text**: New content that replaces the stored memory value. In the Python OSS SDK, `data` is a deprecated alias for `text`.
|
||||
- **metadata**: Optional key-value pairs you update alongside the text.
|
||||
- **timestamp**: Unix epoch (int/float) or ISO 8601 string to override the memory's timestamp.
|
||||
- **batch_update**: Platform API that edits multiple memories in a single request.
|
||||
@@ -110,17 +110,47 @@ from mem0 import Memory
|
||||
|
||||
memory = Memory()
|
||||
|
||||
# Replace the content
|
||||
memory.update(
|
||||
memory_id="mem_123",
|
||||
data="Alex now prefers decaf coffee",
|
||||
text="Alex now prefers decaf coffee",
|
||||
)
|
||||
|
||||
# Update content plus metadata and an expiration date (None clears it)
|
||||
memory.update(
|
||||
memory_id="mem_123",
|
||||
text="Alex now prefers decaf coffee",
|
||||
metadata={"category": "preferences"},
|
||||
expiration_date="2030-01-31",
|
||||
)
|
||||
```
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import { Memory } from "mem0ai/oss";
|
||||
|
||||
const memory = new Memory();
|
||||
|
||||
// Replace the content
|
||||
await memory.update("mem_123", { text: "Alex now prefers decaf coffee" });
|
||||
|
||||
// Update content plus metadata and an expiration date (null clears it)
|
||||
await memory.update("mem_123", {
|
||||
text: "Alex now prefers decaf coffee",
|
||||
metadata: { category: "preferences" },
|
||||
expirationDate: "2030-01-31",
|
||||
});
|
||||
|
||||
// Update metadata only, leaving the stored text untouched
|
||||
await memory.update("mem_123", { metadata: { category: "preferences" } });
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Note>
|
||||
OSS JavaScript SDK does not expose `update` yet: use the REST API or Python SDK when self-hosting.
|
||||
In both OSS SDKs the content is optional — pass only `metadata` and/or an expiration date to update those while keeping the existing content. At least one of the three must be provided, otherwise the call raises.
|
||||
</Note>
|
||||
|
||||
<Note>
|
||||
`data` is a deprecated alias for `text` in both OSS SDKs (`data=` in Python, `{ data: ... }` in JavaScript). It still works but logs a warning; prefer `text`. In JavaScript, passing a bare string is shorthand for `{ text }`, so `update(memoryId, "new text")` also still works.
|
||||
</Note>
|
||||
|
||||
## Tips
|
||||
@@ -138,7 +168,7 @@ memory.update(
|
||||
|
||||
| Capability | Mem0 Platform | Mem0 OSS |
|
||||
| --- | --- | --- |
|
||||
| Update call | `client.update(memory_id, {...})` | `memory.update(memory_id, data=...)` |
|
||||
| Update call | `client.update(memory_id, {...})` | `memory.update(memory_id, text=...)` |
|
||||
| Batch updates | `client.batch_update` (up to 1000 memories) | Script your own loop or bulk job |
|
||||
| Dashboard visibility | Inspect updates in the UI | Inspect via logs or custom tooling |
|
||||
| Immutable handling | Returns descriptive error | Raises exception: delete and re-add |
|
||||
|
||||
+2
-2
@@ -61,7 +61,7 @@ client.get_all(user_id="alice")
|
||||
client.get(memory_id="<id>")
|
||||
|
||||
# Update
|
||||
client.update(memory_id="<id>", data="Alice loves mountain hiking")
|
||||
client.update(memory_id="<id>", text="Alice loves mountain hiking")
|
||||
|
||||
# Delete
|
||||
client.delete(memory_id="<id>")
|
||||
@@ -118,7 +118,7 @@ m.get_all(user_id="alice")
|
||||
m.get(memory_id="<id>")
|
||||
|
||||
# Update
|
||||
m.update(memory_id="<id>", data="Alice loves mountain hiking")
|
||||
m.update(memory_id="<id>", text="Alice loves mountain hiking")
|
||||
|
||||
# Delete
|
||||
m.delete(memory_id="<id>")
|
||||
|
||||
@@ -36,7 +36,7 @@ icon: "bolt"
|
||||
| Search memories | `await memory.search(...)` | Returns dict with `results`, identical shape. |
|
||||
| List memories | `await memory.get_all(...)` | Filter by `user_id`, `agent_id`, `run_id`. |
|
||||
| Retrieve memory | `await memory.get(memory_id=...)` | Raises `ValueError` if ID is invalid. |
|
||||
| Update memory | `await memory.update(memory_id=..., data=...)` | Accepts partial updates. |
|
||||
| Update memory | `await memory.update(memory_id=..., text=...)` | Accepts partial updates. |
|
||||
| Delete memory | `await memory.delete(memory_id=...)` | Returns confirmation payload. |
|
||||
| Delete in bulk | `await memory.delete_all(...)` | Requires at least one scope filter. |
|
||||
| History | `await memory.history(memory_id=...)` | Fetches change log for auditing. |
|
||||
@@ -185,7 +185,7 @@ specific_memory = await memory.get(memory_id="memory-id-here")
|
||||
# Update a memory
|
||||
updated_memory = await memory.update(
|
||||
memory_id="memory-id-here",
|
||||
data="I'm travelling to Seattle"
|
||||
text="I'm travelling to Seattle"
|
||||
)
|
||||
|
||||
# Delete a memory
|
||||
|
||||
@@ -129,7 +129,7 @@ matches = await memory.search(
|
||||
```python
|
||||
await memory.update(
|
||||
memory_id=matches["results"][0]["id"],
|
||||
data="Morgan avoids shellfish and prefers boutique hotels in central Tokyo.",
|
||||
text="Morgan avoids shellfish and prefers boutique hotels in central Tokyo.",
|
||||
)
|
||||
```
|
||||
</Step>
|
||||
|
||||
Reference in New Issue
Block a user