improved docs (#1834)
This commit is contained in:
@@ -4,14 +4,16 @@ title: Features
|
|||||||
|
|
||||||
## Core features
|
## Core features
|
||||||
|
|
||||||
- **User, Session, and AI Agent Memory**: Retains information across user sessions, interactions, and AI agents, ensuring continuity and context.
|
- **User, Session, and AI Agent Memory**: Retains information across sessions and interactions for users and AI agents, ensuring continuity and context.
|
||||||
- **Adaptive Personalization**: Continuously improves personalization based on user interactions and feedback.
|
- **Adaptive Personalization**: Continuously updates memories based on user interactions and feedback.
|
||||||
- **Developer-Friendly API**: Offers a straightforward API for seamless integration into various applications.
|
- **Developer-Friendly API**: Offers a straightforward API for seamless integration into various applications.
|
||||||
- **Platform Consistency**: Ensures consistent behavior and data across different platforms and devices.
|
- **Platform Consistency**: Ensures consistent behavior and data across different platforms and devices.
|
||||||
- **Managed Service**: Provides a hosted solution for easy deployment and maintenance.
|
- **Managed Service**: Provides a hosted solution for easy deployment and maintenance.
|
||||||
|
- **Save Costs**: Saves costs by adding relevent memories instead of complete transcripts to context window
|
||||||
|
|
||||||
|
|
||||||
## How Mem0 Works?
|
|
||||||
|
## How does Mem0 work?
|
||||||
|
|
||||||
Mem0 leverages a hybrid database approach to manage and retrieve long-term memories for AI agents and assistants. Each memory is associated with a unique identifier, such as a user ID or agent ID, allowing Mem0 to organize and access memories specific to an individual or context.
|
Mem0 leverages a hybrid database approach to manage and retrieve long-term memories for AI agents and assistants. Each memory is associated with a unique identifier, such as a user ID or agent ID, allowing Mem0 to organize and access memories specific to an individual or context.
|
||||||
|
|
||||||
@@ -19,18 +21,18 @@ When a message is added to the Mem0 using add() method, the system extracts rel
|
|||||||
|
|
||||||
When an AI agent or LLM needs to recall memories, it uses the search() method. Mem0 then performs search across these data stores, retrieving relevant information from each source. This information is then passed through a scoring layer, which evaluates their importance based on relevance, importance, and recency. This ensures that only the most personalized and useful context is surfaced.
|
When an AI agent or LLM needs to recall memories, it uses the search() method. Mem0 then performs search across these data stores, retrieving relevant information from each source. This information is then passed through a scoring layer, which evaluates their importance based on relevance, importance, and recency. This ensures that only the most personalized and useful context is surfaced.
|
||||||
|
|
||||||
The retrieved memories can then be appended to the LLM's prompt as needed, enhancing the personalization and relevance of its responses.
|
The retrieved memories can then be appended to the LLM's prompt as needed, making responses personalized and relevant.
|
||||||
|
|
||||||
|
|
||||||
## Common Use Cases
|
## Common Use Cases
|
||||||
|
|
||||||
- **Personalized Learning Assistants**: Long-term memory allows learning assistants to remember user preferences, past interactions, and progress, providing a more tailored and effective learning experience.
|
- **Personalized Learning Assistants**: Long-term memory allows learning assistants to remember user preferences, strengths and weaknesses, and progress, providing a more tailored and effective learning experience.
|
||||||
|
|
||||||
- **Customer Support AI Agents**: By retaining information from previous interactions, customer support bots can offer more accurate and context-aware assistance, improving customer satisfaction and reducing resolution times.
|
- **Customer Support AI Agents**: By retaining information from previous interactions, customer support bots can offer more accurate and context-aware assistance, improving customer satisfaction and reducing resolution times.
|
||||||
|
|
||||||
- **Healthcare Assistants**: Long-term memory enables healthcare assistants to keep track of patient history, medication schedules, and treatment plans, ensuring personalized and consistent care.
|
- **Healthcare Assistants**: Long-term memory enables healthcare assistants to keep track of patient history, medication schedules, and treatment plans, ensuring personalized and consistent care.
|
||||||
|
|
||||||
- **Virtual Companions**: Virtual companions can use long-term memory to build deeper relationships with users by remembering personal details, preferences, and past conversations, making interactions more meaningful.
|
- **Virtual Companions**: Virtual companions can use long-term memory to build deeper relationships with users by remembering personal details, preferences, and past conversations, making interactions more delightful.
|
||||||
|
|
||||||
- **Productivity Tools**: Long-term memory helps productivity tools remember user habits, frequently used documents, and task history, streamlining workflows and enhancing efficiency.
|
- **Productivity Tools**: Long-term memory helps productivity tools remember user habits, frequently used documents, and task history, streamlining workflows and enhancing efficiency.
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ Mem0's memory implementation for Large Language Models (LLMs) offers several adv
|
|||||||
|
|
||||||
- **Entity Relationships**: Mem0 can understand and relate entities across different interactions, unlike RAG which retrieves information from static documents. This leads to a deeper understanding of context and relationships.
|
- **Entity Relationships**: Mem0 can understand and relate entities across different interactions, unlike RAG which retrieves information from static documents. This leads to a deeper understanding of context and relationships.
|
||||||
|
|
||||||
- **Recency, Relevancy, and Decay**: Mem0 prioritizes recent interactions and gradually forgets outdated information, ensuring the memory remains relevant and up-to-date for more accurate responses.
|
- **Recency, Relevancy, and Decay**: Mem0 uses custom search algorithms to prioritize recent interactions and gradually forgets outdated information, ensuring the memory remains relevant and up-to-date for more accurate responses.
|
||||||
|
|
||||||
- **Contextual Continuity**: Mem0 retains information across sessions, maintaining continuity in conversations and interactions, which is essential for long-term engagement applications like virtual companions or personalized learning assistants.
|
- **Contextual Continuity**: Mem0 retains information across sessions, maintaining continuity in conversations and interactions, which is essential for long-term engagement applications like virtual companions or personalized learning assistants.
|
||||||
|
|
||||||
|
|||||||
BIN
docs/images/playground/pg-add-memory.png
Normal file
BIN
docs/images/playground/pg-add-memory.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
BIN
docs/images/playground/pg-retrieve-memory.png
Normal file
BIN
docs/images/playground/pg-retrieve-memory.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
@@ -52,6 +52,8 @@
|
|||||||
"group": "Get Started",
|
"group": "Get Started",
|
||||||
"pages": [
|
"pages": [
|
||||||
"overview",
|
"overview",
|
||||||
|
"quickstart",
|
||||||
|
"playground",
|
||||||
"features"
|
"features"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ config = {
|
|||||||
m = Memory.from_config(config_dict=config)
|
m = Memory.from_config(config_dict=config)
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to use a managed version of Mem0, please check out [Mem0](https://app.mem0.ai). If you have any questions, please feel free to reach out to us using one of the following methods:
|
If you want to use a managed version of Mem0, please check out [Mem0](https://mem0.dev/pd). If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||||
|
|
||||||
<Snippet file="get-help.mdx" />
|
<Snippet file="get-help.mdx" />
|
||||||
|
|||||||
@@ -299,6 +299,6 @@ m.search("Who is spiderman?", user_id="alice123")
|
|||||||
|
|
||||||
> **Note:** The Graph Memory implementation is not standalone. You will be adding/retrieving memories to the vector store and the graph store simultaneously.
|
> **Note:** The Graph Memory implementation is not standalone. You will be adding/retrieving memories to the vector store and the graph store simultaneously.
|
||||||
|
|
||||||
If you want to use a managed version of Mem0, please check out [Mem0](https://app.mem0.ai). If you have any questions, please feel free to reach out to us using one of the following methods:
|
If you want to use a managed version of Mem0, please check out [Mem0](https://mem0.dev/pd). If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||||
|
|
||||||
<Snippet file="get-help.mdx" />
|
<Snippet file="get-help.mdx" />
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: Quickstart
|
title: Guide
|
||||||
description: 'Get started with Mem0 quickly!'
|
description: 'Get started with Mem0 quickly!'
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -2,317 +2,29 @@
|
|||||||
title: Overview
|
title: Overview
|
||||||
---
|
---
|
||||||
|
|
||||||
[Mem0](https://mem0.ai) (pronounced "mem-zero") enhances AI assistants and agents with an intelligent memory layer, enabling personalized AI interactions. Mem0 remembers user preferences, adapts to individual needs, and continuously improves over time, making it ideal for customer support chatbots, AI assistants, and autonomous systems.
|
[Mem0](https://mem0.dev/wd) (pronounced "mem-zero") enhances AI assistants and agents with an intelligent memory layer, enabling personalized AI interactions. Mem0 remembers user preferences and traits and continuously updates over time, making it ideal for applications like customer support chatbots and AI assistants.
|
||||||
|
|
||||||
Mem0 offers two powerful ways to leverage our technology: [our managed Platform](#mem0-platform-managed-solution) and [our open source solution](#mem0-open-source).
|
Mem0 offers two powerful ways to leverage our technology: our [managed platform](/platform/overview) and our [open source solution](/open-source/quickstart).
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
<CardGroup cols={2}>
|
<CardGroup cols={3}>
|
||||||
<Card title="Mem0 Platform" icon="chart-simple" href="#mem0-platform-managed-solution">
|
<Card title="Quickstart" icon="rocket" href="/quickstart">
|
||||||
Better, faster, fully managed, and hassle free solution.
|
Integrate Mem0 in a few lines of code
|
||||||
</Card>
|
</Card>
|
||||||
<Card title="Mem0 Open Source" icon="code-branch" href="#mem0-open-source">
|
<Card title="Playground" icon="play" href="playground">
|
||||||
Self hosted, fully customizable, and open source.
|
Mem0 in action
|
||||||
|
</Card>
|
||||||
|
<Card title="Examples" icon="lightbulb" href="/open-source/quickstart">
|
||||||
|
See what you can build with Mem0
|
||||||
</Card>
|
</Card>
|
||||||
</CardGroup>
|
</CardGroup>
|
||||||
|
|
||||||
|
|
||||||
## Mem0 Platform (Managed Solution)
|
|
||||||
|
|
||||||
Our fully managed platform provides a hassle-free way to integrate Mem0's capabilities into your AI agents and assistants. Sign up for Mem0 platform [here](https://app.mem0.ai).
|
|
||||||
|
|
||||||
Follow the steps below to get started with Mem0 Platform:
|
|
||||||
|
|
||||||
1. [Install Mem0](#1-install-mem0)
|
|
||||||
2. [Add Memories](#2-add-memories)
|
|
||||||
3. [Retrieve Memories](#3-retrieve-memories)
|
|
||||||
|
|
||||||
### 1. Install Mem0
|
|
||||||
|
|
||||||
<AccordionGroup>
|
|
||||||
<Accordion title="Install package">
|
|
||||||
<CodeGroup>
|
|
||||||
```bash pip
|
|
||||||
pip install mem0ai
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash npm
|
|
||||||
npm install mem0ai
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
<Accordion title="Get API Key">
|
|
||||||
|
|
||||||
1. Sign in to [Mem0 Platform](https://app.mem0.ai/dashboard/api-keys)
|
|
||||||
2. Copy your API Key from the dashboard
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
</Accordion>
|
|
||||||
</AccordionGroup>
|
|
||||||
|
|
||||||
### 2. Add Memories
|
|
||||||
|
|
||||||
<AccordionGroup>
|
|
||||||
<Accordion title="Instantiate client">
|
|
||||||
<CodeGroup>
|
|
||||||
```python Python
|
|
||||||
from mem0 import MemoryClient
|
|
||||||
client = MemoryClient(api_key="your-api-key")
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript JavaScript
|
|
||||||
const MemoryClient = require('mem0ai');
|
|
||||||
const client = new MemoryClient('your-api-key');
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
<Accordion title="Add memories">
|
|
||||||
<CodeGroup>
|
|
||||||
|
|
||||||
```python Python
|
|
||||||
messages = [
|
|
||||||
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
|
|
||||||
{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
|
|
||||||
]
|
|
||||||
client.add(messages, user_id="alex")
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript JavaScript
|
|
||||||
const messages = [
|
|
||||||
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
|
|
||||||
{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
|
|
||||||
];
|
|
||||||
client.add(messages, { user_id: "alex" })
|
|
||||||
.then(response => console.log(response))
|
|
||||||
.catch(error => console.error(error));
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash cURL
|
|
||||||
curl -X POST "https://api.mem0.ai/v1/memories/" \
|
|
||||||
-H "Authorization: Token your-api-key" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"messages": [
|
|
||||||
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
|
|
||||||
{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
|
|
||||||
],
|
|
||||||
"user_id": "alex"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
{'message': 'ok'}
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
</AccordionGroup>
|
|
||||||
|
|
||||||
### 3. Retrieve Memories
|
|
||||||
|
|
||||||
<AccordionGroup>
|
|
||||||
<Accordion title="Search for relevant memories">
|
|
||||||
<CodeGroup>
|
|
||||||
|
|
||||||
```python Python
|
|
||||||
query = "What do you know about me?"
|
|
||||||
client.search(query, user_id="alex")
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript JavaScript
|
|
||||||
const query = "What do you know about me?";
|
|
||||||
client.search(query, { user_id: "alex" })
|
|
||||||
.then(results => console.log(results))
|
|
||||||
.catch(error => console.error(error));
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash cURL
|
|
||||||
curl -X POST "https://api.mem0.ai/v1/memories/search/" \
|
|
||||||
-H "Authorization: Token your-api-key" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{
|
|
||||||
"query": "What do you know about me?",
|
|
||||||
"user_id": "alex"
|
|
||||||
}'
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",
|
|
||||||
"memory": "Name: Alex. Vegetarian. Allergic to nuts.",
|
|
||||||
"input": [
|
|
||||||
{
|
|
||||||
"role": "user",
|
|
||||||
"content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"role": "assistant",
|
|
||||||
"content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"user_id": "alex",
|
|
||||||
"hash": "9ee7e1455e84d1dab700ed8749aed75a",
|
|
||||||
"metadata": null,
|
|
||||||
"created_at": "2024-07-20T01:30:36.275141-07:00",
|
|
||||||
"updated_at": "2024-07-20T01:30:36.275172-07:00"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
|
|
||||||
</Accordion>
|
|
||||||
<Accordion title="Get all memories of a user">
|
|
||||||
|
|
||||||
<CodeGroup>
|
|
||||||
|
|
||||||
```python Python
|
|
||||||
user_memories = client.get_all(user_id="alex")
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript JavaScript
|
|
||||||
client.getAll({ user_id: "alex" })
|
|
||||||
.then(memories => console.log(memories))
|
|
||||||
.catch(error => console.error(error));
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash cURL
|
|
||||||
curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex" \
|
|
||||||
-H "Authorization: Token your-api-key"
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7",
|
|
||||||
"memory":"是素食主义者,对坚果过敏。",
|
|
||||||
"agent_id":"travel-assistant",
|
|
||||||
"hash":"62bc074f56d1f909f1b4c2b639f56f6a",
|
|
||||||
"metadata":"None",
|
|
||||||
"created_at":"2024-07-25T23:57:00.108347-07:00",
|
|
||||||
"updated_at":"2024-07-25T23:57:00.108367-07:00"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878",
|
|
||||||
"memory":"Will maintain personalized travel preferences for each user. Provide customized recommendations based on dietary restrictions, interests, and past interactions.",
|
|
||||||
"agent_id":"travel-assistant",
|
|
||||||
"hash":"35a305373d639b0bffc6c2a3e2eb4244",
|
|
||||||
"metadata":"None",
|
|
||||||
"created_at":"2024-07-26T00:31:03.543759-07:00",
|
|
||||||
"updated_at":"2024-07-26T00:31:03.543778-07:00"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
</AccordionGroup>
|
|
||||||
|
|
||||||
<Card title="Mem0 Platform" icon="chart-simple" href="/platform/overview">
|
|
||||||
Learn more about Mem0 platform
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
## Mem0 Open Source
|
|
||||||
|
|
||||||
Our open-source version is available for those who prefer full control and customization. You can self-host Mem0 on your infrastructure and integrate it with your AI agents and assistants. Checkout the [GitHub repository](https://github.com/mem0ai/mem0)
|
|
||||||
|
|
||||||
Follow the steps below to get started with Mem0 Open Source:
|
|
||||||
|
|
||||||
1. [Install Mem0 Open Source](#1-install-mem0-open-source)
|
|
||||||
2. [Add Memories](#2-add-memories-open-source)
|
|
||||||
3. [Retrieve Memories](#3-retrieve-memories-open-source)
|
|
||||||
|
|
||||||
### 1. Install Mem0 Open Source
|
|
||||||
|
|
||||||
<AccordionGroup>
|
|
||||||
<Accordion title="Install package">
|
|
||||||
```bash
|
|
||||||
pip install mem0ai
|
|
||||||
```
|
|
||||||
</Accordion>
|
|
||||||
</AccordionGroup>
|
|
||||||
|
|
||||||
### 2. Add Memories <a name="2-add-memories-open-source"></a>
|
|
||||||
|
|
||||||
<AccordionGroup>
|
|
||||||
<Accordion title="Instantiate client">
|
|
||||||
```python Python
|
|
||||||
from mem0 import Memory
|
|
||||||
m = Memory()
|
|
||||||
```
|
|
||||||
</Accordion>
|
|
||||||
<Accordion title="Add memories">
|
|
||||||
<CodeGroup>
|
|
||||||
```python Code
|
|
||||||
# For a user
|
|
||||||
result = m.add("Likes to play cricket on weekends", user_id="alice", metadata={"category": "hobbies"})
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
{'message': 'ok'}
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
</AccordionGroup>
|
|
||||||
|
|
||||||
### 3. Retrieve Memories <a name="3-retrieve-memories-open-source"></a>
|
|
||||||
|
|
||||||
<AccordionGroup>
|
|
||||||
<Accordion title="Search for relevant memories">
|
|
||||||
<CodeGroup>
|
|
||||||
```python Code
|
|
||||||
related_memories = m.search(query="What are Alice's hobbies?", user_id="alice")
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id":"ea925981-272f-40dd-b576-be64e4871429",
|
|
||||||
"memory":"Likes to play cricket and plays cricket on weekends.",
|
|
||||||
"hash":"c8809002-25c1-4c97-a3a2-227ce9c20c53",
|
|
||||||
"metadata":{
|
|
||||||
"category":"hobbies"
|
|
||||||
},
|
|
||||||
"score":0.32116443111457704,
|
|
||||||
"created_at":"2024-07-26T10:29:36.630547-07:00",
|
|
||||||
"updated_at":"None",
|
|
||||||
"user_id":"alice"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
<Accordion title="Get all memories of a user">
|
|
||||||
<CodeGroup>
|
|
||||||
```python Code
|
|
||||||
# Get all memories
|
|
||||||
all_memories = m.get_all()
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id":"13efe83b-a8df-4ec0-814e-428d6e8451eb",
|
|
||||||
"memory":"Likes to play cricket on weekends",
|
|
||||||
"hash":"87bcddeb-fe45-4353-bc22-15a841c50308",
|
|
||||||
"metadata":"None",
|
|
||||||
"created_at":"2024-07-26T08:44:41.039788-07:00",
|
|
||||||
"updated_at":"None",
|
|
||||||
"user_id":"alice"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
</Accordion>
|
|
||||||
</AccordionGroup>
|
|
||||||
|
|
||||||
<Card title="Mem0 Open source" icon="code-branch" href="/open-source/overview">
|
|
||||||
Learn more about Mem0 open source
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
## Key Features
|
## Key Features
|
||||||
|
|
||||||
- OpenAI-compatible API: Easily switch between OpenAI and Mem0
|
- OpenAI-compatible API: Easily switch between OpenAI and Mem0
|
||||||
- Advanced memory management: Efficient handling of long-term context
|
- Advanced memory management: Save costs by efficiently handling long-term context
|
||||||
- Flexible deployment: Choose between managed platform or self-hosted solution
|
- Flexible deployment: Choose between managed platform or self-hosted solution
|
||||||
|
<Card title="All Mem0 Features" icon="list" href="/features" horizontal="false">
|
||||||
|
</Card>
|
||||||
|
|
||||||
## Need help?
|
## Need help?
|
||||||
|
|
||||||
|
|||||||
@@ -5,36 +5,28 @@ description: 'Empower your AI applications with long-term memory and personaliza
|
|||||||
|
|
||||||
## Welcome to Mem0 Platform
|
## Welcome to Mem0 Platform
|
||||||
|
|
||||||
Mem0 Platform is a managed service that revolutionizes the way AI applications handle memory. By providing a smart, self-improving memory layer for Large Language Models (LLMs), we enable developers to create personalized AI experiences that evolve with each user interaction.
|
The Mem0 Platform is a managed service and the easiest way to add our powerful memory layer to your applications.
|
||||||
|
|
||||||
## Why Choose Mem0 Platform?
|
## Why Choose Mem0 Platform?
|
||||||
|
|
||||||
1. **Enhanced User Experience**: Deliver tailored interactions that make your AI applications truly stand out.
|
Mem0 Platform offers a powerful, user-centric solution for AI memory management with a few key features:
|
||||||
2. **Simplified Development**: Our API-first approach streamlines integration, allowing you to focus on building great features.
|
|
||||||
3. **Scalable Solution**: Designed to grow with your application, from prototypes to production-ready systems.
|
|
||||||
|
|
||||||
## Key Features
|
1. **Simplified Development**: Integrate comprehensive memory capabilities with just 4 lines of code. Our API-first approach allows you to focus on building great features while we handle the complexities of memory management.
|
||||||
|
|
||||||
- **Comprehensive Memory Management**: Easily manage long-term, short-term, semantic, and episodic memories for individual users, agents, and sessions through our robust APIs.
|
2. **Scalable Solution**: Whether you're working on a prototype or a production-ready system, Mem0 is designed to grow with your application. Our platform effortlessly scales to meet your evolving needs.
|
||||||
- **Self-Improving Memory**: Our adaptive system continuously learns from user interactions, refining its understanding over time.
|
|
||||||
- **Cross-Platform Consistency**: Ensure a unified user experience across various AI platforms and applications.
|
|
||||||
- **Centralized Memory Control**: Store, update, and delete memories effortlessly, taking away the hassle of memory management.
|
|
||||||
|
|
||||||
## Common Use Cases
|
3. **Enhanced Performance**: Experience lightning-fast response times with sub-50ms latency, ensuring smooth and responsive user interactions in your AI applications.
|
||||||
|
|
||||||
|
4. **Insightful Dashboard**: Gain valuable insights and maintain full control over your AI's memory through our intuitive dashboard. Easily manage memories and access key user insights.
|
||||||
|
|
||||||
- Personalized Learning Assistants
|
|
||||||
- Customer Support AI Agents
|
|
||||||
- Healthcare Assistants
|
|
||||||
- Virtual Companions
|
|
||||||
- Productivity Tools
|
|
||||||
- Gaming AI
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
Check out our [Quickstart Guide](/platform/quickstart) to start using Mem0 quickly.
|
Check out our [Platform Guide](/platform/guide) to start using Mem0 platform quickly.
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
- Join our [discord](https://mem0.ai/discord) or [slack](https://mem0.ai/slack) with other developers and get support.
|
- Sign up to the [Mem0 Platform](https://mem0.dev/pd)
|
||||||
|
- Join our [Discord](https://mem0.dev/Did) or [Slack](https://mem0.ai/slack) with other developers and get support.
|
||||||
|
|
||||||
We're excited to see what you'll build with Mem0 Platform. Let's create smarter, more personalized AI experiences together!
|
We're excited to see what you'll build with Mem0 Platform. Let's create smarter, more personalized AI experiences together!
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: Quickstart
|
title: Guide
|
||||||
description: 'Get started with Mem0 Platform in minutes'
|
description: 'Get started with Mem0 Platform in minutes'
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ npm install mem0ai
|
|||||||
|
|
||||||
## 2. API Key Setup
|
## 2. API Key Setup
|
||||||
|
|
||||||
1. Sign in to [Mem0 Platform](https://app.mem0.ai/dashboard/api-keys)
|
1. Sign in to [Mem0 Platform](https://mem0.dev/pd-api)
|
||||||
2. Copy your API Key from the dashboard
|
2. Copy your API Key from the dashboard
|
||||||
|
|
||||||

|

|
||||||
@@ -44,10 +44,10 @@ Mem0 provides a simple and customizable interface for performing CRUD operations
|
|||||||
|
|
||||||
### 4.1 Create Memories
|
### 4.1 Create Memories
|
||||||
|
|
||||||
You can create long-term and short-term memories for your users, AI Agents, etc. Here are some examples:
|
|
||||||
|
|
||||||
#### Long-term memory for a user
|
#### Long-term memory for a user
|
||||||
|
|
||||||
|
These memory instances persist across multiple sessions. Ideal for maintaining memory over long time spans.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
```python Python
|
```python Python
|
||||||
@@ -88,6 +88,8 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
|
|||||||
|
|
||||||
#### Short-term memory for a user session
|
#### Short-term memory for a user session
|
||||||
|
|
||||||
|
These memory instances persist only for the duration of a user session. Ideal for non-repetitive interactions and managing context windows efficiently.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
```python Python
|
```python Python
|
||||||
@@ -134,23 +136,24 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
|
|||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|
||||||
#### Long-term memory for agents
|
#### Long-term memory for agents
|
||||||
|
Add a memory layer for the assistants and agents so that their responses remain consistent across sessions.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
```python Python
|
```python Python
|
||||||
messages = [
|
messages = [
|
||||||
{"role": "system", "content": "You are a personalized travel assistant. Remember user preferences and provide tailored recommendations."},
|
{"role": "system", "content": "You are an AI tutor with a personality. Give yourself a name for the user."},
|
||||||
{"role": "assistant", "content": "Understood. I'll maintain personalized travel preferences for each user and provide customized recommendations based on their dietary restrictions, interests, and past interactions."}
|
{"role": "assistant", "content": "Understood. I'm an AI tutor with a personality. My name is Alice."}
|
||||||
]
|
]
|
||||||
client.add(messages, agent_id="travel-assistant")
|
client.add(messages, agent_id="ai-tutor")
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript JavaScript
|
```javascript JavaScript
|
||||||
const messages = [
|
const messages = [
|
||||||
{"role": "system", "content": "You are a personalized travel assistant. Remember user preferences and provide tailored recommendations."},
|
{"role": "system", "content": "You are an AI tutor with a personality. Give yourself a name for the user."},
|
||||||
{"role": "assistant", "content": "Understood. I'll maintain personalized travel preferences for each user and provide customized recommendations based on their dietary restrictions, interests, and past interactions."}
|
{"role": "assistant", "content": "Understood. I'm an AI tutor with a personality. My name is Alice."}
|
||||||
];
|
];
|
||||||
client.add(messages, { agent_id: "travel-assistant" })
|
client.add(messages, { agent_id: "ai-tutor" })
|
||||||
.then(response => console.log(response))
|
.then(response => console.log(response))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
```
|
```
|
||||||
@@ -161,10 +164,10 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"messages": [
|
"messages": [
|
||||||
{"role": "system", "content": "You are a personalized travel assistant. Remember user preferences and provide tailored recommendations."},
|
{"role": "system", "content": "You are an AI tutor with a personality. Give yourself a name for the user."},
|
||||||
{"role": "assistant", "content": "Understood. I'll maintain personalized travel preferences for each user and provide customized recommendations based on their dietary restrictions, interests, and past interactions."}
|
{"role": "assistant", "content": "Understood. I'm an AI tutor with a personality. My name is Alice."}
|
||||||
],
|
],
|
||||||
"agent_id": "travel-assistant"
|
"agent_id": "ai-tutor"
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -173,23 +176,27 @@ curl -X POST "https://api.mem0.ai/v1/memories/" \
|
|||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|
||||||
You can monitor memory operations on the platform:
|
#### Monitor Memories
|
||||||
|
|
||||||
|
You can monitor memory operations on the platform dashboard:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 4.2 Search Relevant Memories
|
### 4.2 Search Memories
|
||||||
|
|
||||||
You can also get related memories for a given natural language question using our search method.
|
#### General Memory Search
|
||||||
|
|
||||||
|
Pass user messages, interactions, and queries into our search method to retrieve relevant memories.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
```python Python
|
```python Python
|
||||||
query = "What do you know about me?"
|
query = "What should I cook for dinner today?"
|
||||||
client.search(query, user_id="alex")
|
client.search(query, user_id="alex")
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript JavaScript
|
```javascript JavaScript
|
||||||
const query = "What do you know about me?";
|
const query = "What should I cook for dinner today?";
|
||||||
client.search(query, { user_id: "alex" })
|
client.search(query, { user_id: "alex" })
|
||||||
.then(results => console.log(results))
|
.then(results => console.log(results))
|
||||||
.catch(error => console.error(error));
|
.catch(error => console.error(error));
|
||||||
@@ -200,7 +207,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \
|
|||||||
-H "Authorization: Token your-api-key" \
|
-H "Authorization: Token your-api-key" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"query": "What do you know about me?",
|
"query": "What should I cook for dinner today?",
|
||||||
"user_id": "alex"
|
"user_id": "alex"
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
@@ -209,7 +216,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",
|
"id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",
|
||||||
"memory": "Name: Alex. Vegetarian. Allergic to nuts.",
|
"memory": "Vegetarian. Allergic to nuts.",
|
||||||
"input": [
|
"input": [
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
@@ -232,7 +239,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/" \
|
|||||||
|
|
||||||
#### Search using custom filters
|
#### Search using custom filters
|
||||||
|
|
||||||
You can also search for memories using custom filters along with user_id, agent_id, app_id, etc.
|
Our advanced search allows you to set custom search filters. You can filter by user_id, agent_id, app_id, date, and more.
|
||||||
|
|
||||||
Here you need to define `version` as `v2` in the search method.
|
Here you need to define `version` as `v2` in the search method.
|
||||||
|
|
||||||
@@ -405,7 +412,7 @@ curl -X POST "https://api.mem0.ai/v1/memories/search/?version=v2" \
|
|||||||
|
|
||||||
### 4.3 Get All Users
|
### 4.3 Get All Users
|
||||||
|
|
||||||
Get all users, agents, and sessions for which memories exist.
|
Get all users, agents, and sessions which have memories associated with them.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
@@ -430,7 +437,7 @@ curl -X GET "https://api.mem0.ai/v1/entities/" \
|
|||||||
{
|
{
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"name": "user123",
|
"name": "user123",
|
||||||
"created_at": "2024-07-17T16:47:23.899900-07:00",
|
"created_2024-07-17T16:47:23.899900-07:00",
|
||||||
"updated_at": "2024-07-17T16:47:23.899918-07:00",
|
"updated_at": "2024-07-17T16:47:23.899918-07:00",
|
||||||
"total_memories": 5,
|
"total_memories": 5,
|
||||||
"owner": "alex",
|
"owner": "alex",
|
||||||
@@ -459,49 +466,7 @@ curl -X GET "https://api.mem0.ai/v1/entities/" \
|
|||||||
|
|
||||||
Fetch all memories for a user, agent, or session using the getAll() method.
|
Fetch all memories for a user, agent, or session using the getAll() method.
|
||||||
|
|
||||||
#### Get all memories of an AI Agent
|
#### Get all memories of a user
|
||||||
|
|
||||||
<CodeGroup>
|
|
||||||
```python Python
|
|
||||||
client.get_all(agent_id="travel-assistant")
|
|
||||||
```
|
|
||||||
|
|
||||||
```javascript JavaScript
|
|
||||||
client.getAll({ agent_id: "travel-assistant" })
|
|
||||||
.then(memories => console.log(memories))
|
|
||||||
.catch(error => console.error(error));
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash cURL
|
|
||||||
curl -X GET "https://api.mem0.ai/v1/memories/?agent_id=travel-assistant" \
|
|
||||||
-H "Authorization: Token your-api-key"
|
|
||||||
```
|
|
||||||
|
|
||||||
```json Output
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7",
|
|
||||||
"memory":"是素食主义者,对坚果过敏。",
|
|
||||||
"agent_id":"travel-assistant",
|
|
||||||
"hash":"62bc074f56d1f909f1b4c2b639f56f6a",
|
|
||||||
"metadata":"None",
|
|
||||||
"created_at":"2024-07-25T23:57:00.108347-07:00",
|
|
||||||
"updated_at":"2024-07-25T23:57:00.108367-07:00"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878",
|
|
||||||
"memory":"Will maintain personalized travel preferences for each user. Provide customized recommendations based on dietary restrictions, interests, and past interactions.",
|
|
||||||
"agent_id":"travel-assistant",
|
|
||||||
"hash":"35a305373d639b0bffc6c2a3e2eb4244",
|
|
||||||
"metadata":"None",
|
|
||||||
"created_at":"2024-07-26T00:31:03.543759-07:00",
|
|
||||||
"updated_at":"2024-07-26T00:31:03.543778-07:00"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
|
||||||
</CodeGroup>
|
|
||||||
|
|
||||||
#### Get all memories of user
|
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
@@ -544,7 +509,50 @@ curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex" \
|
|||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|
||||||
#### Get short-term memories for a session
|
|
||||||
|
#### Get all memories of an AI Agent
|
||||||
|
|
||||||
|
<CodeGroup>
|
||||||
|
```python Python
|
||||||
|
client.get_all(agent_id="ai-tutor")
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
client.getAll({ agent_id: "ai-tutor" })
|
||||||
|
.then(memories => console.log(memories))
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash cURL
|
||||||
|
curl -X GET "https://api.mem0.ai/v1/memories/?agent_id=travel-assistant" \
|
||||||
|
-H "Authorization: Token your-api-key"
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7",
|
||||||
|
"memory":"是素食主义者,对坚果过敏。",
|
||||||
|
"agent_id":"ai-tutor",
|
||||||
|
"hash":"62bc074f56d1f909f1b4c2b639f56f6a",
|
||||||
|
"metadata":"None",
|
||||||
|
"created_at":"2024-07-25T23:57:00.108347-07:00",
|
||||||
|
"updated_at":"2024-07-25T23:57:00.108367-07:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878",
|
||||||
|
"memory":"My name is Alice.",
|
||||||
|
"agent_id":"ai-tutor",
|
||||||
|
"hash":"35a305373d639b0bffc6c2a3e2eb4244",
|
||||||
|
"metadata":"None",
|
||||||
|
"created_at":"2024-07-26T00:31:03.543759-07:00",
|
||||||
|
"updated_at":"2024-07-26T00:31:03.543778-07:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
|
||||||
|
#### Get the short-term memories for a session
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
@@ -630,7 +638,7 @@ curl -X GET "https://api.mem0.ai/v1/memories/582bbe6d-506b-48c6-a4c6-5df3b1e6342
|
|||||||
|
|
||||||
### 4.5 Memory History
|
### 4.5 Memory History
|
||||||
|
|
||||||
Get history of how a memory has changed over time
|
Get history of how a memory has changed over time.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
@@ -763,7 +771,7 @@ curl -X PUT "https://api.mem0.ai/v1/memories/memory-id-here" \
|
|||||||
|
|
||||||
### 4.7 Delete Memory
|
### 4.7 Delete Memory
|
||||||
|
|
||||||
Delete specific memory:
|
Delete specific memory.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
@@ -787,7 +795,7 @@ curl -X DELETE "https://api.mem0.ai/v1/memories/memory-id-here" \
|
|||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|
||||||
Delete all memories of a user:
|
Delete all memories of a user.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
@@ -811,7 +819,7 @@ curl -X DELETE "https://api.mem0.ai/v1/memories/?user_id=alex" \
|
|||||||
```
|
```
|
||||||
</CodeGroup>
|
</CodeGroup>
|
||||||
|
|
||||||
Delete all users:
|
Delete all users.
|
||||||
|
|
||||||
<CodeGroup>
|
<CodeGroup>
|
||||||
|
|
||||||
|
|||||||
25
docs/playground.mdx
Normal file
25
docs/playground.mdx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
title: Interactive Playground
|
||||||
|
---
|
||||||
|
Watch Mem0 in action with our Playground tool.
|
||||||
|
|
||||||
|
<Steps>
|
||||||
|
<Step title="Create Mem0 Account">
|
||||||
|
You'll need to create a free Mem0 account to use the playground – this helps ensure responses are more tailored to you by associating interactions with an individual profile.
|
||||||
|
<Card title="Sign up to Mem0" icon="right-to-bracket" href="https://mem0.dev/pd" horizontal="true">
|
||||||
|
</Card>
|
||||||
|
</Step>
|
||||||
|
<Step title="Go to Playground">
|
||||||
|
<Card title="Mem0 Playground" icon="play" href="https://mem0.dev/pd-pg" horizontal="true">
|
||||||
|
</Card>
|
||||||
|
</Step>
|
||||||
|
<Step title="Start adding memories">
|
||||||
|
Chat with the assistant to start adding memories.
|
||||||
|

|
||||||
|
</Step>
|
||||||
|
<Step title="Experience the power of Mem0">
|
||||||
|
Memories are stored in context for all future conversations, creating truly personal AI.
|
||||||
|

|
||||||
|
</Step>
|
||||||
|
</Steps>
|
||||||
|
|
||||||
306
docs/quickstart.mdx
Normal file
306
docs/quickstart.mdx
Normal file
@@ -0,0 +1,306 @@
|
|||||||
|
---
|
||||||
|
title: Quickstart
|
||||||
|
---
|
||||||
|
Mem0 offers two powerful ways to leverage our technology: [our managed platform](#mem0-platform-managed-solution) and [our open source solution](#mem0-open-source).
|
||||||
|
|
||||||
|
<CardGroup cols={2}>
|
||||||
|
<Card title="Mem0 Platform" icon="chart-simple" href="#mem0-platform-managed-solution">
|
||||||
|
Better, faster, fully managed, and hassle free solution.
|
||||||
|
</Card>
|
||||||
|
<Card title="Mem0 Open Source" icon="code-branch" href="#mem0-open-source">
|
||||||
|
Self hosted, fully customizable, and open source.
|
||||||
|
</Card>
|
||||||
|
</CardGroup>
|
||||||
|
|
||||||
|
|
||||||
|
## Mem0 Platform (Managed Solution)
|
||||||
|
|
||||||
|
Our fully managed platform provides a hassle-free way to integrate Mem0's capabilities into your AI agents and assistants. Sign up for Mem0 platform [here](https://mem0.dev/pd).
|
||||||
|
|
||||||
|
Follow the steps below to get started with Mem0 Platform:
|
||||||
|
|
||||||
|
1. [Install Mem0](#1-install-mem0)
|
||||||
|
2. [Add Memories](#2-add-memories)
|
||||||
|
3. [Retrieve Memories](#3-retrieve-memories)
|
||||||
|
|
||||||
|
### 1. Install Mem0
|
||||||
|
|
||||||
|
<AccordionGroup>
|
||||||
|
<Accordion title="Install package">
|
||||||
|
<CodeGroup>
|
||||||
|
```bash pip
|
||||||
|
pip install mem0ai
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash npm
|
||||||
|
npm install mem0ai
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
<Accordion title="Get API Key">
|
||||||
|
|
||||||
|
1. Sign in to [Mem0 Platform](https://mem0.dev/pd-api)
|
||||||
|
2. Copy your API Key from the dashboard
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
</Accordion>
|
||||||
|
</AccordionGroup>
|
||||||
|
|
||||||
|
### 2. Add Memories
|
||||||
|
|
||||||
|
<AccordionGroup>
|
||||||
|
<Accordion title="Instantiate client">
|
||||||
|
<CodeGroup>
|
||||||
|
```python Python
|
||||||
|
from mem0 import MemoryClient
|
||||||
|
client = MemoryClient(api_key="your-api-key")
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
const MemoryClient = require('mem0ai');
|
||||||
|
const client = new MemoryClient('your-api-key');
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
<Accordion title="Add memories">
|
||||||
|
<CodeGroup>
|
||||||
|
|
||||||
|
```python Python
|
||||||
|
messages = [
|
||||||
|
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
|
||||||
|
{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
|
||||||
|
]
|
||||||
|
client.add(messages, user_id="alex")
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
const messages = [
|
||||||
|
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
|
||||||
|
{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
|
||||||
|
];
|
||||||
|
client.add(messages, { user_id: "alex" })
|
||||||
|
.then(response => console.log(response))
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash cURL
|
||||||
|
curl -X POST "https://api.mem0.ai/v1/memories/" \
|
||||||
|
-H "Authorization: Token your-api-key" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"messages": [
|
||||||
|
{"role": "user", "content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."},
|
||||||
|
{"role": "assistant", "content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."}
|
||||||
|
],
|
||||||
|
"user_id": "alex"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
{'message': 'ok'}
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
</AccordionGroup>
|
||||||
|
|
||||||
|
### 3. Retrieve Memories
|
||||||
|
|
||||||
|
<AccordionGroup>
|
||||||
|
<Accordion title="Search for relevant memories">
|
||||||
|
<CodeGroup>
|
||||||
|
|
||||||
|
```python Python
|
||||||
|
query = "What can I cook for dinner tonight?"
|
||||||
|
client.search(query, user_id="alex")
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
const query = "What can I cook for dinner tonight?";
|
||||||
|
client.search(query, { user_id: "alex" })
|
||||||
|
.then(results => console.log(results))
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash cURL
|
||||||
|
curl -X POST "https://api.mem0.ai/v1/memories/search/" \
|
||||||
|
-H "Authorization: Token your-api-key" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"query": "What can I cook for dinner tonight?",
|
||||||
|
"user_id": "alex"
|
||||||
|
}'
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "7f165f7e-b411-4afe-b7e5-35789b72c4a5",
|
||||||
|
"memory": "Name: Alex. Vegetarian. Allergic to nuts.",
|
||||||
|
"input": [
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": "Hi, I'm Alex. I'm a vegetarian and I'm allergic to nuts."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "assistant",
|
||||||
|
"content": "Hello Alex! I've noted that you're a vegetarian and have a nut allergy. I'll keep this in mind for any food-related recommendations or discussions."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"user_id": "alex",
|
||||||
|
"hash": "9ee7e1455e84d1dab700ed8749aed75a",
|
||||||
|
"metadata": null,
|
||||||
|
"created_at": "2024-07-20T01:30:36.275141-07:00",
|
||||||
|
"updated_at": "2024-07-20T01:30:36.275172-07:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
|
||||||
|
</Accordion>
|
||||||
|
<Accordion title="Get all memories of a user">
|
||||||
|
|
||||||
|
<CodeGroup>
|
||||||
|
|
||||||
|
```python Python
|
||||||
|
user_memories = client.get_all(user_id="alex")
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
client.getAll({ user_id: "alex" })
|
||||||
|
.then(memories => console.log(memories))
|
||||||
|
.catch(error => console.error(error));
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash cURL
|
||||||
|
curl -X GET "https://api.mem0.ai/v1/memories/?user_id=alex" \
|
||||||
|
-H "Authorization: Token your-api-key"
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id":"f38b689d-6b24-45b7-bced-17fbb4d8bac7",
|
||||||
|
"memory":"是素食主义者,对坚果过敏。",
|
||||||
|
"agent_id":"travel-assistant",
|
||||||
|
"hash":"62bc074f56d1f909f1b4c2b639f56f6a",
|
||||||
|
"metadata":"None",
|
||||||
|
"created_at":"2024-07-25T23:57:00.108347-07:00",
|
||||||
|
"updated_at":"2024-07-25T23:57:00.108367-07:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":"0a14d8f0-e364-4f5c-b305-10da1f0d0878",
|
||||||
|
"memory":"Will maintain personalized travel preferences for each user. Provide customized recommendations based on dietary restrictions, interests, and past interactions.",
|
||||||
|
"agent_id":"travel-assistant",
|
||||||
|
"hash":"35a305373d639b0bffc6c2a3e2eb4244",
|
||||||
|
"metadata":"None",
|
||||||
|
"created_at":"2024-07-26T00:31:03.543759-07:00",
|
||||||
|
"updated_at":"2024-07-26T00:31:03.543778-07:00"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
</AccordionGroup>
|
||||||
|
|
||||||
|
<Card title="Mem0 Platform" icon="chart-simple" href="/platform/overview">
|
||||||
|
Learn more about Mem0 platform
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
## Mem0 Open Source
|
||||||
|
|
||||||
|
Our open-source version is available for those who prefer full control and customization. You can self-host Mem0 on your infrastructure and integrate it with your AI agents and assistants. Checkout our [GitHub repository](https://mem0.dev/gd)
|
||||||
|
|
||||||
|
Follow the steps below to get started with Mem0 Open Source:
|
||||||
|
|
||||||
|
1. [Install Mem0 Open Source](#1-install-mem0-open-source)
|
||||||
|
2. [Add Memories](#2-add-memories-open-source)
|
||||||
|
3. [Retrieve Memories](#3-retrieve-memories-open-source)
|
||||||
|
|
||||||
|
### 1. Install Mem0 Open Source
|
||||||
|
|
||||||
|
<AccordionGroup>
|
||||||
|
<Accordion title="Install package">
|
||||||
|
```bash
|
||||||
|
pip install mem0ai
|
||||||
|
```
|
||||||
|
</Accordion>
|
||||||
|
</AccordionGroup>
|
||||||
|
|
||||||
|
### 2. Add Memories <a name="2-add-memories-open-source"></a>
|
||||||
|
|
||||||
|
<AccordionGroup>
|
||||||
|
<Accordion title="Instantiate client">
|
||||||
|
```python Python
|
||||||
|
from mem0 import Memory
|
||||||
|
m = Memory()
|
||||||
|
```
|
||||||
|
</Accordion>
|
||||||
|
<Accordion title="Add memories">
|
||||||
|
<CodeGroup>
|
||||||
|
```python Code
|
||||||
|
# For a user
|
||||||
|
result = m.add("I like to take long walks on weekends.", user_id="alice", metadata={"category": "hobbies"})
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
{'message': 'ok'}
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
</AccordionGroup>
|
||||||
|
|
||||||
|
### 3. Retrieve Memories <a name="3-retrieve-memories-open-source"></a>
|
||||||
|
|
||||||
|
<AccordionGroup>
|
||||||
|
<Accordion title="Search for relevant memories">
|
||||||
|
<CodeGroup>
|
||||||
|
```python Code
|
||||||
|
related_memories = m.search(query="Help me plan my weekend.", user_id="alice")
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id":"ea925981-272f-40dd-b576-be64e4871429",
|
||||||
|
"memory":"Likes to take long walks on weekends.",
|
||||||
|
"hash":"c8809002-25c1-4c97-a3a2-227ce9c20c53",
|
||||||
|
"metadata":{
|
||||||
|
"category":"hobbies"
|
||||||
|
},
|
||||||
|
"score":0.32116443111457704,
|
||||||
|
"created_at":"2024-07-26T10:29:36.630547-07:00",
|
||||||
|
"updated_at":"None",
|
||||||
|
"user_id":"alice"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
<Accordion title="Get all memories of a user">
|
||||||
|
<CodeGroup>
|
||||||
|
```python Code
|
||||||
|
# Get all memories
|
||||||
|
all_memories = m.get_all(user_id="alice")
|
||||||
|
```
|
||||||
|
|
||||||
|
```json Output
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id":"13efe83b-a8df-4ec0-814e-428d6e8451eb",
|
||||||
|
"memory":"Likes to take long walks on weekends",
|
||||||
|
"hash":"87bcddeb-fe45-4353-bc22-15a841c50308",
|
||||||
|
"metadata":"None",
|
||||||
|
"created_at":"2024-07-26T08:44:41.039788-07:00",
|
||||||
|
"updated_at":"None",
|
||||||
|
"user_id":"alice"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
</CodeGroup>
|
||||||
|
</Accordion>
|
||||||
|
</AccordionGroup>
|
||||||
|
|
||||||
|
<Card title="Mem0 Open source" icon="code-branch" href="/open-source/overview">
|
||||||
|
Learn more about Mem0 open source
|
||||||
|
</Card>
|
||||||
Reference in New Issue
Block a user