Files
wehub-resource-sync 555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:45 +08:00

202 lines
6.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Update Memory
description: Modify an existing memory by updating its content or metadata.
icon: "pen-to-square"
iconType: "solid"
---
# Keep Memories Accurate with Update
Mem0s update operation lets you fix or enrich an existing memory without deleting it. When a user changes their preference or clarifies a fact, use update to keep the knowledge base fresh.
## Key terms
- **memory_id**: Unique identifier returned by `add` or `search` results.
- **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.
- **immutable**: Flagged memories that must be deleted and re-added instead of updated.
## How the update flow works
<Steps>
<Step title="Locate the memory">
Use `search` or dashboard inspection to capture the `memory_id` you want to change.
</Step>
<Step title="Submit the update">
Call `update` (or `batch_update`) with new text and optional metadata. Mem0 overwrites the stored value and adjusts indexes.
</Step>
<Step title="Verify">
Check the response or re-run `search` to ensure the revised memory appears with the new content.
</Step>
</Steps>
## Single memory update (Platform)
<CodeGroup>
```python Python
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
memory_id = "your_memory_id"
client.update(
memory_id=memory_id,
text="Updated memory content about the user",
metadata={"category": "profile-update"},
timestamp="2025-01-15T12:00:00Z"
)
```
```javascript JavaScript
import MemoryClient from 'mem0ai';
const client = new MemoryClient({ apiKey: "your-api-key" });
const memory_id = "your_memory_id";
await client.update(memory_id, {
text: "Updated memory content about the user",
metadata: { category: "profile-update" },
timestamp: "2025-01-15T12:00:00Z"
});
```
</CodeGroup>
<Info icon="check">
Expect a confirmation message and the updated memory to appear in the dashboard almost instantly.
</Info>
## Batch update (Platform)
Update up to 1000 memories in one call.
<CodeGroup>
```python Python
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
update_memories = [
{"memory_id": "id1", "text": "Watches football"},
{"memory_id": "id2", "text": "Likes to travel"}
]
response = client.batch_update(update_memories)
print(response)
```
```javascript JavaScript
import MemoryClient from 'mem0ai';
const client = new MemoryClient({ apiKey: "your-api-key" });
const updateMemories = [
{ memoryId: "id1", text: "Watches football" },
{ memoryId: "id2", text: "Likes to travel" }
];
client.batchUpdate(updateMemories)
.then(response => console.log('Batch update response:', response))
.catch(error => console.error(error));
```
</CodeGroup>
## Update with Mem0 OSS
<CodeGroup>
```python Python
from mem0 import Memory
memory = Memory()
# Replace the content
memory.update(
memory_id="mem_123",
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>
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
- Update both `text` **and** `metadata` together to keep filters accurate.
- Batch updates are ideal after large imports or when syncing CRM corrections.
- Immutable memories must be deleted and re-added instead of updated.
- Pair updates with feedback signals (thumbs up/down) to self-heal memories automatically.
<Callout type="tip" icon="plug">
**MCP Alternative**: With <Link href="/platform/mem0-mcp">Mem0 MCP</Link>, AI agents can update their own memories when users correct information.
</Callout>
## Managed vs OSS differences
| Capability | Mem0 Platform | Mem0 OSS |
| --- | --- | --- |
| 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 |
## Put it into practice
- Review the <Link href="/api-reference/memory/update-memory">Update Memory API reference</Link> for request/response details.
- Combine updates with <Link href="/platform/features/feedback-mechanism">Feedback Mechanism</Link> to automate corrections.
## See it live
- <Link href="/cookbooks/operations/support-inbox">Support Inbox with Mem0</Link> uses updates to refine customer profiles.
- <Link href="/cookbooks/companions/ai-tutor">AI Tutor with Mem0</Link> demonstrates user preference corrections mid-course.
{/* DEBUG: verify CTA targets */}
<CardGroup cols={2}>
<Card
title="Learn Delete Concepts"
description="Understand when to remove memories instead of editing them."
icon="trash"
href="/core-concepts/memory-operations/delete"
/>
<Card
title="Automate Corrections"
description="See how feedback loops trigger updates in production."
icon="rocket"
href="/platform/features/feedback-mechanism"
/>
</CardGroup>