Added improved docs index and overview pages and quickstart (#3603)
This commit is contained in:
@@ -0,0 +1,336 @@
|
||||
---
|
||||
title: "Configuration"
|
||||
description: "Configure Mem0 with custom LLMs, vector stores, embedders, and rerankers for production deployments"
|
||||
icon: "sliders"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
Mem0 is highly configurable, allowing you to customize every component of your memory system. Choose from **51+ supported providers** across LLMs, vector databases, embedders, and rerankers.
|
||||
|
||||
## Quick Start
|
||||
|
||||
The simplest setup uses OpenAI defaults:
|
||||
|
||||
```python
|
||||
import os
|
||||
from mem0 import Memory
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "your-api-key"
|
||||
m = Memory()
|
||||
```
|
||||
|
||||
For production or custom setups, configure specific components:
|
||||
|
||||
```python
|
||||
from mem0 import Memory
|
||||
|
||||
config = {
|
||||
"vector_store": {
|
||||
"provider": "qdrant",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 6333
|
||||
}
|
||||
},
|
||||
"llm": {
|
||||
"provider": "openai",
|
||||
"config": {
|
||||
"model": "gpt-4.1-nano-2025-04-14",
|
||||
"temperature": 0.1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m = Memory.from_config(config)
|
||||
```
|
||||
|
||||
## Configuration Components
|
||||
|
||||
Mem0 has four configurable components. Click any to see all supported providers and detailed configuration options.
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="LLMs" icon="message-bot" href="/components/llms/overview">
|
||||
**17 providers** including OpenAI, Anthropic, Ollama, Groq, and more
|
||||
|
||||
Configure the language model for memory extraction and processing
|
||||
|
||||
</Card>
|
||||
|
||||
<Card title="Vector Databases" icon="hard-drive" href="/components/vectordbs/overview">
|
||||
**25+ databases** including Qdrant, Chroma, Pinecone, Weaviate, and more
|
||||
|
||||
Choose where to store and retrieve memory embeddings
|
||||
|
||||
</Card>
|
||||
|
||||
<Card title="Embedding Models" icon="cube" href="/components/embedders/overview">
|
||||
**9 providers** including OpenAI, HuggingFace, Ollama, and more
|
||||
|
||||
Select the model to convert memories into vector embeddings
|
||||
|
||||
</Card>
|
||||
|
||||
<Card title="Rerankers" icon="ranking-star" href="/components/rerankers/overview">
|
||||
**4 models** including Cohere, Zero Entropy, and LLM-based
|
||||
|
||||
Improve search relevance by re-scoring retrieved memories
|
||||
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Configuration Recipes
|
||||
|
||||
### Production Setup with Qdrant
|
||||
|
||||
For production deployments, use a dedicated vector store:
|
||||
|
||||
<Steps>
|
||||
<Step title="Start Qdrant">
|
||||
```bash
|
||||
docker pull qdrant/qdrant
|
||||
|
||||
docker run -p 6333:6333 -p 6334:6334 \
|
||||
-v $(pwd)/qdrant_storage:/qdrant/storage:z \
|
||||
qdrant/qdrant
|
||||
|
||||
````
|
||||
</Step>
|
||||
|
||||
<Step title="Configure Mem0">
|
||||
```python
|
||||
import os
|
||||
from mem0 import Memory
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "your-api-key"
|
||||
|
||||
config = {
|
||||
"vector_store": {
|
||||
"provider": "qdrant",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 6333,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m = Memory.from_config(config)
|
||||
````
|
||||
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
### Fully Local Setup
|
||||
|
||||
Run Mem0 completely offline with Ollama (no external APIs):
|
||||
|
||||
<Card title="Local Setup with Ollama" icon="server" href="/examples/mem0-with-ollama">
|
||||
Step-by-step guide to run Mem0 with local LLM and embeddings
|
||||
</Card>
|
||||
|
||||
### Multi-Cloud Setup
|
||||
|
||||
Mix providers from different clouds:
|
||||
|
||||
```python
|
||||
config = {
|
||||
"llm": {
|
||||
"provider": "azure_openai",
|
||||
"config": {
|
||||
"api_key": "azure-key",
|
||||
"deployment_name": "gpt-4.1-nano-2025-04-14"
|
||||
}
|
||||
},
|
||||
"vector_store": {
|
||||
"provider": "pinecone",
|
||||
"config": {
|
||||
"api_key": "pinecone-key",
|
||||
"index_name": "mem0"
|
||||
}
|
||||
},
|
||||
"embedder": {
|
||||
"provider": "vertexai",
|
||||
"config": {
|
||||
"model": "textembedding-gecko@003"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Graph Memory Setup
|
||||
|
||||
Enable relationship tracking with Neo4j:
|
||||
|
||||
```python
|
||||
config = {
|
||||
"graph_store": {
|
||||
"provider": "neo4j",
|
||||
"config": {
|
||||
"url": "neo4j+s://your-instance.databases.neo4j.io",
|
||||
"username": "neo4j",
|
||||
"password": "your-password"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m = Memory.from_config(config)
|
||||
```
|
||||
|
||||
<Card title="Graph Memory Guide" icon="diagram-project" href="/open-source/graph_memory/overview">
|
||||
Learn how to use graph memory for relationship-based retrieval
|
||||
</Card>
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
### Custom Prompts
|
||||
|
||||
Override default prompts for memory processing:
|
||||
|
||||
```python
|
||||
config = {
|
||||
"custom_fact_extraction_prompt": """
|
||||
Extract key facts from the conversation.
|
||||
Focus on: preferences, decisions, and context.
|
||||
Output as a single sentence.
|
||||
""",
|
||||
"custom_update_memory_prompt": """
|
||||
Update the existing memory with new information.
|
||||
Preserve important context from the old memory.
|
||||
"""
|
||||
}
|
||||
```
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Custom Fact Extraction" icon="sparkles" href="/open-source/features/custom-fact-extraction-prompt">
|
||||
Customize how memories are extracted from conversations
|
||||
</Card>
|
||||
|
||||
<Card title="Custom Memory Updates" icon="pen" href="/open-source/features/custom-update-memory-prompt">
|
||||
Control how existing memories are modified
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
### Reranking for Better Search
|
||||
|
||||
Add reranking to improve search relevance:
|
||||
|
||||
```python
|
||||
config = {
|
||||
"rerank": {
|
||||
"provider": "cohere",
|
||||
"config": {
|
||||
"model": "rerank-english-v3.0",
|
||||
"top_k": 5
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<Card title="Reranking Guide" icon="arrow-up-arrow-down" href="/open-source/features/reranking">
|
||||
Learn how reranking improves memory search accuracy
|
||||
</Card>
|
||||
|
||||
### History Database
|
||||
|
||||
Configure where operation history is stored:
|
||||
|
||||
```python
|
||||
config = {
|
||||
"history_db_path": "/custom/path/to/history.db"
|
||||
}
|
||||
```
|
||||
|
||||
## All Configuration Options
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="LLM Configuration">
|
||||
| Parameter | Description | Provider |
|
||||
|-----------------------|-----------------------------------------------|-------------------|
|
||||
| `provider` | LLM provider (e.g., "openai", "anthropic") | All |
|
||||
| `model` | Model to use | All |
|
||||
| `temperature` | Temperature of the model (0.0-2.0) | All |
|
||||
| `api_key` | API key to use | Most |
|
||||
| `max_tokens` | Maximum tokens to generate | All |
|
||||
| `top_p` | Nucleus sampling threshold | All |
|
||||
| `top_k` | Top-k sampling parameter | Some |
|
||||
| `ollama_base_url` | Base URL for Ollama API | Ollama |
|
||||
| `openai_base_url` | Base URL for OpenAI API | OpenAI |
|
||||
| `azure_kwargs` | Azure-specific initialization args | Azure OpenAI |
|
||||
|
||||
**See all 17 LLM providers:** [LLMs Overview](/components/llms/overview)
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Vector Store Configuration">
|
||||
Common parameters (provider-specific options vary):
|
||||
|
||||
| Parameter | Description | Example |
|
||||
| ----------------- | -------------------------- | ----------- |
|
||||
| `provider` | Vector store provider | "qdrant" |
|
||||
| `host` | Host address | "localhost" |
|
||||
| `port` | Port number | 6333 |
|
||||
| `collection_name` | Collection/index name | "memories" |
|
||||
| `api_key` | API key (for cloud stores) | "your-key" |
|
||||
|
||||
**See all 25+ vector stores:** [Vector Databases Overview](/components/vectordbs/overview)
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Embedder Configuration">
|
||||
| Parameter | Description | Default |
|
||||
|-------------|---------------------------------|------------------------------|
|
||||
| `provider` | Embedding provider | "openai" |
|
||||
| `model` | Embedding model to use | "text-embedding-3-small" |
|
||||
| `api_key` | API key for embedding service | None |
|
||||
|
||||
**See all 9 embedder providers:** [Embedders Overview](/components/embedders/overview)
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Reranker Configuration">
|
||||
| Parameter | Description | Example |
|
||||
|-------------|---------------------------------|------------------------------|
|
||||
| `provider` | Reranker provider | "cohere" |
|
||||
| `model` | Reranker model to use | "rerank-english-v3.0" |
|
||||
| `top_k` | Number of results to return | 5 |
|
||||
| `api_key` | API key for reranker service | "your-key" |
|
||||
|
||||
**See all reranker options:** [Rerankers Overview](/components/rerankers/overview)
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Graph Store Configuration">
|
||||
| Parameter | Description | Example |
|
||||
|-------------|---------------------------------|------------------------------|
|
||||
| `provider` | Graph store provider | "neo4j" |
|
||||
| `url` | Connection URL | "neo4j+s://..." |
|
||||
| `username` | Authentication username | "neo4j" |
|
||||
| `password` | Authentication password | "your-password" |
|
||||
|
||||
**Learn more:** [Graph Memory Overview](/open-source/graph_memory/overview)
|
||||
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="General Configuration">
|
||||
| Parameter | Description | Default |
|
||||
|------------------|--------------------------------------|----------------------------|
|
||||
| `history_db_path` | Path to the history database | "{mem0_dir}/history.db" |
|
||||
| `custom_fact_extraction_prompt` | Custom prompt for memory extraction | None |
|
||||
| `custom_update_memory_prompt` | Custom prompt for memory updates | None |
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Next Steps
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Python Quickstart" icon="python" href="/open-source/python-quickstart">
|
||||
Get started with the Python SDK
|
||||
</Card>
|
||||
|
||||
<Card title="Self-Hosting Features" icon="server" href="/open-source/features/overview">
|
||||
Explore OSS-specific capabilities
|
||||
</Card>
|
||||
|
||||
<Card title="Examples" icon="book" href="/examples">
|
||||
See configuration examples in action
|
||||
</Card>
|
||||
</CardGroup>
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Async Memory
|
||||
description: 'Asynchronous memory for Mem0'
|
||||
icon: "bolt"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
## AsyncMemory
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Custom Fact Extraction Prompt
|
||||
description: 'Enhance your product experience by adding custom fact extraction prompt tailored to your needs'
|
||||
icon: "pencil"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
## Introduction to Custom Fact Extraction Prompt
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
title: Custom Update Memory Prompt
|
||||
icon: "pencil"
|
||||
iconType: "solid"
|
||||
description: 'Control memory update actions with a custom prompt'
|
||||
---
|
||||
|
||||
|
||||
@@ -234,4 +233,4 @@ The prompt needs to guide the output to follow the structure as shown below:
|
||||
|---------|-------------------------------|-----------------|
|
||||
| Use case | Determine the action to be performed on the memory | Extract facts from messages |
|
||||
| Reference | Retrieved facts from messages and old memory | Messages |
|
||||
| Output | Action to be performed on the memory | Extracted facts |
|
||||
| Output | Action to be performed on the memory | Extracted facts |
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Enhanced Metadata Filtering
|
||||
description: 'Advanced filtering capabilities for precise memory retrieval in Mem0 1.0.0 '
|
||||
icon: "filter"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Info>
|
||||
@@ -386,4 +384,4 @@ results = m.search(
|
||||
|
||||
<Info>
|
||||
Enhanced metadata filtering provides powerful capabilities for precise memory retrieval. Start with simple filters and gradually adopt more complex patterns as needed.
|
||||
</Info>
|
||||
</Info>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Multimodal Support
|
||||
description: Integrate images into your interactions with Mem0
|
||||
icon: "image"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
Mem0 extends its capabilities beyond text by supporting multimodal data. With this feature, you can seamlessly integrate images into your interactions—allowing Mem0 to extract relevant information and context from visual content.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
title: OpenAI Compatibility
|
||||
icon: "code"
|
||||
iconType: "solid"
|
||||
description: 'Integrate Mem0 using OpenAI-compatible client APIs'
|
||||
---
|
||||
|
||||
Mem0 can be easily integrated into chat applications to enhance conversational agents with structured memory. Mem0's APIs are designed to be compatible with OpenAI's, with the goal of making it easy to leverage Mem0 in applications you may have already built.
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Overview
|
||||
description: 'Build powerful AI applications with self-improving memory using Mem0 open-source'
|
||||
icon: "eye"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
## Welcome to Mem0 Open Source
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Reranker-Enhanced Search
|
||||
description: 'Improve search relevance with reranking models in Mem0 1.0.0 '
|
||||
icon: "sort"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Info>
|
||||
@@ -415,4 +413,4 @@ results = m.search("query", user_id="alice") # Automatically reranked
|
||||
|
||||
<Info>
|
||||
Reranker-enhanced search significantly improves result relevance. Start with a local model and upgrade to API-based solutions as your needs grow.
|
||||
</Info>
|
||||
</Info>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
---
|
||||
title: Reranking
|
||||
description: 'Improve memory search relevance with advanced reranking capabilities'
|
||||
icon: "arrow-up-arrow-down"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
## Overview
|
||||
@@ -127,4 +125,4 @@ results = memory.search("query", user_id="alice", rerank=False)
|
||||
- Explore specific [reranker providers](../../components/rerankers/overview) and their capabilities
|
||||
- Learn about [configuration options](../../components/rerankers/config) for fine-tuning
|
||||
- Check out [Vector Stores](../../components/vectordbs/overview) for different storage backends
|
||||
- See [Async Memory](./async-memory) for non-blocking reranking operations
|
||||
- See [Async Memory](./async-memory) for non-blocking reranking operations
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
---
|
||||
title: REST API Server
|
||||
icon: "server"
|
||||
iconType: "solid"
|
||||
description: 'Reach every Mem0 capability through a FastAPI-powered REST server'
|
||||
---
|
||||
|
||||
Mem0 provides a REST API server (written using FastAPI). Users can perform all operations through REST endpoints. The API also includes OpenAPI documentation, accessible at `/docs` when the server is running.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Features
|
||||
description: 'Graph Memory features'
|
||||
icon: "list-check"
|
||||
icon: "sparkles"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
title: Overview
|
||||
description: 'Enhance your memory system with graph-based knowledge representation and retrieval'
|
||||
icon: "info"
|
||||
icon: "network-wired"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
|
||||
@@ -1,28 +1,86 @@
|
||||
---
|
||||
title: Overview
|
||||
icon: "eye"
|
||||
title: "Overview"
|
||||
icon: "code-branch"
|
||||
iconType: "solid"
|
||||
description: "Self-host Mem0 with full control over your infrastructure and data"
|
||||
---
|
||||
|
||||
Welcome to Mem0 Open Source, a powerful, self-hosted memory management solution for AI agents and assistants. With Mem0 OSS, you get full control over your infrastructure while maintaining complete customization flexibility.
|
||||
<Tip>
|
||||
**Mem0 v1.0.0 is now available** — Introducing rerankers, async by default, Azure support, and more. [View changelog →](/changelog)
|
||||
</Tip>
|
||||
|
||||
We offer two SDKs: Python and Node.js.
|
||||
## Self-Host Mem0 with Full Control
|
||||
|
||||
Check out our [GitHub repository](https://mem0.dev/gd) to explore the source code.
|
||||
Mem0 Open Source gives you a powerful, self-hosted memory layer for AI agents. Deploy on your infrastructure, customize every component, and maintain complete data ownership.
|
||||
|
||||
## Get Started
|
||||
|
||||
Choose your preferred SDK and get Mem0 running locally in minutes:
|
||||
|
||||
<CardGroup cols={2}>
|
||||
<Card title="Python SDK Guide" icon="python" href="/open-source/python-quickstart">
|
||||
Learn more about Mem0 OSS Python SDK
|
||||
</Card>
|
||||
<Card title="Node.js SDK Guide" icon="node" href="/open-source/node-quickstart">
|
||||
Learn more about Mem0 OSS Node.js SDK
|
||||
</Card>
|
||||
<Card title="Python Quickstart" icon="python" href="/open-source/python-quickstart">
|
||||
Install and configure Mem0 OSS with Python in 10 minutes
|
||||
</Card>
|
||||
|
||||
<Card title="Node.js Quickstart" icon="node" href="/open-source/node-quickstart">
|
||||
Set up Mem0 OSS with Node.js and TypeScript support
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Key Features
|
||||
## Explore OSS Capabilities
|
||||
|
||||
- **Full Infrastructure Control**: Host Mem0 on your own servers.
|
||||
- **Customizable Implementation**: Modify and extend functionality as needed.
|
||||
- **Local Development**: Perfect for development and testing.
|
||||
- **No Vendor Lock-in**: Own your data and infrastructure.
|
||||
- **Community Driven**: Benefit from and contribute to community improvements.
|
||||
Mem0 Open Source offers powerful features for building production-grade AI applications with memory. From graph-based knowledge structures to flexible component configuration, you have full control over how memory works in your system.
|
||||
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Graph Memory" icon="network-wired" href="/open-source/graph_memory/overview">
|
||||
Build relationship-aware memory with knowledge graph capabilities
|
||||
</Card>
|
||||
|
||||
<Card title="Component Configuration" icon="sliders" href="/open-source/configuration">
|
||||
Choose your LLM, vector database, embedding model, and rerankers
|
||||
</Card>
|
||||
|
||||
<Card title="REST API" icon="bolt" href="/open-source/features/rest-api">
|
||||
Build high-throughput pipelines with async clients and REST endpoints
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
<Note>
|
||||
**Platform vs OSS?** See our [comparison guide](/platform/platform-vs-oss) to understand which deployment option fits your use case.
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
## Why Choose Open Source?
|
||||
|
||||
| Benefit | What You Get |
|
||||
|---------|--------------|
|
||||
| **Full Infrastructure Control** | Host on your own servers with complete access to configuration and deployment |
|
||||
| **Complete Customization** | Modify implementation, extend functionality, and adapt to your specific needs |
|
||||
| **Local Development** | Perfect for development, testing, and air-gapped environments |
|
||||
| **No Vendor Lock-in** | Own your data, choose your stack, and maintain full independence |
|
||||
| **Community Driven** | Contribute to and benefit from active community improvements and integrations |
|
||||
|
||||
<Info>
|
||||
**Looking for production scale?** [Mem0 Platform](/platform/overview) offers managed infrastructure with advanced features like webhooks, multimodal support, and enterprise support.
|
||||
</Info>
|
||||
|
||||
<Note>
|
||||
**Need help?** Check out our [GitHub repository](https://mem0.dev/gd) for source code, issues, and community discussions.
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
## Default Components
|
||||
|
||||
<Note>
|
||||
**No configuration needed to get started.** Mem0 works out of the box with sensible defaults:
|
||||
|
||||
- **LLM**: OpenAI `gpt-4.1-nano-2025-04-14` via your `OPENAI_API_KEY`
|
||||
- **Embeddings**: OpenAI `text-embedding-3-small` (1536 dimensions)
|
||||
- **Vector store**: Local Qdrant instance storing data at `/tmp/qdrant`
|
||||
- **History storage**: SQLite database at `~/.mem0/history.db`
|
||||
- **Reranker**: Disabled unless you configure one
|
||||
|
||||
Override any component with [`Memory.from_config`](/open-source/configuration).
|
||||
</Note>
|
||||
|
||||
@@ -1,546 +1,95 @@
|
||||
---
|
||||
title: Python SDK Quickstart
|
||||
description: 'Get started with Mem0 quickly!'
|
||||
description: "Get started with Mem0 quickly!"
|
||||
icon: "python"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
> Welcome to the Mem0 quickstart guide. This guide will help you get up and running with Mem0 in no time.
|
||||
Get started with Mem0's Python SDK in under 5 minutes. This guide shows you how to install Mem0 and store your first memory.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Python 3.10 or higher
|
||||
- OpenAI API key ([Get one here](https://platform.openai.com/api-keys))
|
||||
|
||||
## Installation
|
||||
|
||||
To install Mem0, you can use pip. Run the following command in your terminal:
|
||||
|
||||
<Steps>
|
||||
<Step title="Install via pip">
|
||||
```bash
|
||||
pip install mem0ai
|
||||
```
|
||||
</Step>
|
||||
|
||||
## Basic Usage
|
||||
|
||||
### Initialize Mem0
|
||||
|
||||
<Tabs>
|
||||
<Tab title="Basic">
|
||||
<Step title="Initialize Memory">
|
||||
```python
|
||||
import os
|
||||
from mem0 import Memory
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "your-api-key"
|
||||
|
||||
m = Memory()
|
||||
m = Memory(api_key="your-openai-api-key")
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Async">
|
||||
</Step>
|
||||
|
||||
<Step title="Add a memory">
|
||||
```python
|
||||
import os
|
||||
from mem0 import AsyncMemory
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "your-api-key"
|
||||
|
||||
m = AsyncMemory()
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Advanced">
|
||||
If you want to run Mem0 in production, initialize using the following method:
|
||||
|
||||
Run Qdrant first:
|
||||
|
||||
```bash
|
||||
docker pull qdrant/qdrant
|
||||
|
||||
docker run -p 6333:6333 -p 6334:6334 \
|
||||
-v $(pwd)/qdrant_storage:/qdrant/storage:z \
|
||||
qdrant/qdrant
|
||||
```
|
||||
|
||||
Then, instantiate memory with qdrant server:
|
||||
|
||||
```python
|
||||
import os
|
||||
from mem0 import Memory
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "your-api-key"
|
||||
|
||||
config = {
|
||||
"vector_store": {
|
||||
"provider": "qdrant",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 6333,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
m = Memory.from_config(config)
|
||||
```
|
||||
</Tab>
|
||||
|
||||
<Tab title="Advanced (Graph Memory)">
|
||||
|
||||
```python
|
||||
import os
|
||||
from mem0 import Memory
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "your-api-key"
|
||||
|
||||
config = {
|
||||
"graph_store": {
|
||||
"provider": "neo4j",
|
||||
"config": {
|
||||
"url": "neo4j+s://---",
|
||||
"username": "neo4j",
|
||||
"password": "---"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m = Memory.from_config(config_dict=config)
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
|
||||
### Store a Memory
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
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."}
|
||||
{"role": "user", "content": "Hi, I'm Alex. I love basketball and gaming."},
|
||||
{"role": "assistant", "content": "Hey Alex! I'll remember your interests."}
|
||||
]
|
||||
m.add(messages, user_id="alex")
|
||||
```
|
||||
</Step>
|
||||
|
||||
# Store inferred memories (default behavior)
|
||||
result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})
|
||||
|
||||
# Store memories with agent and run context
|
||||
result = m.add(messages, user_id="alice", agent_id="movie-assistant", run_id="session-001", metadata={"category": "movie_recommendations"})
|
||||
|
||||
# Store raw messages without inference
|
||||
# result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"}, infer=False)
|
||||
<Step title="Search memories">
|
||||
```python
|
||||
results = m.search("What do you know about me?", filters={"user_id": "alex"})
|
||||
print(results)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
|
||||
"memory": "User is planning to watch a movie tonight.",
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"event": "ADD"
|
||||
},
|
||||
{
|
||||
"id": "cbb1fe73-0bf1-4067-8c1f-63aa53e7b1a4",
|
||||
"memory": "User is not a big fan of thriller movies.",
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"event": "ADD"
|
||||
},
|
||||
{
|
||||
"id": "475bde34-21e6-42ab-8bef-0ab84474f156",
|
||||
"memory": "User loves sci-fi movies.",
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"event": "ADD"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
### Retrieve Memories
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
# Get all memories
|
||||
all_memories = m.get_all(user_id="alice")
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
|
||||
"memory": "User is planning to watch a movie tonight.",
|
||||
"hash": "1a271c007316c94377175ee80e746a19",
|
||||
"created_at": "2025-02-27T16:33:20.557Z",
|
||||
"updated_at": "2025-02-27T16:33:27.051Z",
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
},
|
||||
{
|
||||
"id": "475bde34-21e6-42ab-8bef-0ab84474f156",
|
||||
"memory": "User loves sci-fi movies.",
|
||||
"hash": "285d07801ae42054732314853e9eadd7",
|
||||
"created_at": "2025-02-27T16:33:20.560Z",
|
||||
"updated_at": None,
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
},
|
||||
{
|
||||
"id": "cbb1fe73-0bf1-4067-8c1f-63aa53e7b1a4",
|
||||
"memory": "User is not a big fan of thriller movies.",
|
||||
"hash": "285d07801ae42054732314853e9eadd7",
|
||||
"created_at": "2025-02-27T16:33:20.560Z",
|
||||
"updated_at": None,
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
<br />
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
# Get a single memory by ID
|
||||
specific_memory = m.get("892db2ae-06d9-49e5-8b3e-585ef9b85b8e")
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
|
||||
"memory": "User is planning to watch a movie tonight.",
|
||||
"hash": "1a271c007316c94377175ee80e746a19",
|
||||
"created_at": "2025-02-27T16:33:20.557Z",
|
||||
"updated_at": None,
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
### Search Memories
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
related_memories = m.search(query="What do you know about me?", user_id="alice")
|
||||
```
|
||||
|
||||
```json Output
|
||||
**Output:**
|
||||
```json
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
|
||||
"memory": "User is planning to watch a movie tonight.",
|
||||
"hash": "1a271c007316c94377175ee80e746a19",
|
||||
"created_at": "2025-02-27T16:33:20.557Z",
|
||||
"updated_at": None,
|
||||
"score": 0.38920719231944799,
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
},
|
||||
{
|
||||
"id": "475bde34-21e6-42ab-8bef-0ab84474f156",
|
||||
"memory": "User loves sci-fi movies.",
|
||||
"hash": "285d07801ae42054732314853e9eadd7",
|
||||
"created_at": "2025-02-27T16:33:20.560Z",
|
||||
"updated_at": None,
|
||||
"score": 0.36869761478135689,
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
},
|
||||
{
|
||||
"id": "cbb1fe73-0bf1-4067-8c1f-63aa53e7b1a4",
|
||||
"memory": "User is not a big fan of thriller movies.",
|
||||
"hash": "285d07801ae42054732314853e9eadd7",
|
||||
"created_at": "2025-02-27T16:33:20.560Z",
|
||||
"updated_at": None,
|
||||
"score": 0.33855272141248272,
|
||||
"metadata": {
|
||||
"category": "movie_recommendations"
|
||||
},
|
||||
"user_id": "alice"
|
||||
"id": "mem_123abc",
|
||||
"memory": "Name is Alex. Enjoys basketball and gaming.",
|
||||
"user_id": "alex",
|
||||
"categories": ["personal_info"],
|
||||
"created_at": "2025-10-22T04:40:22.864647-07:00",
|
||||
"score": 0.89
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
</Step>
|
||||
</Steps>
|
||||
|
||||
### Update a Memory
|
||||
<Note>
|
||||
By default `Memory()` wires up:
|
||||
- OpenAI `gpt-4.1-nano-2025-04-14` for fact extraction and updates
|
||||
- OpenAI `text-embedding-3-small` embeddings (1536 dimensions)
|
||||
- Qdrant vector store with on-disk data at `/tmp/qdrant`
|
||||
- SQLite history at `~/.mem0/history.db`
|
||||
- No reranker (add one in the config when you need it)
|
||||
</Note>
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
result = m.update(memory_id="892db2ae-06d9-49e5-8b3e-585ef9b85b8e", data="I love India, it is my favorite country.")
|
||||
```
|
||||
## What's Next?
|
||||
|
||||
```json Output
|
||||
{'message': 'Memory updated successfully!'}
|
||||
```
|
||||
</CodeGroup>
|
||||
<CardGroup cols={3}>
|
||||
<Card title="Memory Operations" icon="database" href="/open-source/overview">
|
||||
Learn how to search, update, and manage memories with full CRUD operations
|
||||
</Card>
|
||||
|
||||
### Memory History
|
||||
<Card title="Configuration" icon="sliders" href="/open-source/configuration">
|
||||
Customize Mem0 with different LLMs, vector stores, and embedders for production use
|
||||
</Card>
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
history = m.history(memory_id="892db2ae-06d9-49e5-8b3e-585ef9b85b8e")
|
||||
```
|
||||
<Card title="Advanced Features" icon="sparkles" href="/open-source/features/async-memory">
|
||||
Explore async support, graph memory, and multi-agent memory organization
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
```json Output
|
||||
[
|
||||
{
|
||||
"id": 39,
|
||||
"memory_id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
|
||||
"previous_value": "User is planning to watch a movie tonight.",
|
||||
"new_value": "I love India, it is my favorite country.",
|
||||
"action": "UPDATE",
|
||||
"created_at": "2025-02-27T16:33:20.557Z",
|
||||
"updated_at": "2025-02-27T16:33:27.051Z",
|
||||
"is_deleted": 0
|
||||
},
|
||||
{
|
||||
"id": 37,
|
||||
"memory_id": "892db2ae-06d9-49e5-8b3e-585ef9b85b8e",
|
||||
"previous_value": null,
|
||||
"new_value": "User is planning to watch a movie tonight.",
|
||||
"action": "ADD",
|
||||
"created_at": "2025-02-27T16:33:20.557Z",
|
||||
"updated_at": null,
|
||||
"is_deleted": 0
|
||||
}
|
||||
]
|
||||
```
|
||||
</CodeGroup>
|
||||
## Additional Resources
|
||||
|
||||
### Delete Memory
|
||||
|
||||
```python
|
||||
# Delete a memory by id
|
||||
m.delete(memory_id="892db2ae-06d9-49e5-8b3e-585ef9b85b8e")
|
||||
# Delete all memories for a user
|
||||
m.delete_all(user_id="alice")
|
||||
```
|
||||
|
||||
### Reset Memory
|
||||
|
||||
```python
|
||||
m.reset() # Reset all memories
|
||||
```
|
||||
|
||||
## Advanced Memory Organization
|
||||
|
||||
Mem0 supports three key parameters for organizing memories:
|
||||
|
||||
- **`user_id`**: Organize memories by user identity.
|
||||
- **`agent_id`**: Organize memories by AI agent or assistant.
|
||||
- **`run_id`**: Organize memories by session, workflow, or execution context.
|
||||
|
||||
### Using All Three Parameters
|
||||
|
||||
```python
|
||||
# Store memories with full context
|
||||
m.add("User prefers vegetarian food",
|
||||
user_id="alice",
|
||||
agent_id="diet-assistant",
|
||||
run_id="consultation-001")
|
||||
|
||||
# Retrieve memories with different scopes
|
||||
all_user_memories = m.get_all(user_id="alice")
|
||||
agent_memories = m.get_all(user_id="alice", agent_id="diet-assistant")
|
||||
session_memories = m.get_all(user_id="alice", run_id="consultation-001")
|
||||
specific_memories = m.get_all(user_id="alice", agent_id="diet-assistant", run_id="consultation-001")
|
||||
|
||||
# Search with context
|
||||
general_search = m.search("What do you know about me?", user_id="alice")
|
||||
agent_search = m.search("What do you know about me?", user_id="alice", agent_id="diet-assistant")
|
||||
session_search = m.search("What do you know about me?", user_id="alice", run_id="consultation-001")
|
||||
```
|
||||
|
||||
## Configuration Parameters
|
||||
|
||||
Mem0 offers extensive configuration options to customize its behavior according to your needs. These configurations span different components like vector stores, language models, embedders, and graph stores.
|
||||
|
||||
<AccordionGroup>
|
||||
<Accordion title="Vector Store Configuration">
|
||||
| Parameter | Description | Default |
|
||||
|-------------|---------------------------------|-------------|
|
||||
| `provider` | Vector store provider (e.g., "qdrant") | "qdrant" |
|
||||
| `host` | Host address | "localhost" |
|
||||
| `port` | Port number | 6333 |
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="LLM Configuration">
|
||||
| Parameter | Description | Provider |
|
||||
|-----------------------|-----------------------------------------------|-------------------|
|
||||
| `provider` | LLM provider (e.g., "openai", "anthropic") | All |
|
||||
| `model` | Model to use | All |
|
||||
| `temperature` | Temperature of the model | All |
|
||||
| `api_key` | API key to use | All |
|
||||
| `max_tokens` | Tokens to generate | All |
|
||||
| `top_p` | Probability threshold for nucleus sampling | All |
|
||||
| `top_k` | Number of highest probability tokens to keep | All |
|
||||
| `http_client_proxies` | Allow proxy server settings | AzureOpenAI |
|
||||
| `models` | List of models | Openrouter |
|
||||
| `route` | Routing strategy | Openrouter |
|
||||
| `openrouter_base_url` | Base URL for Openrouter API | Openrouter |
|
||||
| `site_url` | Site URL | Openrouter |
|
||||
| `app_name` | Application name | Openrouter |
|
||||
| `ollama_base_url` | Base URL for Ollama API | Ollama |
|
||||
| `openai_base_url` | Base URL for OpenAI API | OpenAI |
|
||||
| `azure_kwargs` | Azure LLM args for initialization | AzureOpenAI |
|
||||
| `deepseek_base_url` | Base URL for DeepSeek API | DeepSeek |
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Embedder Configuration">
|
||||
| Parameter | Description | Default |
|
||||
|-------------|---------------------------------|------------------------------|
|
||||
| `provider` | Embedding provider | "openai" |
|
||||
| `model` | Embedding model to use | "text-embedding-3-small" |
|
||||
| `api_key` | API key for embedding service | None |
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Graph Store Configuration">
|
||||
| Parameter | Description | Default |
|
||||
|-------------|---------------------------------|-------------|
|
||||
| `provider` | Graph store provider (e.g., "neo4j") | "neo4j" |
|
||||
| `url` | Connection URL | None |
|
||||
| `username` | Authentication username | None |
|
||||
| `password` | Authentication password | None |
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="General Configuration">
|
||||
| Parameter | Description | Default |
|
||||
|------------------|--------------------------------------|----------------------------|
|
||||
| `history_db_path` | Path to the history database | "{mem0_dir}/history.db" |
|
||||
| `version` | API version | "v1.1" |
|
||||
| `custom_fact_extraction_prompt` | Custom prompt for memory processing | None |
|
||||
| `custom_update_memory_prompt` | Custom prompt for memory updates | None |
|
||||
</Accordion>
|
||||
|
||||
<Accordion title="Complete Configuration Example">
|
||||
```python
|
||||
config = {
|
||||
"vector_store": {
|
||||
"provider": "qdrant",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 6333
|
||||
}
|
||||
},
|
||||
"llm": {
|
||||
"provider": "openai",
|
||||
"config": {
|
||||
"api_key": "your-api-key",
|
||||
"model": "gpt-4"
|
||||
}
|
||||
},
|
||||
"embedder": {
|
||||
"provider": "openai",
|
||||
"config": {
|
||||
"api_key": "your-api-key",
|
||||
"model": "text-embedding-3-small"
|
||||
}
|
||||
},
|
||||
"graph_store": {
|
||||
"provider": "neo4j",
|
||||
"config": {
|
||||
"url": "neo4j+s://your-instance",
|
||||
"username": "neo4j",
|
||||
"password": "password"
|
||||
}
|
||||
},
|
||||
"history_db_path": "/path/to/history.db",
|
||||
"version": "v1.1",
|
||||
"custom_fact_extraction_prompt": "Optional custom prompt for fact extraction for memory",
|
||||
"custom_update_memory_prompt": "Optional custom prompt for update memory"
|
||||
}
|
||||
```
|
||||
</Accordion>
|
||||
</AccordionGroup>
|
||||
|
||||
## Run Mem0 Locally
|
||||
|
||||
Please refer to the example [Mem0 with Ollama](../examples/mem0-with-ollama) to run Mem0 locally.
|
||||
|
||||
|
||||
## Chat Completion
|
||||
|
||||
Mem0 can be easily integrated into chat applications to enhance conversational agents with structured memory. Mem0's APIs are designed to be compatible with OpenAI's, with the goal of making it easy to leverage Mem0 in applications you may have already built.
|
||||
|
||||
If you have a `Mem0 API key`, you can use it to initialize the client. Alternatively, you can initialize Mem0 without an API key if you're using it locally.
|
||||
|
||||
Mem0 supports several language models (LLMs) through integration with various [providers](https://litellm.vercel.app/docs/providers).
|
||||
|
||||
## Use Mem0 OSS
|
||||
|
||||
```python
|
||||
config = {
|
||||
"vector_store": {
|
||||
"provider": "qdrant",
|
||||
"config": {
|
||||
"host": "localhost",
|
||||
"port": 6333,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
client = Mem0(config=config)
|
||||
|
||||
chat_completion = client.chat.completions.create(
|
||||
messages=[
|
||||
{
|
||||
"role": "user",
|
||||
"content": "What's the capital of France?",
|
||||
}
|
||||
],
|
||||
model="gpt-4.1-nano-2025-04-14",
|
||||
)
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome contributions to Mem0. Here's how you can contribute:
|
||||
|
||||
1. Fork the repository and create your branch from `main`.
|
||||
2. Clone the forked repository to your local machine.
|
||||
3. Install the project dependencies:
|
||||
|
||||
```bash
|
||||
poetry install
|
||||
```
|
||||
|
||||
4. Install pre-commit hooks:
|
||||
|
||||
```bash
|
||||
pip install pre-commit # If pre-commit is not already installed
|
||||
pre-commit install
|
||||
```
|
||||
|
||||
5. Make your changes and ensure they adhere to the project's coding standards.
|
||||
|
||||
6. Run the tests locally:
|
||||
|
||||
```bash
|
||||
poetry run pytest
|
||||
```
|
||||
|
||||
7. If all tests pass, commit your changes and push to your fork.
|
||||
8. Open a pull request with a clear title and description.
|
||||
|
||||
Please ensure your code follows our coding conventions and is well-documented.
|
||||
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
- **[OpenAI Compatibility](/open-source/features/openai_compatibility)** - Use Mem0 with OpenAI-compatible chat completions
|
||||
- **[Contributing Guide](/contributing/development)** - Learn how to contribute to Mem0
|
||||
- **[Examples](/examples/mem0-with-ollama)** - See Mem0 in action with Ollama and other integrations
|
||||
|
||||
Reference in New Issue
Block a user