---
title: Quickstart
description: 'Get started with Mem0 Platform in minutes'
---
## 1. Installation
Install the Mem0 Python package:
```bash
pip install mem0ai
```
## 2. API Key Setup
1. Sign in to [Mem0 Platform](https://app.mem0.ai/dashboard/api-keys)
2. Copy your API Key from the dashboard

## 3. Instantiate Client
```python
from mem0 import MemoryClient
client = MemoryClient(api_key="your-api-key")
```
## 4. Memory Operations
We provide a simple yet customizable interface for performing CRUD operations on memory. Here is how you can create and get memories:
### 4.1 Create Memories
For users (long-term memory):
```python
# create long-term memory for users
client.add("Remember my name is Deshraj Yadav.", user_id="deshraj")
client.add("I like to eat pizza and go out on weekends.", user_id="deshraj")
client.add("Oh I am actually allergic to cheese to cannot eat pizza anymore.", user_id="deshraj")
```
Output:
```python
{'message': 'Memory added successfully!'}
```
You can see all the memory operations happening on the platform itself.

You can also add memories for a particular session or for an AI agent that you are building:
- For user sessions (short-term memory):
```python
client.add("Deshraj is building Gmail AI agent", user_id="deshraj", session_id="session-1")
```
- For agents (long-term memory):
```python
client.add("Return short responses when responding to emails", agent_id="gmail-agent")
```
### 4.2 Retrieve Memories
```python Code
client.get_all(user_id="deshraj")
```
```python Output
[
{
'id': 'dbce6e06-6adf-40b8-9187-3d30bd13b741',
'agent': None,
'consumer': {
'id': 8,
'user_id': 'deshraj',
'metadata': None,
'created_at': '2024-07-17T16:47:23.899900-07:00',
'updated_at': '2024-07-17T16:47:23.899918-07:00'
},
'app': None,
'run': None,
'hash': '57288ac8a87c4ac8d3ac7f2075d264ca',
'input': 'Remember my name is Deshraj Yadav.',
'text': 'My name is Deshraj Yadav.',
'metadata': None,
'created_at': '2024-07-17T16:47:25.670180-07:00',
'updated_at': '2024-07-17T16:47:25.670197-07:00'
},
{
'id': 'f6dec5d1-b5db-45f5-a2fb-3979a0f27d30',
'agent': None,
'consumer': {
'id': 8,
'user_id': 'deshraj',
# ... other consumer fields ...
},
# ... other fields ...
'text': 'I am allergic to cheese so I cannot eat pizza anymore.',
# ... remaining fields ...
},
# ... additional memory entries ...
]
```
Similarly, you can get all memories for an agent:
```python
agent_memories = client.get_all(agent_id="gmail-agent")
```
Get specific memory:
```python Code
memory = client.get(memory_id="dbce6e06-6adf-40b8-9187-3d30bd13b741")
```
```python Output
{
'id': 'dbce6e06-6adf-40b8-9187-3d30bd13b741',
'agent': None,
'consumer': {
'id': 8,
'user_id': 'deshraj',
'metadata': None,
'created_at': '2024-07-17T16:47:23.899900-07:00',
'updated_at': '2024-07-17T16:47:23.899918-07:00'
},
'app': None,
'run': None,
'hash': '57288ac8a87c4ac8d3ac7f2075d264ca',
'input': 'Remember my name is Deshraj Yadav.',
'text': 'My name is Deshraj Yadav.',
'metadata': None,
'created_at': '2024-07-17T16:47:25.670180-07:00',
'updated_at': '2024-07-17T16:47:25.670197-07:00'
}
```
### 4.3 Update Memory
You can also update specific memory by using the following method:
```python Code
client.update(memory_id, data="Updated name is Deshraj Kumar")
```
```python Output
{
'id': 'dbce6e06-6adf-40b8-9187-3d30bd13b741',
'agent': None,
'consumer': {
'id': 8,
'user_id': 'deshraj',
'metadata': None,
'created_at': '2024-07-17T16:47:23.899900-07:00',
'updated_at': '2024-07-17T16:47:23.899918-07:00'
},
'app': None,
'run': None,
'hash': '57288ac8a87c4ac8d3ac7f2075d264ca',
'input': 'Updated name is Deshraj Kumar.',
'text': 'Name is Deshraj Kumar.',
'metadata': None,
'created_at': '2024-07-17T16:47:25.670180-07:00',
'updated_at': '2024-07-17T16:47:25.670197-07:00'
}
```
### 4.4 Memory History
Get history of how a memory has changed over time
```python Code
history = client.history(memory_id)
```
```python Output
[
{
'id': '51193804-2ee6-4f81-b4e7-497e98b70858',
'memory': {
'id': 'dbce6e06-6adf-40b8-9187-3d30bd13b741',
'agent': None,
'consumer': {
'id': 8,
'user_id': 'deshraj',
'metadata': None,
'created_at': '2024-07-17T16:47:23.899900-07:00',
'updated_at': '2024-07-17T16:47:23.899918-07:00'
},
'app': None,
'run': None,
'hash': '57288ac8a87c4ac8d3ac7f2075d264ca',
'input': 'Remember my name is Deshraj Yadav.',
'text': 'My name is Deshraj Yadav.',
'metadata': None,
'created_at': '2024-07-17T16:47:25.670180-07:00',
'updated_at': '2024-07-17T16:47:25.670197-07:00'
},
'hash': '57288ac8a87c4ac8d3ac7f2075d264ca',
'event': 'ADD',
'input': 'Remember my name is Deshraj Yadav.',
'previous_text': None,
'text': 'My name is Deshraj Yadav.',
'metadata': None,
'created_at': '2024-07-17T16:47:25.686899-07:00',
'updated_at': '2024-07-17T16:47:25.670197-07:00',
'change_description': 'Memory ADD event'
}
]
```
### 4.5 Search for relevant memories
```python Code
client.search("What does Deshraj like to eat?", user_id="deshraj", limit=3)
```
```python Output
[
{
"id": "dbce6e06-6adf-40b8-9187-3d30bd13b741",
"agent": null,
"consumer": {
"id": 8,
"user_id": "deshraj",
"metadata": null,
"created_at": "...",
"updated_at": "..."
},
"app": null,
"run": null,
"hash": "57288ac8a87c4ac8d3ac7f2075d264ca",
"input": "Remember my name is Deshraj Yadav.",
"text": "My name is Deshraj Yadav.",
"metadata": null,
"created_at": "2024-07-17T16:47:25.670180-07:00",
"updated_at": "..."
},
{
"id": "091dbed6-74b4-4e15-b765-81be2abe0d6b",
"agent": null,
"consumer": {
"id": 8,
"user_id": "deshraj",
"metadata": null,
"created_at": "...",
"updated_at": "..."
},
"app": null,
"run": null,
"hash": "622a5a24d5ac54136414a22ec12f9520",
"input": "Oh I am actually allergic to cheese to cannot eat pizza anymore.",
"text": "I like to eat pizza and go out on weekends.",
"metadata": null,
"created_at": "2024-07-17T16:49:24.276695-07:00",
"updated_at": "..."
},
{
"id": "5fb8f85d-3383-4bad-9d46-f171272478a4",
"agent": null,
"consumer": {
"id": 8,
"user_id": "deshraj",
"metadata": null,
"created_at": "...",
"updated_at": "..."
},
"app": null,
"run": {
"id": 1,
"run_id": "session-1",
"name": "",
"metadata": null,
"created_at": "...",
"updated_at": "..."
},
"hash": "179ced9649ac2b85350ece4946b1ee9b",
"input": "Deshraj is building Gmail AI agent",
"text": "Deshraj is building Gmail AI agent",
"metadata": null,
"created_at": "2024-07-17T16:52:41.278920-07:00",
"updated_at": "..."
},
{
"id": "f6dec5d1-b5db-45f5-a2fb-3979a0f27d30",
"agent": null,
"consumer": {
"id": 8,
"user_id": "deshraj",
"metadata": null,
"created_at": "...",
"updated_at": "..."
},
"app": null,
"run": null,
"hash": "19248f0766044b5973fc0ef1bf3955ef",
"input": "Oh I am actually allergic to cheese to cannot eat pizza anymore.",
"text": "I am allergic to cheese so I cannot eat pizza anymore.",
"metadata": null,
"created_at": "2024-07-17T16:49:38.622084-07:00",
"updated_at": "..."
}
]
```
### 4.6 Delete Memory
Delete specific memory:
```python Code
client.delete(memory_id)
```
```python Output
{'message': 'Memory deleted successfully!'}
```
Delete all memories of a user:
```python Code
client.delete_all(user_id="alex")
```
```python Output
{'message': 'Memories deleted successfully!'}
```