Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

5.9 KB
Raw Blame
---
title: Quickstart
description: "Set up your Mem0 Platform account, install the SDK, and store your first memory in under five minutes."
icon: "bolt"
iconType: "solid"
---

In about five minutes you will get an API key, store your first memory, and search it back. Follow along in Python, JavaScript, cURL, or the terminal.

<Note>
**Are you an AI agent?** See [Sign up as an agent](/platform/agent-signup): create a working API key in four commands, with no email or dashboard.
</Note>

## Prerequisites

- Mem0 Platform account (<a href="https://app.mem0.ai?utm_source=oss&utm_medium=platform-quickstart">Sign up here</a>)
- API key (<a href="https://app.mem0.ai/dashboard/settings?tab=api-keys&subtab=configuration">Get one from dashboard</a>)
- Python 3.10+, Node.js 18+, or cURL. The CLI needs either Node.js 18+ or Python 3.10+.

## Store your first memory

<Steps>
<Step title="Install">
Pick a tab and use the same one for every step below.

<CodeGroup>
```bash Python
pip install mem0ai
```

```bash JavaScript
npm install mem0ai
```

```bash cURL
# Nothing to install. cURL ships with macOS and most Linux distributions.
```

```bash CLI
npm install -g @mem0/cli
# or, if you prefer Python: pip install mem0-cli
```

</CodeGroup>
</Step>

<Step title="Set your API key">
<CodeGroup>
```python Python
from mem0 import MemoryClient

client = MemoryClient(api_key="your-api-key")
```

```javascript JavaScript
import MemoryClient from 'mem0ai';
const client = new MemoryClient({ apiKey: 'your-api-key' });
```

```bash cURL
export MEM0_API_KEY="your-api-key"
```

```bash CLI
mem0 init --api-key "your-api-key"
```

</CodeGroup>
</Step>

<Step title="Add a memory">
<CodeGroup>
```python Python
messages = [
    {"role": "user", "content": "I'm a vegetarian and allergic to nuts."},
    {"role": "assistant", "content": "Got it! I'll remember your dietary preferences."}
]
client.add(messages, user_id="user123")
```

```javascript JavaScript
const messages = [
    {"role": "user", "content": "I'm a vegetarian and allergic to nuts."},
    {"role": "assistant", "content": "Got it! I'll remember your dietary preferences."}
];
await client.add(messages, { userId: "user123" });
```

```bash cURL
curl -X POST https://api.mem0.ai/v3/memories/add/ \
  -H "Authorization: Token $MEM0_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Im a vegetarian and allergic to nuts."},
      {"role": "assistant", "content": "Got it! Ill remember your dietary preferences."}
    ],
    "user_id": "user123"
  }'
```

```bash CLI
mem0 add "I'm a vegetarian and allergic to nuts." --user-id user123
```

</CodeGroup>

Mem0 pulls the individual facts out of the conversation and stores each one separately:

```json
{
  "results": [
    {"id": "0f2c1b6e-9a3d-4b18-8f77-1c2d3e4f5a6b", "memory": "Is a vegetarian", "event": "ADD"},
    {"id": "14e1b28a-2014-40ad-ac42-69c9ef42193d", "memory": "Allergic to nuts", "event": "ADD"}
  ]
}
```
</Step>

<Step title="Search memories">
<CodeGroup>
```python Python
results = client.search("What are my dietary restrictions?", filters={"user_id": "user123"})
print(results)
```

```javascript JavaScript
const results = await client.search("What are my dietary restrictions?", { filters: { user_id: "user123" } });
console.log(results);
```

```bash cURL
curl -X POST https://api.mem0.ai/v3/memories/search/ \
  -H "Authorization: Token $MEM0_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "What are my dietary restrictions?",
    "filters": {"user_id": "user123"}
  }'
```

```bash CLI
mem0 search "What are my dietary restrictions?" --user-id user123
```

</CodeGroup>

Both facts come back, ranked by how well they match the question:

```json
{
  "results": [
    {
      "id": "14e1b28a-2014-40ad-ac42-69c9ef42193d",
      "memory": "Allergic to nuts",
      "user_id": "user123",
      "agent_id": null,
      "app_id": null,
      "run_id": null,
      "categories": ["health"],
      "metadata": {},
      "created_at": "2025-10-22T04:40:22.864647-07:00",
      "updated_at": "2025-10-22T04:40:22.864647-07:00",
      "expiration_date": null,
      "score": 0.87
    },
    {
      "id": "0f2c1b6e-9a3d-4b18-8f77-1c2d3e4f5a6b",
      "memory": "Is a vegetarian",
      "user_id": "user123",
      "agent_id": null,
      "app_id": null,
      "run_id": null,
      "categories": ["food_preferences"],
      "metadata": {},
      "created_at": "2025-10-22T04:40:22.864647-07:00",
      "updated_at": "2025-10-22T04:40:22.864647-07:00",
      "expiration_date": null,
      "score": 0.81
    }
  ]
}
```

Pass these memories to your model as context, and it answers with what it already knows about the user instead of asking again.

</Step>
</Steps>

<Tip>
  Rather than calling `add` and `search` yourself, you can hand Mem0 to your agent as a set of tools and let it decide when to save and look things up. See [Mem0 MCP](/platform/mem0-mcp).
</Tip>

## What's next?

You stored and searched your first memory. Start with scoping, since every call you make from here needs it:

<CardGroup cols={2}>
<Card title="Scope memories to users and agents" icon="users" href="/platform/features/entity-scoped-memory">
  What `user_id` actually does, plus the `agent_id`, `app_id`, and `run_id` fields that came back empty above.
</Card>

<Card title="How Mem0 works" icon="diagram-project" href="/core-concepts/how-it-works">
  Why one sentence became two memories, and how Mem0 decides what to keep.
</Card>

<Card title="Update and delete memories" icon="database" href="/core-concepts/memory-operations/add">
  The operations beyond add and search, for when stored facts change or go stale.
</Card>

<Card title="Use Mem0 with your agent framework" icon="plug" href="/integrations">
  Wire memory into LangChain, CrewAI, LangGraph, or the OpenAI Agents SDK.
</Card>
</CardGroup>

<Note>
  Something not working? The [FAQs and troubleshooting](/platform/faqs) page covers the common setup errors.
</Note>