docs/core-concepts/memory-operations/add.mdx
Adding memory is how Mem0 captures useful details from a conversation so your agents can reuse them later. Think of it as saving the important sentences from a chat transcript into a structured notebook your agent can search.
<Info> **Why it matters** - Preserves user preferences, goals, and feedback across sessions. - Powers personalization and decision-making in downstream conversations. - Keeps context consistent between managed Platform and OSS deployments. </Info>add.infer=True, default) or stores raw messages.{"category": "movie_recommendations"}) that improve retrieval later.user_id, agent_id, or run_id that scope the memory for future searches.Mem0 offers two flows:
Both flows take the same payload and pass it through the same pipeline.
<Frame caption="Architecture diagram illustrating the process of adding memories."> </Frame> <Steps> <Step title="Information extraction"> Mem0 sends the messages through an LLM that pulls out key facts, decisions, or preferences to remember. </Step> <Step title="Conflict resolution"> Existing memories are checked for duplicates or contradictions so the latest truth wins. </Step> <Step title="Storage"> The resulting memories land in managed vector storage (and optional graph storage) so future searches return them quickly. </Step> </Steps> <Warning> Duplicate protection only runs during that conflict-resolution step when you let Mem0 infer memories (`infer=True`, the default). If you switch to `infer=False`, Mem0 stores your payload exactly as provided, so duplicates will land. Mixing both modes for the same fact will save it twice. </Warning>You trigger this pipeline with a single add call—no manual orchestration needed.
client = MemoryClient(api_key="your-api-key")
messages = [ {"role": "user", "content": "I'm planning a trip to Tokyo next month."}, {"role": "assistant", "content": "Great! I’ll remember that for future suggestions."} ]
client.add( messages=messages, user_id="alice", )
```javascript JavaScript
import { MemoryClient } from "mem0ai";
const client = new MemoryClient({apiKey: "your-api-key"});
const messages = [
{ role: "user", content: "I'm planning a trip to Tokyo next month." },
{ role: "assistant", content: "Great! I’ll remember that for future suggestions." }
];
await client.add(messages, {
user_id: "alice",
});
os.environ["OPENAI_API_KEY"] = "your-api-key"
m = Memory()
messages = [ {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} ]
result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})
result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"}, infer=False)
```javascript JavaScript
import { Memory } from 'mem0ai/oss';
const memory = new Memory();
const messages = [
{
role: "user",
content: "I like to drink coffee in the morning and go for a walk"
}
];
const result = memory.add(messages, {
userId: "alice",
metadata: { category: "preferences" }
});
Add memory whenever your agent learns something useful:
Storing this context allows the agent to reason better in future interactions.
For full list of supported fields, required formats, and advanced options, see the Add Memory API Reference.
| Capability | Mem0 Platform | Mem0 OSS |
|---|---|---|
| Conflict resolution | Automatic with dashboard visibility | SDK handles merges locally; you control storage |
| Rate limits | Managed quotas per workspace | Limited by your hardware and provider APIs |
| Dashboard visibility | Yes — inspect memories visually | Inspect via CLI, logs, or custom UI |