221 lines
4.8 KiB
Plaintext
221 lines
4.8 KiB
Plaintext
---
|
|
title: Quickstart
|
|
description: 'Get started with Mem0 Platform in minutes'
|
|
icon: "bolt"
|
|
iconType: "solid"
|
|
---
|
|
|
|
Get up and running with Mem0 Platform quickly. This guide covers the essential steps to start storing and retrieving memories.
|
|
|
|
## 1. Installation
|
|
|
|
<CodeGroup>
|
|
```bash pip
|
|
pip install mem0ai
|
|
```
|
|
|
|
```bash npm
|
|
npm install mem0ai
|
|
```
|
|
</CodeGroup>
|
|
|
|
## 2. API Key Setup
|
|
|
|
1. Sign in to [Mem0 Platform](https://mem0.dev/pd-api)
|
|
2. Copy your API Key from the dashboard
|
|
|
|

|
|
|
|
## 3. Initialize Client
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
import os
|
|
from mem0 import MemoryClient
|
|
|
|
os.environ["MEM0_API_KEY"] = "your-api-key"
|
|
client = MemoryClient()
|
|
```
|
|
|
|
```javascript JavaScript
|
|
import MemoryClient from 'mem0ai';
|
|
const client = new MemoryClient({ apiKey: 'your-api-key' });
|
|
```
|
|
</CodeGroup>
|
|
|
|
## 4. Basic Operations
|
|
|
|
### Add Memories
|
|
|
|
Store user preferences and context:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
messages = [
|
|
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and allergic to nuts."},
|
|
{"role": "assistant", "content": "Hello Alex! I'll remember your dietary preferences."}
|
|
]
|
|
|
|
result = client.add(messages, user_id="alex")
|
|
print(result)
|
|
```
|
|
|
|
```javascript JavaScript
|
|
const messages = [
|
|
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and allergic to nuts."},
|
|
{"role": "assistant", "content": "Hello Alex! I'll remember your dietary preferences."}
|
|
];
|
|
|
|
client.add(messages, { user_id: "alex" })
|
|
.then(result => console.log(result))
|
|
.catch(error => console.error(error));
|
|
```
|
|
</CodeGroup>
|
|
|
|
### Search Memories
|
|
|
|
Retrieve relevant memories based on queries:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
query = "What should I cook for dinner?"
|
|
results = client.search(query, user_id="alex")
|
|
print(results)
|
|
```
|
|
|
|
```javascript JavaScript
|
|
const query = "What should I cook for dinner?";
|
|
client.search(query, { user_id: "alex" })
|
|
.then(results => console.log(results))
|
|
.catch(error => console.error(error));
|
|
```
|
|
</CodeGroup>
|
|
|
|
### Get All Memories
|
|
|
|
Fetch all memories for a user:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
memories = client.get_all(user_id="alex")
|
|
print(memories)
|
|
```
|
|
|
|
```javascript JavaScript
|
|
client.getAll({ user_id: "alex" })
|
|
.then(memories => console.log(memories))
|
|
.catch(error => console.error(error));
|
|
```
|
|
</CodeGroup>
|
|
|
|
## 5. Memory Types
|
|
|
|
### User Memories
|
|
Long-term memories that persist across sessions:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
client.add(messages, user_id="alex", metadata={"category": "preferences"})
|
|
```
|
|
|
|
```javascript JavaScript
|
|
client.add(messages, { user_id: "alex", metadata: { category: "preferences" } });
|
|
```
|
|
</CodeGroup>
|
|
|
|
### Session Memories
|
|
Short-term memories for specific conversations:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
client.add(messages, user_id="alex", run_id="session-123")
|
|
```
|
|
|
|
```javascript JavaScript
|
|
client.add(messages, { user_id: "alex", run_id: "session-123" });
|
|
```
|
|
</CodeGroup>
|
|
|
|
### Agent Memories
|
|
Memories for AI assistants and agents:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
client.add(messages, agent_id="support-bot")
|
|
```
|
|
|
|
```javascript JavaScript
|
|
client.add(messages, { agent_id: "support-bot" });
|
|
```
|
|
</CodeGroup>
|
|
|
|
## 6. Advanced Features
|
|
|
|
### Async Processing
|
|
Process memories in the background for faster responses:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
client.add(messages, user_id="alex", async_mode=True)
|
|
```
|
|
|
|
```javascript JavaScript
|
|
client.add(messages, { user_id: "alex", async_mode: true });
|
|
```
|
|
</CodeGroup>
|
|
|
|
### Search with Filters
|
|
Filter results by categories and metadata:
|
|
|
|
<CodeGroup>
|
|
```python Python
|
|
results = client.search(
|
|
"food preferences",
|
|
user_id="alex",
|
|
categories=["preferences"],
|
|
metadata={"category": "food"}
|
|
)
|
|
```
|
|
|
|
```javascript JavaScript
|
|
client.search("food preferences", {
|
|
user_id: "alex",
|
|
categories: ["preferences"],
|
|
metadata: { category: "food" }
|
|
});
|
|
```
|
|
</CodeGroup>
|
|
|
|
## TypeScript Example
|
|
|
|
<CodeGroup>
|
|
```typescript TypeScript
|
|
import MemoryClient, { Message, MemoryOptions } from 'mem0ai';
|
|
|
|
const client = new MemoryClient('your-api-key');
|
|
|
|
const messages: Message[] = [
|
|
{ role: "user", content: "I love Italian food" },
|
|
{ role: "assistant", content: "Noted! I'll remember your preference for Italian cuisine." }
|
|
];
|
|
|
|
const options: MemoryOptions = {
|
|
user_id: "alex",
|
|
metadata: { category: "food_preferences" }
|
|
};
|
|
|
|
client.add(messages, options)
|
|
.then(result => console.log(result))
|
|
.catch(error => console.error(error));
|
|
```
|
|
</CodeGroup>
|
|
|
|
## Next Steps
|
|
|
|
Now that you're up and running, explore more advanced features:
|
|
|
|
- **[Advanced Memory Operations](/core-concepts/memory-operations)** - Learn about filtering, updating, and managing memories
|
|
- **[Platform Features](/platform/features/platform-overview)** - Discover advanced platform capabilities
|
|
- **[API Reference](/api-reference)** - Complete API documentation
|
|
|
|
<Snippet file="get-help.mdx" /> |