docs/platform/advanced-memory-operations.mdx
memory = AsyncMemoryClient(api_key=os.environ["MEM0_API_KEY"])
</Step>
</Steps>
</Tab>
<Tab title="TypeScript">
<Steps>
<Step title="Install the OSS SDK">
```bash
npm install mem0ai
const memory = new Memory({ apiKey: process.env.MEM0_API_KEY!, async: true });
</Step>
</Steps>
</Tab>
</Tabs>
## Add memories with metadata and graph context
<Tabs>
<Tab title="Python">
<Steps>
<Step title="Record conversations with metadata">
```python
conversation = [
{"role": "user", "content": "I'm Morgan, planning a 3-week trip to Japan in May."},
{"role": "assistant", "content": "Great! I'll track dietary notes and cities you mention."},
{"role": "user", "content": "Please remember I avoid shellfish and prefer boutique hotels in Tokyo."},
]
result = await memory.add(
conversation,
user_id="traveler-42",
metadata={"trip": "japan-2025", "preferences": ["boutique", "no-shellfish"]},
run_id="planning-call-1",
)
const result = await memory.add(conversation, { userId: "traveler-42", metadata: { trip: "japan-2025", preferences: ["boutique", "no-shellfish"] }, runId: "planning-call-1", });
</Step>
</Steps>
</Tab>
</Tabs>
<Info icon="check">
Successful calls return memories tagged with the metadata you passed. In the dashboard, confirm a graph edge between “Morgan” and “Tokyo” and verify the `trip=japan-2025` tag exists.
</Info>
## Retrieve and refine
<Tabs>
<Tab title="Python">
<Steps>
<Step title="Filter by metadata + reranker">
```python
matches = await memory.search(
"Any food alerts?",
user_id="traveler-42",
filters={"metadata.trip": "japan-2025"},
rerank=True,
include_vectors=False,
)
filters values and confirm metadata keys match (case-sensitive).