Doc: Feature docs changes (#2756)
This commit is contained in:
105
docs/platform/features/advanced-retrieval.mdx
Normal file
105
docs/platform/features/advanced-retrieval.mdx
Normal file
@@ -0,0 +1,105 @@
|
||||
---
|
||||
title: Advanced Retrieval
|
||||
icon: "magnifying-glass"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
Mem0's **Advanced Retrieval** feature delivers superior search results by leveraging state-of-the-art search algorithms. Beyond the default search functionality, Mem0 offers the following advanced retrieval modes:
|
||||
|
||||
1. **Keyword Search**
|
||||
|
||||
This mode emphasizes keywords within the query, returning memories that contain the most relevant keywords alongside those from the default search. By default, this parameter is set to `false`. Enabling it enhances search recall, though it may slightly impact precision.
|
||||
|
||||
```python
|
||||
client.search(query, keyword_search=True, user_id='alex')
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```python
|
||||
# Search for memories about food preferences with keyword search enabled
|
||||
query = "What are my food preferences?"
|
||||
results = client.search(query, keyword_search=True, user_id='alex')
|
||||
|
||||
# Output might include:
|
||||
# - "Vegetarian. Allergic to nuts." (highly relevant)
|
||||
# - "Prefers spicy food and enjoys Thai cuisine" (relevant)
|
||||
# - "Mentioned disliking sea food during restaurant discussion" (keyword match)
|
||||
|
||||
# Without keyword_search=True, only the most relevant memories would be returned:
|
||||
# - "Vegetarian. Allergic to nuts." (highly relevant)
|
||||
# - "Prefers spicy food and enjoys Thai cuisine" (relevant)
|
||||
# The keyword-based match about "sea food" would be excluded
|
||||
```
|
||||
|
||||
2. **Reranking**
|
||||
|
||||
Normal retrieval gives you memories sorted in order of their relevancy, but the order may not be perfect. Reranking uses a deep neural network to correct this order, ensuring the most relevant memories appear first. If you are concerned about the order of memories, or want that the best results always comes at top then use reranking. This parameter is set to `false` by default. When enabled, it reorders the memories based on a more accurate relevance score.
|
||||
|
||||
```python
|
||||
client.search(query, rerank=True, user_id='alex')
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```python
|
||||
# Search for travel plans with reranking enabled
|
||||
query = "What are my travel plans?"
|
||||
results = client.search(query, rerank=True, user_id='alex')
|
||||
|
||||
# Without reranking, results might be ordered like:
|
||||
# 1. "Traveled to France last year" (less relevant to current plans)
|
||||
# 2. "Planning a trip to Japan next month" (more relevant to current plans)
|
||||
# 3. "Interested in visiting Tokyo restaurants" (relevant to current plans)
|
||||
|
||||
# With reranking enabled, results would be reordered:
|
||||
# 1. "Planning a trip to Japan next month" (most relevant to current plans)
|
||||
# 2. "Interested in visiting Tokyo restaurants" (highly relevant to current plans)
|
||||
# 3. "Traveled to France last year" (less relevant to current plans)
|
||||
```
|
||||
|
||||
3. **Filtering**
|
||||
|
||||
Filtering allows you to narrow down search results by applying specific criterias. This parameter is set to `false` by default. When activated, it significantly enhances search precision by removing irrelevant memories, though it may slightly reduce recall. Filtering is particularly useful when you need highly specific information.
|
||||
|
||||
```python
|
||||
client.search(query, filter_memories=True, user_id='alex')
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```python
|
||||
# Search for dietary restrictions with filtering enabled
|
||||
query = "What are my dietary restrictions?"
|
||||
results = client.search(query, filter_memories=True, user_id='alex')
|
||||
|
||||
# Without filtering, results might include:
|
||||
# - "Vegetarian. Allergic to nuts." (directly relevant)
|
||||
# - "I enjoy cooking Italian food on weekends" (somewhat related to food)
|
||||
# - "Mentioned disliking seafood during restaurant discussion" (food-related)
|
||||
# - "Prefers to eat dinner at 7pm" (tangentially food-related)
|
||||
|
||||
# With filtering enabled, results would be focused:
|
||||
# - "Vegetarian. Allergic to nuts." (directly relevant)
|
||||
# - "Mentioned disliking seafood during restaurant discussion" (relevant restriction)
|
||||
#
|
||||
# The filtering process removes memories that are about food preferences
|
||||
# but not specifically about dietary restrictions
|
||||
```
|
||||
|
||||
<Note> You can enable or disable these search modes by passing the respective parameters to the `search` method. There is no required sequence for these modes, and any combination can be used based on your needs. </Note>
|
||||
|
||||
|
||||
### Latency Numbers
|
||||
|
||||
Here are the typical latency ranges for each search mode:
|
||||
|
||||
| **Mode** | **Latency** |
|
||||
|---------------------|------------------|
|
||||
| **Keyword Search** | **<10ms** |
|
||||
| **Reranking** | **150-200ms** |
|
||||
| **Filtering** | **200-300ms** |
|
||||
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
179
docs/platform/features/async-client.mdx
Normal file
179
docs/platform/features/async-client.mdx
Normal file
@@ -0,0 +1,179 @@
|
||||
---
|
||||
title: Async Client
|
||||
description: 'Asynchronous client for Mem0'
|
||||
icon: "bolt"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
The `AsyncMemoryClient` is an asynchronous client for interacting with the Mem0 API. It provides similar functionality to the synchronous `MemoryClient` but allows for non-blocking operations, which can be beneficial in applications that require high concurrency.
|
||||
|
||||
## Initialization
|
||||
|
||||
To use the async client, you first need to initialize it:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
import os
|
||||
from mem0 import AsyncMemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = AsyncMemoryClient()
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
const { MemoryClient } = require('mem0ai');
|
||||
const client = new MemoryClient({ apiKey: 'your-api-key'});
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Methods
|
||||
|
||||
The `AsyncMemoryClient` provides the following methods:
|
||||
|
||||
### Add
|
||||
|
||||
Add a new memory asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
messages = [
|
||||
{"role": "user", "content": "Alice loves playing badminton"},
|
||||
{"role": "assistant", "content": "That's great! Alice is a fitness freak"},
|
||||
]
|
||||
await client.add(messages, user_id="alice")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
const messages = [
|
||||
{"role": "user", "content": "Alice loves playing badminton"},
|
||||
{"role": "assistant", "content": "That's great! Alice is a fitness freak"},
|
||||
];
|
||||
await client.add(messages, { user_id: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Search
|
||||
|
||||
Search for memories based on a query asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.search("What is Alice's favorite sport?", user_id="alice")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.search("What is Alice's favorite sport?", { user_id: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Get All
|
||||
|
||||
Retrieve all memories for a user asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.get_all(user_id="alice")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.getAll({ user_id: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Delete
|
||||
|
||||
Delete a specific memory asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.delete(memory_id="memory-id-here")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.delete("memory-id-here");
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Delete All
|
||||
|
||||
Delete all memories for a user asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.delete_all(user_id="alice")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.deleteAll({ user_id: "alice" });
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### History
|
||||
|
||||
Get the history of a specific memory asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.history(memory_id="memory-id-here")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.history("memory-id-here");
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Users
|
||||
|
||||
Get all users, agents, and runs which have memories associated with them asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.users()
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.users();
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Reset
|
||||
|
||||
Reset the client, deleting all users and memories asynchronously.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
await client.reset()
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
await client.reset();
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Conclusion
|
||||
|
||||
The `AsyncMemoryClient` provides a powerful way to interact with the Mem0 API asynchronously, allowing for more efficient and responsive applications. By using this client, you can perform memory operations without blocking your application's execution.
|
||||
|
||||
If you have any questions or need further assistance, please don't hesitate to reach out:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
207
docs/platform/features/contextual-add.mdx
Normal file
207
docs/platform/features/contextual-add.mdx
Normal file
@@ -0,0 +1,207 @@
|
||||
---
|
||||
title: Contextual Add (ADD v2)
|
||||
icon: "square-plus"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
Mem0 now supports an contextual add version (v2). To use it, set `version="v2"` during the add call. The default version is v1, which is deprecated now. We recommend migrating to `v2` for new applications.
|
||||
|
||||
## Key Differences Between v1 and v2
|
||||
|
||||
### Version 1 (Legacy)
|
||||
In v1 (default), users needed to pass either the entire conversation history or past k messages with each new message to generate properly contextualized memories. This approach required:
|
||||
|
||||
- Manually tracking and sending previous messages using a sliding window approach
|
||||
- Increased payload sizes as conversations grew longer, requiring careful window size management
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# First interaction
|
||||
messages1 = [
|
||||
{"role": "user", "content": "Hi, I'm Alex and I live in San Francisco."},
|
||||
{"role": "assistant", "content": "Hello Alex! Nice to meet you. San Francisco is a beautiful city."}
|
||||
]
|
||||
client.add(messages1, user_id="alex")
|
||||
|
||||
# Second interaction - must include previous messages for context
|
||||
messages2 = [
|
||||
{"role": "user", "content": "Hi, I'm Alex and I live in San Francisco."},
|
||||
{"role": "assistant", "content": "Hello Alex! Nice to meet you. San Francisco is a beautiful city."},
|
||||
{"role": "user", "content": "I like to eat sushi, and yesterday I went to Sunnyvale to eat sushi with my friends."},
|
||||
{"role": "assistant", "content": "Sushi is really a tasty choice. What did you do this weekend?"}
|
||||
]
|
||||
client.add(messages2, user_id="alex")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// First interaction
|
||||
const messages1 = [
|
||||
{"role": "user", "content": "Hi, I'm Alex and I live in San Francisco."},
|
||||
{"role": "assistant", "content": "Hello Alex! Nice to meet you. San Francisco is a beautiful city."}
|
||||
];
|
||||
client.add(messages1, { user_id: "alex" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
|
||||
// Second interaction - must include previous messages for context
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "Hi, I'm Alex and I live in San Francisco."},
|
||||
{"role": "assistant", "content": "Hello Alex! Nice to meet you. San Francisco is a beautiful city."},
|
||||
{"role": "user", "content": "I like to eat sushi, and yesterday I went to Sunnyvale to eat sushi with my friends."},
|
||||
{"role": "assistant", "content": "Sushi is really a tasty choice. What did you do this weekend?"}
|
||||
];
|
||||
client.add(messages2, { user_id: "alex" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Version 2 (Recommended)
|
||||
In v2, Mem0 automatically manages conversation context. Users only need to send new messages, and the system will:
|
||||
|
||||
- Automatically retrieve relevant conversation history
|
||||
- Generate properly contextualized memories
|
||||
- Reduce payload sizes and simplify integration
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# First interaction
|
||||
messages1 = [
|
||||
{"role": "user", "content": "Hi, I'm Alex and I live in San Francisco."},
|
||||
{"role": "assistant", "content": "Hello Alex! Nice to meet you. San Francisco is a beautiful city."}
|
||||
]
|
||||
client.add(messages1, user_id="alex", version="v2")
|
||||
|
||||
# Second interaction - only need to send new messages
|
||||
messages2 = [
|
||||
{"role": "user", "content": "I like to eat sushi, and yesterday I went to Sunnyvale to eat sushi with my friends."},
|
||||
{"role": "assistant", "content": "Sushi is really a tasty choice. What did you do this weekend?"}
|
||||
]
|
||||
client.add(messages2, user_id="alex", version="v2")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// First interaction
|
||||
const messages1 = [
|
||||
{"role": "user", "content": "Hi, I'm Alex and I live in San Francisco."},
|
||||
{"role": "assistant", "content": "Hello Alex! Nice to meet you. San Francisco is a beautiful city."}
|
||||
];
|
||||
client.add(messages1, { user_id: "alex", version: "v2" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
|
||||
// Second interaction - only need to send new messages
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "I like to eat sushi, and yesterday I went to Sunnyvale to eat sushi with my friends."},
|
||||
{"role": "assistant", "content": "Sushi is really a tasty choice. What did you do this weekend?"}
|
||||
];
|
||||
client.add(messages2, { user_id: "alex", version: "v2" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Benefits of Using v2
|
||||
|
||||
1. **Simplified Integration**: No need to track and manage conversation history
|
||||
2. **Reduced Payload Size**: Only send new messages, not the entire conversation
|
||||
3. **Improved Memory Quality**: Automatic context retrieval ensures better memory generation
|
||||
|
||||
## Understanding ID Parameters in v2
|
||||
|
||||
When using contextual add v2, you have different options for how to organize and retrieve memories:
|
||||
|
||||
### Using Only `user_id`
|
||||
|
||||
When you provide only a `user_id`:
|
||||
|
||||
- Memories are associated with this user's long-term memory store
|
||||
- The system will automatically retrieve relevant context from all of the user's previous conversations
|
||||
- These memories persist indefinitely across all of the user's sessions
|
||||
- Ideal for maintaining persistent user information (preferences, personal details, etc.)
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Adding to long-term user memory
|
||||
messages = [
|
||||
{"role": "user", "content": "I'm allergic to peanuts and shellfish."},
|
||||
{"role": "assistant", "content": "I've noted your allergies to peanuts and shellfish."}
|
||||
]
|
||||
client.add(messages, user_id="alex", version="v2")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Adding to long-term user memory
|
||||
const messages = [
|
||||
{"role": "user", "content": "I'm allergic to peanuts and shellfish."},
|
||||
{"role": "assistant", "content": "I've noted your allergies to peanuts and shellfish."}
|
||||
];
|
||||
client.add(messages, { user_id: "alex", version: "v2" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Using `user_id` with `run_id`
|
||||
|
||||
When you provide both `user_id` and `run_id`:
|
||||
|
||||
- Memories are associated with a specific conversation session or interaction
|
||||
- The system will retrieve context primarily from this specific session
|
||||
- These memories are still tied to the user but are organized by the specific session
|
||||
- Ideal for maintaining context within a specific conversation flow or task
|
||||
- Helps prevent context from different conversations from interfering with each other
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Adding to a specific conversation session
|
||||
messages = [
|
||||
{"role": "user", "content": "For this trip to Paris, I want to focus on art museums."},
|
||||
{"role": "assistant", "content": "Great! I'll help you plan your Paris trip with a focus on art museums."}
|
||||
]
|
||||
client.add(messages, user_id="alex", run_id="paris-trip-2024", version="v2")
|
||||
|
||||
# Later in the same conversation session
|
||||
messages2 = [
|
||||
{"role": "user", "content": "I'd like to visit the Louvre on Monday."},
|
||||
{"role": "assistant", "content": "The Louvre is a great choice for Monday. Would you like information about opening hours?"}
|
||||
]
|
||||
client.add(messages2, user_id="alex", run_id="paris-trip-2024", version="v2")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Adding to a specific conversation session
|
||||
const messages = [
|
||||
{"role": "user", "content": "For this trip to Paris, I want to focus on art museums."},
|
||||
{"role": "assistant", "content": "Great! I'll help you plan your Paris trip with a focus on art museums."}
|
||||
];
|
||||
client.add(messages, { user_id: "alex", run_id: "paris-trip-2024", version: "v2" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
|
||||
// Later in the same conversation session
|
||||
const messages2 = [
|
||||
{"role": "user", "content": "I'd like to visit the Louvre on Monday."},
|
||||
{"role": "assistant", "content": "The Louvre is a great choice for Monday. Would you like information about opening hours?"}
|
||||
];
|
||||
client.add(messages2, { user_id: "alex", run_id: "paris-trip-2024", version: "v2" })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
Using `run_id` helps you organize memories into logical sessions or tasks, making it easier to maintain context for specific interactions while still associating everything with the user's overall profile.
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
184
docs/platform/features/criteria-retrieval.mdx
Normal file
184
docs/platform/features/criteria-retrieval.mdx
Normal file
@@ -0,0 +1,184 @@
|
||||
---
|
||||
title: Criteria Retrieval
|
||||
icon: "magnifying-glass-plus"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
Mem0's **Criteria Retrieval** feature allows you to retrieve memories based on specific criteria. This is useful when you need to find memories that match certain conditions or criteria, such as emotional content, sentiment, or other custom attributes.
|
||||
|
||||
## Setting Up Custom Criteria
|
||||
|
||||
You can define custom criteria at the project level, assigning weights to each criterion. These weights will be normalized during memory retrieval.
|
||||
|
||||
```python
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(
|
||||
api_key="mem0_api_key",
|
||||
org_id="mem0_organization_id",
|
||||
project_id="mem0_project_id"
|
||||
)
|
||||
|
||||
# Define custom criteria with weights
|
||||
retrieval_criteria = [
|
||||
{
|
||||
"name": "joy",
|
||||
"description": "Measure the intensity of positive emotions such as happiness, excitement, or amusement expressed in the sentence. A higher score reflects greater joy.",
|
||||
"weight": 3
|
||||
},
|
||||
{
|
||||
"name": "curiosity",
|
||||
"description": "Assess the extent to which the sentence reflects inquisitiveness, interest in exploring new information, or asking questions. A higher score reflects stronger curiosity.",
|
||||
"weight": 2
|
||||
},
|
||||
{
|
||||
"name": "emotion",
|
||||
"description": "Evaluate the presence and depth of sadness or negative emotional tone, including expressions of disappointment, frustration, or sorrow. A higher score reflects greater sadness.",
|
||||
"weight": 1
|
||||
}
|
||||
]
|
||||
|
||||
# Update project with custom criteria
|
||||
client.update_project(
|
||||
retrieval_criteria=retrieval_criteria
|
||||
)
|
||||
```
|
||||
|
||||
## Using Criteria Retrieval
|
||||
|
||||
After setting up your criteria, you can use them to filter and retrieve memories. Here's an example:
|
||||
|
||||
```python
|
||||
# Add some example memories
|
||||
messages = [
|
||||
{"role": "user", "content": "What a beautiful sunny day! I feel so refreshed and ready to take on anything!"},
|
||||
{"role": "user", "content": "I've always wondered how storms form—what triggers them in the atmosphere?"},
|
||||
{"role": "user", "content": "It's been raining for days, and it just makes everything feel heavier."},
|
||||
{"role": "user", "content": "Finally I get time to draw something today, after a long time!! I am super happy today."}
|
||||
]
|
||||
|
||||
client.add(messages, user_id="alice")
|
||||
|
||||
# Search with criteria-based filtering
|
||||
filters = {
|
||||
"AND": [
|
||||
{"user_id": "alice"}
|
||||
]
|
||||
}
|
||||
results_with_criteria = client.search(
|
||||
query="Why I am feeling happy today?",
|
||||
filters=filters,
|
||||
version="v2"
|
||||
)
|
||||
|
||||
# Standard search without criteria filtering
|
||||
results_without_criteria = client.search(
|
||||
query="Why I am feeling happy today?",
|
||||
user_id="alice"
|
||||
)
|
||||
```
|
||||
|
||||
## Search Results Comparison
|
||||
|
||||
Let's compare the results from criteria-based retrieval versus standard retrieval to see how the emotional criteria affects ranking:
|
||||
|
||||
### Search Results (with Criteria)
|
||||
```python
|
||||
[
|
||||
{
|
||||
"memory": "User feels refreshed and ready to take on anything on a beautiful sunny day",
|
||||
"score": 0.666,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "User finally has time to draw something after a long time",
|
||||
"score": 0.616,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "User is happy today",
|
||||
"score": 0.500,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "User is curious about how storms form and what triggers them in the atmosphere.",
|
||||
"score": 0.400,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "It has been raining for days, making everything feel heavier.",
|
||||
"score": 0.116,
|
||||
...
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
### Search Results (without Criteria)
|
||||
```python
|
||||
[
|
||||
{
|
||||
"memory": "User is happy today",
|
||||
"score": 0.607,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "User feels refreshed and ready to take on anything on a beautiful sunny day",
|
||||
"score": 0.512,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "It has been raining for days, making everything feel heavier.",
|
||||
"score": 0.4617,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "User is curious about how storms form and what triggers them in the atmosphere.",
|
||||
"score": 0.340,
|
||||
...
|
||||
},
|
||||
{
|
||||
"memory": "User finally has time to draw something after a long time",
|
||||
"score": 0.336,
|
||||
...
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Looking at the example results above, we can see how criteria-based filtering affects the output:
|
||||
|
||||
1. **Memory Ordering**: With criteria, memories with high joy scores (like feeling refreshed and drawing) are ranked higher, while without criteria, the most relevant memory ("User is happy today") comes first.
|
||||
|
||||
2. **Score Distribution**: With criteria, scores are more spread out (0.116 to 0.666) and reflect the criteria weights, while without criteria, scores are more clustered (0.336 to 0.607) and based purely on relevance.
|
||||
|
||||
3. **Negative Content**: With criteria, the negative memory about rain has a much lower score (0.116) due to the emotion criteria, while without criteria it maintains a relatively high score (0.4617) due to its relevance.
|
||||
|
||||
4. **Curiosity Content**: The storm-related memory gets a moderate score (0.400) with criteria due to the curiosity weighting, while without criteria it's ranked lower (0.340) as it's less relevant to the happiness query.
|
||||
|
||||
## Key Differences
|
||||
|
||||
1. **Scoring**: With criteria, normalized scores (0-1) are used based on custom criteria weights, while without criteria, standard relevance scoring is used
|
||||
|
||||
2. **Ordering**: With criteria, memories are first retrieved by relevance, then criteria-based filtering and prioritization is applied, while without criteria, ordering is solely by relevance
|
||||
|
||||
3. **Filtering**: With criteria, post-retrieval filtering based on custom criteria (joy, curiosity, etc.) is available, which isn't available without criteria
|
||||
|
||||
<Note>
|
||||
When no custom criteria are specified, the search will default to standard relevance-based retrieval. In this case, results are returned based solely on their relevance to the query, without any additional filtering or prioritization that would normally be applied through criteria.
|
||||
</Note>
|
||||
|
||||
## How It Works
|
||||
|
||||
1. **Criteria Definition**: Define custom criteria with names, descriptions, and weights
|
||||
2. **Project Configuration**: Apply these criteria at the project level
|
||||
3. **Memory Retrieval**: Use v2 search with filters to retrieve memories based on your criteria
|
||||
4. **Weighted Scoring**: Memories are scored based on the defined criteria weights
|
||||
|
||||
<Note>
|
||||
Criteria retrieval is currently supported only in search v2. Make sure to use `version="v2"` when performing searches with custom criteria.
|
||||
</Note>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
204
docs/platform/features/custom-categories.mdx
Normal file
204
docs/platform/features/custom-categories.mdx
Normal file
@@ -0,0 +1,204 @@
|
||||
---
|
||||
title: Custom Categories
|
||||
description: 'Enhance your product experience by adding custom categories tailored to your needs'
|
||||
icon: "tags"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## How to set custom categories?
|
||||
|
||||
You can now create custom categories tailored to your specific needs, instead of using the default categories such as travel, sports, music, and more (see [default categories](#default-categories) below). **When custom categories are provided, they will override the default categories.**
|
||||
|
||||
There are two ways to set custom categories:
|
||||
|
||||
### 1. Project Level
|
||||
|
||||
You can set custom categories at the project level, which will be applied to all memories added within that project. Mem0 will automatically assign relevant categories from your custom set to new memories based on their content. Setting custom categories at the project level will override the default categories.
|
||||
|
||||
Here's how to set custom categories:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
import os
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = MemoryClient()
|
||||
|
||||
# Update custom categories
|
||||
new_categories = [
|
||||
{"lifestyle_management_concerns": "Tracks daily routines, habits, hobbies and interests including cooking, time management and work-life balance"},
|
||||
{"seeking_structure": "Documents goals around creating routines, schedules, and organized systems in various life areas"},
|
||||
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
|
||||
]
|
||||
|
||||
response = client.update_project(custom_categories = new_categories)
|
||||
print(response)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"message": "Updated custom categories"
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
This is how you will use these custom categories during the `add` API call:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
messages = [
|
||||
{"role": "user", "content": "My name is Alice. I need help organizing my daily schedule better. I feel overwhelmed trying to balance work, exercise, and social life."},
|
||||
{"role": "assistant", "content": "I understand how overwhelming that can feel. Let's break this down together. What specific areas of your schedule feel most challenging to manage?"},
|
||||
{"role": "user", "content": "I want to be more productive at work, maintain a consistent workout routine, and still have energy for friends and hobbies."},
|
||||
{"role": "assistant", "content": "Those are great goals for better time management. What's one small change you could make to start improving your daily routine?"},
|
||||
]
|
||||
|
||||
# Add memories with custom categories
|
||||
client.add(messages, user_id="alice")
|
||||
```
|
||||
|
||||
```python Memories with categories
|
||||
# Following categories will be created for the memories added
|
||||
Wants to have energy for friends and hobbies (lifestyle_management_concerns)
|
||||
Wants to maintain a consistent workout routine (seeking_structure, lifestyle_management_concerns)
|
||||
Wants to be more productive at work (lifestyle_management_concerns, seeking_structure)
|
||||
Name is Alice (personal_information)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
You can also retrieve the current custom categories:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
# Get current custom categories
|
||||
categories = client.get_project(fields=["custom_categories"])
|
||||
print(categories)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"custom_categories": [
|
||||
{"lifestyle_management_concerns": "Tracks daily routines, habits, hobbies and interests including cooking, time management and work-life balance"},
|
||||
{"seeking_structure": "Documents goals around creating routines, schedules, and organized systems in various life areas"},
|
||||
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
|
||||
]
|
||||
}
|
||||
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
These project-level categories will be automatically applied to all new memories added to the project.
|
||||
|
||||
|
||||
|
||||
### 2. During the `add` API call
|
||||
You can also set custom categories during the `add` API call. This will override any project-level custom categories for that specific memory addition. For example, if you want to use different categories for food-related memories, you can provide custom categories like "food" and "user_preferences" in the `add` call. These custom categories will be used instead of the project-level categories when categorizing those specific memories.
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
import os
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = MemoryClient(api_key="<your_mem0_api_key>")
|
||||
|
||||
custom_categories = [
|
||||
{"seeking_structure": "Documents goals around creating routines, schedules, and organized systems in various life areas"},
|
||||
{"personal_information": "Basic information about the user including name, preferences, and personality traits"}
|
||||
]
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "My name is Alice. I need help organizing my daily schedule better. I feel overwhelmed trying to balance work, exercise, and social life."},
|
||||
{"role": "assistant", "content": "I understand how overwhelming that can feel. Let's break this down together. What specific areas of your schedule feel most challenging to manage?"},
|
||||
{"role": "user", "content": "I want to be more productive at work, maintain a consistent workout routine, and still have energy for friends and hobbies."},
|
||||
{"role": "assistant", "content": "Those are great goals for better time management. What's one small change you could make to start improving your daily routine?"},
|
||||
]
|
||||
|
||||
client.add(messages, user_id="alice", custom_categories=custom_categories)
|
||||
```
|
||||
|
||||
```python Memories with categories
|
||||
# Following categories will be created for the memories added
|
||||
Wants to have energy for friends and hobbies (seeking_structure)
|
||||
Wants to maintain a consistent workout routine (seeking_structure)
|
||||
Wants to be more productive at work (seeking_structure)
|
||||
Name is Alice (personal_information)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
<Note>Providing more detailed and specific category descriptions will lead to more accurate and relevant memory categorization.</Note>
|
||||
|
||||
|
||||
## Default Categories
|
||||
Here is the list of **default categories**. If you don't specify any custom categories using the above methods, these will be used as default categories.
|
||||
```
|
||||
- personal_details
|
||||
- family
|
||||
- professional_details
|
||||
- sports
|
||||
- travel
|
||||
- food
|
||||
- music
|
||||
- health
|
||||
- technology
|
||||
- hobbies
|
||||
- fashion
|
||||
- entertainment
|
||||
- milestones
|
||||
- user_preferences
|
||||
- misc
|
||||
```
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
import os
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = MemoryClient()
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "Hi, my name is Alice."},
|
||||
{"role": "assistant", "content": "Hi Alice, what sports do you like to play?"},
|
||||
{"role": "user", "content": "I love playing badminton, football, and basketball. I'm quite athletic!"},
|
||||
{"role": "assistant", "content": "That's great! Alice seems to enjoy both individual sports like badminton and team sports like football and basketball."},
|
||||
{"role": "user", "content": "Sometimes, I also draw and sketch in my free time."},
|
||||
{"role": "assistant", "content": "That's cool! I'm sure you're good at it."}
|
||||
]
|
||||
|
||||
# Add memories with default categories
|
||||
client.add(messages, user_id='alice')
|
||||
```
|
||||
|
||||
```python Memories with categories
|
||||
# Following categories will be created for the memories added
|
||||
Sometimes draws and sketches in free time (hobbies)
|
||||
Is quite athletic (sports)
|
||||
Loves playing badminton, football, and basketball (sports)
|
||||
Name is Alice (personal_details)
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
You can check whether default categories are being used by calling `get_project()`. If `custom_categories` returns `None`, it means the default categories are being used.
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
client.get_project(["custom_categories"])
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
'custom_categories': None
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
78
docs/platform/features/custom-instructions.mdx
Normal file
78
docs/platform/features/custom-instructions.mdx
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
title: Custom Instructions
|
||||
description: 'Enhance your product experience by adding custom instructions tailored to your needs'
|
||||
icon: "pencil"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Introduction to Custom Instructions
|
||||
|
||||
Custom instructions allow you to define specific guidelines for your project. This feature helps ensure consistency and provides clear direction for handling project-specific requirements.
|
||||
|
||||
Custom instructions are particularly useful when you want to:
|
||||
- Define how information should be extracted from conversations
|
||||
- Specify what types of data should be captured or ignored
|
||||
- Set rules for categorizing and organizing memories
|
||||
- Maintain consistent handling of project-specific requirements
|
||||
|
||||
When custom instructions are set at the project level, they will be applied to all new memories added within that project. This ensures that your data is processed according to your defined guidelines across your entire project.
|
||||
|
||||
## Setting Custom Instructions
|
||||
|
||||
You can set custom instructions for your project using the following method:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
# Update custom instructions
|
||||
prompt ="""
|
||||
Your Task: Extract ONLY health-related information from conversations, focusing on the following areas:
|
||||
|
||||
1. Medical Conditions, Symptoms, and Diagnoses:
|
||||
- Illnesses, disorders, or symptoms (e.g., fever, diabetes).
|
||||
- Confirmed or suspected diagnoses.
|
||||
|
||||
2. Medications, Treatments, and Procedures:
|
||||
- Prescription or OTC medications (names, dosages).
|
||||
- Treatments, therapies, or medical procedures.
|
||||
|
||||
3. Diet, Exercise, and Sleep:
|
||||
- Dietary habits, fitness routines, and sleep patterns.
|
||||
|
||||
4. Doctor Visits and Appointments:
|
||||
- Past, upcoming, or regular medical visits.
|
||||
|
||||
5. Health Metrics:
|
||||
- Data like weight, BP, cholesterol, or sugar levels.
|
||||
|
||||
Guidelines:
|
||||
- Focus solely on health-related content.
|
||||
- Maintain clarity and context accuracy while recording.
|
||||
"""
|
||||
response = client.update_project(custom_instructions=prompt)
|
||||
print(response)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"message": "Updated custom instructions"
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
You can also retrieve the current custom instructions:
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
# Retrieve current custom instructions
|
||||
response = client.get_project(fields=["custom_instructions"])
|
||||
print(response)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"custom_instructions": "Your Task: Extract ONLY health-related information from conversations, focusing on the following areas:\n1. Medical Conditions, Symptoms, and Diagnoses - illnesses, disorders, or symptoms (e.g., fever, diabetes), confirmed or suspected diagnoses.\n2. Medications, Treatments, and Procedures - prescription or OTC medications (names, dosages), treatments, therapies, or medical procedures.\n3. Diet, Exercise, and Sleep - dietary habits, fitness routines, and sleep patterns.\n4. Doctor Visits and Appointments - past, upcoming, or regular medical visits.\n5. Health Metrics - data like weight, BP, cholesterol, or sugar levels.\n\nGuidelines: Focus solely on health-related content. Maintain clarity and context accuracy while recording."
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
106
docs/platform/features/direct-import.mdx
Normal file
106
docs/platform/features/direct-import.mdx
Normal file
@@ -0,0 +1,106 @@
|
||||
---
|
||||
title: Direct Import
|
||||
description: 'Bypass the memory deduction phase and directly store pre-defined memories for efficient retrieval'
|
||||
icon: "arrow-right"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## How to use Direct Import?
|
||||
The Direct Import feature allows users to skip the memory deduction phase and directly input pre-defined memories into the system for storage and retrieval.
|
||||
To enable this feature, you need to set the `infer` parameter to `False` in the `add` method.
|
||||
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
|
||||
```python Python
|
||||
messages = [
|
||||
{"role": "user", "content": "Alice loves playing badminton"},
|
||||
{"role": "assistant", "content": "That's great! Alice is a fitness freak"},
|
||||
{"role": "user", "content": "Alice mostly cook at home because of gym plan"},
|
||||
]
|
||||
|
||||
|
||||
client.add(messages, user_id="alice", infer=False)
|
||||
```
|
||||
|
||||
```markdown Output
|
||||
[]
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
You can see that the output of add call is an empty list.
|
||||
|
||||
<Note> Only messages with the role "user" will be used for storage. Messages with roles such as "assistant" or "system" will be ignored during the storage process. </Note>
|
||||
|
||||
|
||||
## How to retrieve memories?
|
||||
|
||||
You can retrieve memories using the `search` method.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
client.search("What is Alice's favorite sport?", user_id="alice", output_format="v1.1")
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "19d6d7aa-2454-4e58-96fc-e74d9e9f8dd1",
|
||||
"memory": "Alice loves playing badminton",
|
||||
"user_id": "pc123",
|
||||
"metadata": null,
|
||||
"categories": null,
|
||||
"created_at": "2024-10-15T21:52:11.474901-07:00",
|
||||
"updated_at": "2024-10-15T21:52:11.474912-07:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## How to retrieve all memories?
|
||||
|
||||
You can retrieve all memories using the `get_all` method.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
client.get_all(query="What is Alice's favorite sport?", user_id="alice", output_format="v1.1")
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "19d6d7aa-2454-4e58-96fc-e74d9e9f8dd1",
|
||||
"memory": "Alice loves playing badminton",
|
||||
"user_id": "pc123",
|
||||
"metadata": null,
|
||||
"categories": null,
|
||||
"created_at": "2024-10-15T21:52:11.474901-07:00",
|
||||
"updated_at": "2024-10-15T21:52:11.474912-07:00"
|
||||
},
|
||||
{
|
||||
"id": "8557f05d-7b3c-47e5-b409-9886f9e314fc",
|
||||
"memory": "Alice mostly cook at home because of gym plan",
|
||||
"user_id": "pc123",
|
||||
"metadata": null,
|
||||
"categories": null,
|
||||
"created_at": "2024-10-15T21:52:11.474929-07:00",
|
||||
"updated_at": "2024-10-15T21:52:11.474932-07:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
114
docs/platform/features/expiration-date.mdx
Normal file
114
docs/platform/features/expiration-date.mdx
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
title: Expiration Date
|
||||
description: 'Set time-bound memories in Mem0 with automatic expiration dates to manage temporal information effectively.'
|
||||
icon: "clock"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Benefits of Memory Expiration
|
||||
|
||||
Setting expiration dates for memories offers several advantages:
|
||||
|
||||
• **Time-Sensitive Information Management**: Handle information that's only relevant for a specific time period.
|
||||
|
||||
• **Event-Based Memory**: Manage information related to upcoming events that becomes irrelevant after the event passes.
|
||||
|
||||
These benefits enable more sophisticated memory management for applications where temporal context matters.
|
||||
|
||||
## Setting Memory Expiration Date
|
||||
|
||||
You can set an expiration date for memories, after which they will no longer be retrieved in searches. This is useful for creating temporary memories or memories that are only relevant for a specific time period.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
import datetime
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="your-api-key")
|
||||
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "I'll be in San Francisco until end of this month."
|
||||
}
|
||||
]
|
||||
|
||||
# Set an expiration date for this memory
|
||||
client.add(messages=messages, user_id="alex", expiration_date=str(datetime.datetime.now().date() + datetime.timedelta(days=30)))
|
||||
|
||||
# You can also use an explicit date string
|
||||
client.add(messages=messages, user_id="alex", expiration_date="2023-08-31")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import MemoryClient from 'mem0ai';
|
||||
const client = new MemoryClient({ apiKey: 'your-api-key' });
|
||||
|
||||
const messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "I'll be in San Francisco until end of this month."
|
||||
}
|
||||
];
|
||||
|
||||
// Set an expiration date 30 days from now
|
||||
const expirationDate = new Date();
|
||||
expirationDate.setDate(expirationDate.getDate() + 30);
|
||||
client.add(messages, {
|
||||
user_id: "alex",
|
||||
expiration_date: expirationDate.toISOString().split('T')[0]
|
||||
})
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
|
||||
// You can also use an explicit date string
|
||||
client.add(messages, {
|
||||
user_id: "alex",
|
||||
expiration_date: "2023-08-31"
|
||||
})
|
||||
.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": "I'll be in San Francisco until end of this month."
|
||||
}
|
||||
],
|
||||
"user_id": "alex",
|
||||
"expiration_date": "2023-08-31"
|
||||
}'
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",
|
||||
"data": {
|
||||
"memory": "In San Francisco until end of this month"
|
||||
},
|
||||
"event": "ADD"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
<Note>
|
||||
Once a memory reaches its expiration date, it won't be included in search or get results, though the data remains stored in the system.
|
||||
</Note>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
64
docs/platform/features/feedback-mechanism.mdx
Normal file
64
docs/platform/features/feedback-mechanism.mdx
Normal file
@@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Feedback Mechanism
|
||||
icon: "thumbs-up"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
Mem0's **Feedback Mechanism** allows you to provide feedback on the memories generated by your application. This feedback is used to improve the accuracy of the memories and the search results.
|
||||
|
||||
## How it works
|
||||
|
||||
The feedback mechanism is a simple API that allows you to provide feedback on the memories generated by your application. The feedback is stored in the database and is used to improve the accuracy of the memories and the search results. Over time, Mem0 continuously learns from this feedback, refining its memory generation and search capabilities for better performance.
|
||||
|
||||
## Give Feedback
|
||||
|
||||
You can give feedback on a memory by calling the `feedback` method on the Mem0 client.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(api_key="your_api_key")
|
||||
|
||||
client.feedback(memory_id="your-memory-id", feedback="NEGATIVE", feedback_reason="I don't like this memory because it is not relevant.")
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import MemoryClient from 'mem0ai';
|
||||
|
||||
const client = new MemoryClient({ apiKey: 'your-api-key'});
|
||||
|
||||
client.feedback({
|
||||
memory_id: "your-memory-id",
|
||||
feedback: "NEGATIVE",
|
||||
feedback_reason: "I don't like this memory because it is not relevant."
|
||||
})
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Feedback Types
|
||||
|
||||
The `feedback` parameter can be one of the following values:
|
||||
|
||||
- `POSITIVE`: The memory is useful.
|
||||
- `NEGATIVE`: The memory is not useful.
|
||||
- `VERY_NEGATIVE`: The memory is not useful at all.
|
||||
|
||||
## Parameters
|
||||
|
||||
The `feedback` method takes the following parameters:
|
||||
|
||||
- `memory_id`: The ID of the memory to give feedback on.
|
||||
- `feedback`: The feedback to give on the memory. (Optional)
|
||||
- `feedback_reason`: The reason for the feedback. (Optional)
|
||||
|
||||
The `feedback_reason` parameter is optional and can be used to provide a reason for the feedback.
|
||||
|
||||
<Note>
|
||||
You can pass `None` or `null` to the `feedback` and `feedback_reason` parameters to remove the feedback for a memory.
|
||||
</Note>
|
||||
|
||||
297
docs/platform/features/graph-memory.mdx
Normal file
297
docs/platform/features/graph-memory.mdx
Normal file
@@ -0,0 +1,297 @@
|
||||
---
|
||||
title: Graph Memory
|
||||
icon: "circle-nodes"
|
||||
iconType: "solid"
|
||||
description: "Enable graph-based memory retrieval for more contextually relevant results"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Overview
|
||||
|
||||
Graph Memory enhances memory pipeline by creating relationships between entities in your data. It builds a network of interconnected information for more contextually relevant search results.
|
||||
|
||||
This feature allows your AI applications to understand connections between entities, providing richer context for responses. It's ideal for applications needing relationship tracking and nuanced information retrieval across related memories.
|
||||
|
||||
## How Graph Memory Works
|
||||
|
||||
The Graph Memory feature analyzes how each entity connects and relates to each other. When enabled:
|
||||
|
||||
1. Mem0 automatically builds a graph representation of entities
|
||||
2. Retrieval considers graph relationships between entities
|
||||
3. Results include entities that may be contextually important even if they're not direct semantic matches
|
||||
|
||||
## Using Graph Memory
|
||||
|
||||
To use Graph Memory, you need to enable it in your API calls by setting the `enable_graph=True` parameter. You'll also need to specify `output_format="v1.1"` to receive the enriched response format.
|
||||
|
||||
### Adding Memories with Graph Memory
|
||||
|
||||
When adding new memories, enable Graph Memory to automatically build relationships with existing memories:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient(
|
||||
api_key="your-api-key",
|
||||
org_id="your-org-id",
|
||||
project_id="your-project-id"
|
||||
)
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "My name is Joseph"},
|
||||
{"role": "assistant", "content": "Hello Joseph, it's nice to meet you!"},
|
||||
{"role": "user", "content": "I'm from Seattle and I work as a software engineer"}
|
||||
]
|
||||
|
||||
# Enable graph memory when adding
|
||||
client.add(
|
||||
messages,
|
||||
user_id="joseph",
|
||||
version="v1",
|
||||
enable_graph=True,
|
||||
output_format="v1.1"
|
||||
)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import { MemoryClient } from "mem0";
|
||||
|
||||
const client = new MemoryClient({
|
||||
apiKey: "your-api-key",
|
||||
org_id: "your-org-id",
|
||||
project_id: "your-project-id"
|
||||
});
|
||||
|
||||
const messages = [
|
||||
{ role: "user", content: "My name is Joseph" },
|
||||
{ role: "assistant", content: "Hello Joseph, it's nice to meet you!" },
|
||||
{ role: "user", content: "I'm from Seattle and I work as a software engineer" }
|
||||
];
|
||||
|
||||
// Enable graph memory when adding
|
||||
await client.add({
|
||||
messages,
|
||||
user_id: "joseph",
|
||||
version: "v1",
|
||||
enable_graph: true,
|
||||
output_format: "v1.1"
|
||||
});
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"memory": "Name is Joseph",
|
||||
"event": "ADD",
|
||||
"id": "4a5a417a-fa10-43b5-8c53-a77c45e80438"
|
||||
},
|
||||
{
|
||||
"memory": "Is from Seattle",
|
||||
"event": "ADD",
|
||||
"id": "8d268d0f-5452-4714-b27d-ae46f676a49d"
|
||||
},
|
||||
{
|
||||
"memory": "Is a software engineer",
|
||||
"event": "ADD",
|
||||
"id": "5f0a184e-ddea-4fe6-9b92-692d6a901df8"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
The graph memory would look like this:
|
||||
|
||||
<Frame>
|
||||
<img src="/images/graph-platform.png" alt="Graph Memory Visualization showing relationships between entities" />
|
||||
</Frame>
|
||||
|
||||
<Caption>Graph Memory creates a network of relationships between entities, enabling more contextual retrieval</Caption>
|
||||
|
||||
|
||||
<Note>
|
||||
Response for the graph memory's `add` operation will not be available directly in the response.
|
||||
As adding graph memories is an asynchronous operation due to heavy processing,
|
||||
you can use the `get_all()` endpoint to retrieve the memory with the graph metadata.
|
||||
</Note>
|
||||
|
||||
|
||||
### Searching with Graph Memory
|
||||
|
||||
When searching memories, Graph Memory helps retrieve entities that are contextually important even if they're not direct semantic matches.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Search with graph memory enabled
|
||||
results = client.search(
|
||||
"what is my name?",
|
||||
user_id="joseph",
|
||||
enable_graph=True,
|
||||
output_format="v1.1"
|
||||
)
|
||||
|
||||
print(results)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Search with graph memory enabled
|
||||
const results = await client.search({
|
||||
query: "what is my name?",
|
||||
user_id: "joseph",
|
||||
enable_graph: true,
|
||||
output_format: "v1.1"
|
||||
});
|
||||
|
||||
console.log(results);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "4a5a417a-fa10-43b5-8c53-a77c45e80438",
|
||||
"memory": "Name is Joseph",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.146390-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.146404-07:00",
|
||||
"score": 0.3621795393335552
|
||||
},
|
||||
{
|
||||
"id": "8d268d0f-5452-4714-b27d-ae46f676a49d",
|
||||
"memory": "Is from Seattle",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.170680-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.170692-07:00",
|
||||
"score": 0.31212713194651254
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "name",
|
||||
"target": "joseph",
|
||||
"target_type": "person",
|
||||
"score": 0.39
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Retrieving All Memories with Graph Memory
|
||||
|
||||
When retrieving all memories, Graph Memory provides additional relationship context:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Get all memories with graph context
|
||||
memories = client.get_all(
|
||||
user_id="joseph",
|
||||
enable_graph=True,
|
||||
output_format="v1.1"
|
||||
)
|
||||
|
||||
print(memories)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Get all memories with graph context
|
||||
const memories = await client.getAll({
|
||||
user_id: "joseph",
|
||||
enable_graph: true,
|
||||
output_format: "v1.1"
|
||||
});
|
||||
|
||||
console.log(memories);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "5f0a184e-ddea-4fe6-9b92-692d6a901df8",
|
||||
"memory": "Is a software engineer",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["professional_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.194116-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.194128-07:00",
|
||||
},
|
||||
{
|
||||
"id": "8d268d0f-5452-4714-b27d-ae46f676a49d",
|
||||
"memory": "Is from Seattle",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.170680-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.170692-07:00",
|
||||
},
|
||||
{
|
||||
"id": "4a5a417a-fa10-43b5-8c53-a77c45e80438",
|
||||
"memory": "Name is Joseph",
|
||||
"user_id": "joseph",
|
||||
"metadata": null,
|
||||
"categories": ["personal_details"],
|
||||
"immutable": false,
|
||||
"created_at": "2025-03-19T09:09:00.146390-07:00",
|
||||
"updated_at": "2025-03-19T09:09:00.146404-07:00",
|
||||
}
|
||||
],
|
||||
"relations": [
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "name",
|
||||
"target": "joseph",
|
||||
"target_type": "person"
|
||||
},
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "city",
|
||||
"target": "seattle",
|
||||
"target_type": "city"
|
||||
},
|
||||
{
|
||||
"source": "joseph",
|
||||
"source_type": "person",
|
||||
"relationship": "job",
|
||||
"target": "software engineer",
|
||||
"target_type": "job"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Best Practices
|
||||
|
||||
- Enable Graph Memory for applications where understanding context and relationships between memories is important
|
||||
- Graph Memory works best with a rich history of related conversations
|
||||
- Consider Graph Memory for long-running assistants that need to track evolving information
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
Graph Memory requires additional processing and may increase response times slightly for very large memory stores. However, for most use cases, the improved retrieval quality outweighs the minimal performance impact.
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
|
||||
205
docs/platform/features/memory-export.mdx
Normal file
205
docs/platform/features/memory-export.mdx
Normal file
@@ -0,0 +1,205 @@
|
||||
---
|
||||
title: Memory Export
|
||||
description: 'Export memories in a structured format using customizable Pydantic schemas'
|
||||
icon: "file-export"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Overview
|
||||
|
||||
The Memory Export feature allows you to create structured exports of memories using customizable Pydantic schemas. This process enables you to transform your stored memories into specific data formats that match your needs. You can apply various filters to narrow down which memories to export and define exactly how the data should be structured.
|
||||
|
||||
## Creating a Memory Export
|
||||
|
||||
To create a memory export, you'll need to:
|
||||
1. Define your schema structure
|
||||
2. Submit an export job
|
||||
3. Retrieve the exported data
|
||||
|
||||
### Define Schema
|
||||
|
||||
Here's an example schema for extracting professional profile information:
|
||||
|
||||
```json
|
||||
{
|
||||
"$defs": {
|
||||
"EducationLevel": {
|
||||
"enum": ["high_school", "bachelors", "masters"],
|
||||
"title": "EducationLevel",
|
||||
"type": "string"
|
||||
},
|
||||
"EmploymentStatus": {
|
||||
"enum": ["full_time", "part_time", "student"],
|
||||
"title": "EmploymentStatus",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"full_name": {
|
||||
"anyOf": [
|
||||
{
|
||||
"maxLength": 100,
|
||||
"minLength": 2,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "The professional's full name",
|
||||
"title": "Full Name"
|
||||
},
|
||||
"current_role": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
],
|
||||
"default": null,
|
||||
"description": "Current job title or role",
|
||||
"title": "Current Role"
|
||||
}
|
||||
},
|
||||
"title": "ProfessionalProfile",
|
||||
"type": "object"
|
||||
}
|
||||
```
|
||||
|
||||
### Submit Export Job
|
||||
|
||||
You can optionally provide additional instructions to guide how memories are processed and structured during export using the `export_instructions` parameter.
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Basic export request
|
||||
response = client.create_memory_export(
|
||||
schema=json_schema,
|
||||
user_id="alice"
|
||||
)
|
||||
|
||||
# Export with custom instructions
|
||||
export_instructions = """
|
||||
1. Create a comprehensive profile with detailed information in each category
|
||||
2. Only mark fields as "None" when absolutely no relevant information exists
|
||||
3. Base all information directly on the user's memories
|
||||
4. When contradictions exist, prioritize the most recent information
|
||||
5. Clearly distinguish between factual statements and inferences
|
||||
"""
|
||||
|
||||
# For create operation, using only user_id filter as requested
|
||||
filters = {
|
||||
"AND": [
|
||||
{"user_id": "alex"}
|
||||
]
|
||||
}
|
||||
|
||||
response = client.create_memory_export(
|
||||
schema=json_schema,
|
||||
filters=filters,
|
||||
export_instructions=export_instructions # Optional
|
||||
)
|
||||
|
||||
print(response)
|
||||
```
|
||||
|
||||
```bash cURL
|
||||
curl -X POST "https://api.mem0.ai/v1/memories/export/" \
|
||||
-H "Authorization: Token your-api-key" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"schema": {json_schema},
|
||||
"user_id": "alice",
|
||||
"export_instructions": "1. Create a comprehensive profile with detailed information\n2. Only mark fields as \"None\" when absolutely no relevant information exists"
|
||||
}'
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"message": "Memory export request received. The export will be ready in a few seconds.",
|
||||
"id": "550e8400-e29b-41d4-a716-446655440000"
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Retrieve Export
|
||||
|
||||
Once the export job is complete, you can retrieve the structured data in two ways:
|
||||
|
||||
#### Using Filters
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Retrieve using filters
|
||||
filters = {
|
||||
"AND": [
|
||||
{"created_at": {"gte": "2024-07-10", "lte": "2024-07-20"}},
|
||||
{"user_id": "alex"}
|
||||
]
|
||||
}
|
||||
|
||||
response = client.get_memory_export(filters=filters)
|
||||
print(response)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"full_name": "John Doe",
|
||||
"current_role": "Senior Software Engineer",
|
||||
"years_experience": 8,
|
||||
"employment_status": "full_time",
|
||||
"education_level": "masters",
|
||||
"skills": ["Python", "AWS", "Machine Learning"]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
#### Using Export ID
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Retrieve using export ID
|
||||
response = client.get_memory_export(memory_export_id="550e8400-e29b-41d4-a716-446655440000")
|
||||
print(response)
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"full_name": "John Doe",
|
||||
"current_role": "Senior Software Engineer",
|
||||
"years_experience": 8,
|
||||
"employment_status": "full_time",
|
||||
"education_level": "masters",
|
||||
"skills": ["Python", "AWS", "Machine Learning"]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Available Filters
|
||||
|
||||
You can apply various filters to customize which memories are included in the export:
|
||||
|
||||
- `user_id`: Filter memories by specific user
|
||||
- `agent_id`: Filter memories by specific agent
|
||||
- `run_id`: Filter memories by specific run
|
||||
- `session_id`: Filter memories by specific session
|
||||
- `created_at`: Filter memories by date
|
||||
|
||||
<Note>
|
||||
The export process may take some time to complete, especially when dealing with a large number of memories or complex schemas.
|
||||
</Note>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
307
docs/platform/features/multimodal-support.mdx
Normal file
307
docs/platform/features/multimodal-support.mdx
Normal file
@@ -0,0 +1,307 @@
|
||||
---
|
||||
title: Multimodal Support
|
||||
description: Integrate images and documents into your interactions with Mem0
|
||||
icon: "image"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
Mem0 extends its capabilities beyond text by supporting multimodal data, including images and documents. With this feature, users can seamlessly integrate visual and document content into their interactions—allowing Mem0 to extract relevant information from various media types and enrich the memory system.
|
||||
|
||||
## How It Works
|
||||
|
||||
When a user submits an image or document, Mem0 processes it to extract textual information and other pertinent details. These details are then added to the user's memory, enhancing the system's ability to understand and recall multimodal inputs.
|
||||
|
||||
<CodeGroup>
|
||||
```python Python
|
||||
import os
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = MemoryClient()
|
||||
|
||||
messages = [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hi, my name is Alice."
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "Nice to meet you, Alice! What do you like to eat?"
|
||||
},
|
||||
{
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": "https://www.superhealthykids.com/wp-content/uploads/2021/10/best-veggie-pizza-featured-image-square-2.jpg"
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
# Calling the add method to ingest messages into the memory system
|
||||
client.add(messages, user_id="alice")
|
||||
```
|
||||
|
||||
```typescript TypeScript
|
||||
import MemoryClient from "mem0ai";
|
||||
|
||||
const client = new MemoryClient();
|
||||
|
||||
const messages = [
|
||||
{
|
||||
role: "user",
|
||||
content: "Hi, my name is Alice."
|
||||
},
|
||||
{
|
||||
role: "assistant",
|
||||
content: "Nice to meet you, Alice! What do you like to eat?"
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: {
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
url: "https://www.superhealthykids.com/wp-content/uploads/2021/10/best-veggie-pizza-featured-image-square-2.jpg"
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
await client.add(messages, { user_id: "alice" })
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"memory": "Name is Alice",
|
||||
"event": "ADD",
|
||||
"id": "7ae113a3-3cb5-46e9-b6f7-486c36391847"
|
||||
},
|
||||
{
|
||||
"memory": "Likes large pizza with toppings including cherry tomatoes, black olives, green spinach, yellow bell peppers, diced ham, and sliced mushrooms",
|
||||
"event": "ADD",
|
||||
"id": "56545065-7dee-4acf-8bf2-a5b2535aabb3"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
## Supported Media Types
|
||||
|
||||
Mem0 currently supports the following media types:
|
||||
|
||||
1. **Images** - JPG, PNG, and other common image formats
|
||||
2. **Documents** - MDX, TXT, and PDF files
|
||||
|
||||
## Integration Methods
|
||||
|
||||
### 1. Images
|
||||
|
||||
#### Using an Image URL (Recommended)
|
||||
|
||||
You can include an image by providing its direct URL. This method is simple and efficient for online images.
|
||||
|
||||
```python {2, 5-13}
|
||||
# Define the image URL
|
||||
image_url = "https://www.superhealthykids.com/wp-content/uploads/2021/10/best-veggie-pizza-featured-image-square-2.jpg"
|
||||
|
||||
# Create the message dictionary with the image URL
|
||||
image_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": image_url
|
||||
}
|
||||
}
|
||||
}
|
||||
client.add([image_message], user_id="alice")
|
||||
```
|
||||
|
||||
#### Using Base64 Image Encoding for Local Files
|
||||
|
||||
For local images—or when embedding the image directly is preferable—you can use a Base64-encoded string.
|
||||
|
||||
<CodeGroup>
|
||||
```python Python
|
||||
import base64
|
||||
|
||||
# Path to the image file
|
||||
image_path = "path/to/your/image.jpg"
|
||||
|
||||
# Encode the image in Base64
|
||||
with open(image_path, "rb") as image_file:
|
||||
base64_image = base64.b64encode(image_file.read()).decode("utf-8")
|
||||
|
||||
# Create the message dictionary with the Base64-encoded image
|
||||
image_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": f"data:image/jpeg;base64,{base64_image}"
|
||||
}
|
||||
}
|
||||
}
|
||||
client.add([image_message], user_id="alice")
|
||||
```
|
||||
|
||||
```typescript TypeScript
|
||||
import MemoryClient from "mem0ai";
|
||||
import fs from 'fs';
|
||||
|
||||
const imagePath = 'path/to/your/image.jpg';
|
||||
|
||||
const base64Image = fs.readFileSync(imagePath, { encoding: 'base64' });
|
||||
|
||||
const imageMessage = {
|
||||
role: "user",
|
||||
content: {
|
||||
type: "image_url",
|
||||
image_url: {
|
||||
url: `data:image/jpeg;base64,${base64Image}`
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await client.add([imageMessage], { user_id: "alice" })
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
### 2. Text Documents (MDX/TXT)
|
||||
|
||||
Mem0 supports both online and local text documents in MDX or TXT format.
|
||||
|
||||
#### Using a Document URL
|
||||
|
||||
```python
|
||||
# Define the document URL
|
||||
document_url = "https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt"
|
||||
|
||||
# Create the message dictionary with the document URL
|
||||
document_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "mdx_url",
|
||||
"mdx_url": {
|
||||
"url": document_url
|
||||
}
|
||||
}
|
||||
}
|
||||
client.add([document_message], user_id="alice")
|
||||
```
|
||||
|
||||
#### Using Base64 Encoding for Local Documents
|
||||
|
||||
```python
|
||||
import base64
|
||||
|
||||
# Path to the document file
|
||||
document_path = "path/to/your/document.txt"
|
||||
|
||||
# Function to convert file to Base64
|
||||
def file_to_base64(file_path):
|
||||
with open(file_path, "rb") as file:
|
||||
return base64.b64encode(file.read()).decode('utf-8')
|
||||
|
||||
# Encode the document in Base64
|
||||
base64_document = file_to_base64(document_path)
|
||||
|
||||
# Create the message dictionary with the Base64-encoded document
|
||||
document_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "mdx_url",
|
||||
"mdx_url": {
|
||||
"url": base64_document
|
||||
}
|
||||
}
|
||||
}
|
||||
client.add([document_message], user_id="alice")
|
||||
```
|
||||
|
||||
### 3. PDF Documents
|
||||
|
||||
Mem0 supports PDF documents via URL.
|
||||
|
||||
```python
|
||||
# Define the PDF URL
|
||||
pdf_url = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
|
||||
|
||||
# Create the message dictionary with the PDF URL
|
||||
pdf_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "pdf_url",
|
||||
"pdf_url": {
|
||||
"url": pdf_url
|
||||
}
|
||||
}
|
||||
}
|
||||
client.add([pdf_message], user_id="alice")
|
||||
```
|
||||
|
||||
## Complete Example with Multiple File Types
|
||||
|
||||
Here's a comprehensive example showing how to work with different file types:
|
||||
|
||||
```python
|
||||
import base64
|
||||
from mem0 import MemoryClient
|
||||
|
||||
client = MemoryClient()
|
||||
|
||||
def file_to_base64(file_path):
|
||||
with open(file_path, "rb") as file:
|
||||
return base64.b64encode(file.read()).decode('utf-8')
|
||||
|
||||
# Example 1: Using an image URL
|
||||
image_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "image_url",
|
||||
"image_url": {
|
||||
"url": "https://example.com/sample-image.jpg"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Example 2: Using a text document URL
|
||||
text_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "mdx_url",
|
||||
"mdx_url": {
|
||||
"url": "https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Example 3: Using a PDF URL
|
||||
pdf_message = {
|
||||
"role": "user",
|
||||
"content": {
|
||||
"type": "pdf_url",
|
||||
"pdf_url": {
|
||||
"url": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Add each message to the memory system
|
||||
client.add([image_message], user_id="alice")
|
||||
client.add([text_message], user_id="alice")
|
||||
client.add([pdf_message], user_id="alice")
|
||||
```
|
||||
|
||||
Using these methods, you can seamlessly incorporate various media types into your interactions, further enhancing Mem0's multimodal capabilities.
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
50
docs/platform/features/platform-overview.mdx
Normal file
50
docs/platform/features/platform-overview.mdx
Normal file
@@ -0,0 +1,50 @@
|
||||
---
|
||||
title: Overview
|
||||
icon: "info"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
Learn about the key features and capabilities that make Mem0 a powerful platform for memory management and retrieval.
|
||||
|
||||
## Core Features
|
||||
|
||||
<CardGroup>
|
||||
<Card title="Advanced Retrieval" icon="magnifying-glass" href="/features/advanced-retrieval">
|
||||
Superior search results using state-of-the-art algorithms, including keyword search, reranking, and filtering capabilities.
|
||||
</Card>
|
||||
<Card title="Contextual Add" icon="square-plus" href="/features/contextual-add">
|
||||
Only send your latest conversation history - we automatically retrieve the rest and generate properly contextualized memories.
|
||||
</Card>
|
||||
<Card title="Multimodal Support" icon="photo-film" href="/features/multimodal-support">
|
||||
Process and analyze various types of content including images.
|
||||
</Card>
|
||||
<Card title="Memory Customization" icon="filter" href="/features/selective-memory">
|
||||
Customize and curate stored memories to focus on relevant information while excluding unnecessary data, enabling improved accuracy, privacy control, and resource efficiency.
|
||||
</Card>
|
||||
<Card title="Custom Categories" icon="tags" href="/features/custom-categories">
|
||||
Create and manage custom categories to organize memories based on your specific needs and requirements.
|
||||
</Card>
|
||||
<Card title="Custom Instructions" icon="list-check" href="/features/custom-instructions">
|
||||
Define specific guidelines for your project to ensure consistent handling of information and requirements.
|
||||
</Card>
|
||||
<Card title="Direct Import" icon="message-bot" href="/features/direct-import">
|
||||
Tailor the behavior of your Mem0 instance with custom prompts for specific use cases or domains.
|
||||
</Card>
|
||||
<Card title="Async Client" icon="bolt" href="/features/async-client">
|
||||
Asynchronous client for non-blocking operations and high concurrency applications.
|
||||
</Card>
|
||||
<Card title="Memory Export" icon="file-export" href="/features/memory-export">
|
||||
Export memories in structured formats using customizable Pydantic schemas.
|
||||
</Card>
|
||||
<Card title="Graph Memory" icon="graph" href="/features/graph-memory">
|
||||
Add memories in the form of nodes and edges in a graph database and search for related memories.
|
||||
</Card>
|
||||
</CardGroup>
|
||||
|
||||
## Getting Help
|
||||
|
||||
If you have any questions about these features or need assistance, our team is here to help:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
113
docs/platform/features/selective-memory.mdx
Normal file
113
docs/platform/features/selective-memory.mdx
Normal file
@@ -0,0 +1,113 @@
|
||||
---
|
||||
title: Memory Customization
|
||||
description: 'Mem0 supports customizing the memories you store, allowing you to focus on pertinent information while omitting irrelevant data.'
|
||||
icon: "filter"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Benefits of Memory Customization
|
||||
|
||||
Memory customization offers several key benefits:
|
||||
|
||||
• **Focused Storage**: Store only relevant information for a streamlined system.
|
||||
|
||||
• **Improved Accuracy**: Curate memories for more accurate and relevant retrieval.
|
||||
|
||||
• **Enhanced Privacy**: Exclude sensitive information for better privacy control.
|
||||
|
||||
• **Resource Efficiency**: Optimize storage and processing by keeping only pertinent data.
|
||||
|
||||
• **Personalization**: Tailor the experience to individual user preferences.
|
||||
|
||||
• **Contextual Relevance**: Improve effectiveness in specialized domains or applications.
|
||||
|
||||
These benefits allow users to fine-tune their memory systems, creating a more powerful and personalized AI assistant experience.
|
||||
|
||||
|
||||
## Memory Inclusion
|
||||
Users can define specific kinds of memories to store. This feature enhances memory management by focusing on relevant information, resulting in a more efficient and personalized experience.
|
||||
Here’s how you can do it:
|
||||
|
||||
```python
|
||||
import os
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
m = MemoryClient()
|
||||
|
||||
# Define what to include
|
||||
includes = "sports related things"
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "Hi, my name is Alice and I love to play badminton"},
|
||||
{"role": "assistant", "content": "Nice to meet you, Alice! Badminton is a great sport."},
|
||||
{"role": "user", "content": "I love music festivals"},
|
||||
{"role": "assistant", "content": "Music festivals are exciting! Do you have a favorite one?"},
|
||||
{"role": "user", "content": "I love eating spicy food"},
|
||||
{"role": "assistant", "content": "Spicy food is delicious! What's your favorite spicy dish?"},
|
||||
{"role": "user", "content": "I love playing baseball with my friends"},
|
||||
{"role": "assistant", "content": "Baseball with friends sounds fun!"},
|
||||
]
|
||||
```
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
client.add(messages, user_id="alice", includes=includes)
|
||||
```
|
||||
|
||||
```json Stored Memories
|
||||
User's name is Alice.
|
||||
Alice loves to play badminton.
|
||||
User loves playing baseball with friends.
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
|
||||
|
||||
## Memory Exclusion
|
||||
|
||||
In addition to specifying what to include, users can also define exclusion rules for their memory management. This feature allows for fine-tuning the memory system by instructing it to omit certain types of information.
|
||||
Here’s how you can do it:
|
||||
|
||||
```python
|
||||
from mem0 import MemoryClient
|
||||
|
||||
m = MemoryClient(api_key="xxx")
|
||||
|
||||
# Define what to exclude
|
||||
excludes = "food preferences"
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "Hi, my name is Alice and I love to play badminton"},
|
||||
{"role": "assistant", "content": "Nice to meet you, Alice! Badminton is a great sport."},
|
||||
{"role": "user", "content": "I love music festivals"},
|
||||
{"role": "assistant", "content": "Music festivals are exciting! Do you have a favorite one?"},
|
||||
{"role": "user", "content": "I love eating spicy food"},
|
||||
{"role": "assistant", "content": "Spicy food is delicious! What's your favorite spicy dish?"},
|
||||
{"role": "user", "content": "I love playing baseball with my friends"},
|
||||
{"role": "assistant", "content": "Baseball with friends sounds fun!"},
|
||||
]
|
||||
```
|
||||
|
||||
<CodeGroup>
|
||||
```python Code
|
||||
client.add(messages, user_id="alice", excludes=excludes)
|
||||
```
|
||||
|
||||
```json Stored Memories
|
||||
User's name is Alice.
|
||||
Alice loves to play badminton.
|
||||
Loves music festivals.
|
||||
User loves playing baseball with friends.
|
||||
```
|
||||
</CodeGroup>
|
||||
|
||||
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
150
docs/platform/features/timestamp.mdx
Normal file
150
docs/platform/features/timestamp.mdx
Normal file
@@ -0,0 +1,150 @@
|
||||
---
|
||||
title: Memory Timestamps
|
||||
description: 'Add timestamps to your memories to maintain chronological accuracy and historical context'
|
||||
icon: "clock"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Overview
|
||||
|
||||
The Memory Timestamps feature allows you to specify when a memory was created, regardless of when it's actually added to the system. This powerful capability enables you to:
|
||||
|
||||
- Maintain accurate chronological ordering of memories
|
||||
- Import historical data with proper timestamps
|
||||
- Create memories that reflect when events actually occurred
|
||||
- Build timelines with precise temporal information
|
||||
|
||||
By leveraging custom timestamps, you can ensure that your memory system maintains an accurate representation of when information was generated or events occurred.
|
||||
|
||||
## Benefits of Custom Timestamps
|
||||
|
||||
Custom timestamps offer several important benefits:
|
||||
|
||||
• **Historical Accuracy**: Preserve the exact timing of past events and information.
|
||||
|
||||
• **Data Migration**: Seamlessly migrate existing data while maintaining original timestamps.
|
||||
|
||||
• **Time-Sensitive Analysis**: Enable time-based analysis and pattern recognition across memories.
|
||||
|
||||
• **Consistent Chronology**: Maintain proper ordering of memories for coherent storytelling.
|
||||
|
||||
## Using Custom Timestamps
|
||||
|
||||
When adding new memories, you can specify a custom timestamp to indicate when the memory was created. This timestamp will be used instead of the current time.
|
||||
|
||||
### Adding Memories with Custom Timestamps
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = MemoryClient()
|
||||
|
||||
# Get the current time
|
||||
current_time = datetime.now()
|
||||
|
||||
# Calculate 5 days ago
|
||||
five_days_ago = current_time - timedelta(days=5)
|
||||
|
||||
# Convert to Unix timestamp (seconds since epoch)
|
||||
unix_timestamp = int(five_days_ago.timestamp())
|
||||
|
||||
# Add memory with custom timestamp
|
||||
messages = [
|
||||
{"role": "user", "content": "I'm travelling to SF"}
|
||||
]
|
||||
client.add(messages, user_id="user1", timestamp=unix_timestamp)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
import MemoryClient from 'mem0ai';
|
||||
const client = new MemoryClient({ apiKey: 'your-api-key' });
|
||||
|
||||
// Get the current time
|
||||
const currentTime = new Date();
|
||||
|
||||
// Calculate 5 days ago
|
||||
const fiveDaysAgo = new Date();
|
||||
fiveDaysAgo.setDate(currentTime.getDate() - 5);
|
||||
|
||||
// Convert to Unix timestamp (seconds since epoch)
|
||||
const unixTimestamp = Math.floor(fiveDaysAgo.getTime() / 1000);
|
||||
|
||||
// Add memory with custom timestamp
|
||||
const messages = [
|
||||
{"role": "user", "content": "I'm travelling to SF"}
|
||||
]
|
||||
client.add(messages, { user_id: "user1", timestamp: unixTimestamp })
|
||||
.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": "I'm travelling to SF"}],
|
||||
"user_id": "user1",
|
||||
"timestamp": 1721577600
|
||||
}'
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"results": [
|
||||
{
|
||||
"id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",
|
||||
"data": {"memory": "Travelling to SF"},
|
||||
"event": "ADD"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Timestamp Format
|
||||
|
||||
When specifying a custom timestamp, you should provide a Unix timestamp (seconds since epoch). This is an integer representing the number of seconds that have elapsed since January 1, 1970 (UTC).
|
||||
|
||||
For example, to create a memory with a timestamp of January 1, 2023:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# January 1, 2023 timestamp
|
||||
january_2023_timestamp = 1672531200 # Unix timestamp for 2023-01-01 00:00:00 UTC
|
||||
|
||||
messages = [
|
||||
{"role": "user", "content": "I'm travelling to SF"}
|
||||
]
|
||||
client.add(messages, user_id="user1", timestamp=january_2023_timestamp)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// January 1, 2023 timestamp
|
||||
const january2023Timestamp = 1672531200; // Unix timestamp for 2023-01-01 00:00:00 UTC
|
||||
|
||||
const messages = [
|
||||
{"role": "user", "content": "I'm travelling to SF"}
|
||||
]
|
||||
client.add(messages, { user_id: "user1", timestamp: january2023Timestamp })
|
||||
.then(response => console.log(response))
|
||||
.catch(error => console.error(error));
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
203
docs/platform/features/webhooks.mdx
Normal file
203
docs/platform/features/webhooks.mdx
Normal file
@@ -0,0 +1,203 @@
|
||||
---
|
||||
title: Webhooks
|
||||
description: 'Configure and manage webhooks to receive real-time notifications about memory events'
|
||||
icon: "webhook"
|
||||
iconType: "solid"
|
||||
---
|
||||
|
||||
<Snippet file="paper-release.mdx" />
|
||||
|
||||
## Overview
|
||||
|
||||
Webhooks enable real-time notifications for memory events in your Mem0 project. Webhooks are configured at the project level, meaning each webhook is tied to a specific project and receives events solely from that project. You can configure webhooks to send HTTP POST requests to your specified URLs whenever memories are created, updated, or deleted.
|
||||
|
||||
## Managing Webhooks
|
||||
|
||||
### Create Webhook
|
||||
|
||||
Create a webhook for your project; it will receive events only from that project:
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
import os
|
||||
from mem0 import MemoryClient
|
||||
|
||||
os.environ["MEM0_API_KEY"] = "your-api-key"
|
||||
|
||||
client = MemoryClient()
|
||||
|
||||
# Create webhook in a specific project
|
||||
webhook = client.create_webhook(
|
||||
url="https://your-app.com/webhook",
|
||||
name="Memory Logger",
|
||||
project_id="proj_123",
|
||||
event_types=["memory_add"]
|
||||
)
|
||||
print(webhook)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
const { MemoryClient } = require('mem0ai');
|
||||
const client = new MemoryClient({ apiKey: 'your-api-key'});
|
||||
|
||||
// Create webhook in a specific project
|
||||
const webhook = await client.createWebhook({
|
||||
url: "https://your-app.com/webhook",
|
||||
name: "Memory Logger",
|
||||
projectId: "proj_123",
|
||||
eventTypes: ["memory_add"]
|
||||
});
|
||||
console.log(webhook);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"webhook_id": "wh_123",
|
||||
"name": "Memory Logger",
|
||||
"url": "https://your-app.com/webhook",
|
||||
"event_types": ["memory_add"],
|
||||
"project": "default-project",
|
||||
"is_active": true,
|
||||
"created_at": "2025-02-18T22:59:56.804993-08:00",
|
||||
"updated_at": "2025-02-18T23:06:41.479361-08:00"
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Get Webhooks
|
||||
|
||||
Retrieve all webhooks for your project:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Get webhooks for a specific project
|
||||
webhooks = client.get_webhooks(project_id="proj_123")
|
||||
print(webhooks)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Get webhooks for a specific project
|
||||
const webhooks = await client.getWebhooks({projectId: "proj_123"});
|
||||
console.log(webhooks);
|
||||
```
|
||||
|
||||
```json Output
|
||||
[
|
||||
{
|
||||
"webhook_id": "wh_123",
|
||||
"url": "https://mem0.ai",
|
||||
"name": "mem0",
|
||||
"owner": "john",
|
||||
"event_types": ["memory_add"],
|
||||
"project": "default-project",
|
||||
"is_active": true,
|
||||
"created_at": "2025-02-18T22:59:56.804993-08:00",
|
||||
"updated_at": "2025-02-18T23:06:41.479361-08:00"
|
||||
}
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Update Webhook
|
||||
|
||||
Update an existing webhook’s configuration by specifying its `webhook_id`:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Update webhook for a specific project
|
||||
updated_webhook = client.update_webhook(
|
||||
name="Updated Logger",
|
||||
url="https://your-app.com/new-webhook",
|
||||
event_types=["memory_update", "memory_add"],
|
||||
webhook_id="wh_123"
|
||||
)
|
||||
print(updated_webhook)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Update webhook for a specific project
|
||||
const updatedWebhook = await client.updateWebhook({
|
||||
name: "Updated Logger",
|
||||
url: "https://your-app.com/new-webhook",
|
||||
eventTypes: ["memory_update", "memory_add"],
|
||||
webhookId: "wh_123"
|
||||
});
|
||||
console.log(updatedWebhook);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"message": "Webhook updated successfully"
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
### Delete Webhook
|
||||
|
||||
Delete a webhook by providing its `webhook_id`:
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```python Python
|
||||
# Delete webhook from a specific project
|
||||
response = client.delete_webhook(webhook_id="wh_123")
|
||||
print(response)
|
||||
```
|
||||
|
||||
```javascript JavaScript
|
||||
// Delete webhook from a specific project
|
||||
const response = await client.deleteWebhook({webhookId: "wh_123"});
|
||||
console.log(response);
|
||||
```
|
||||
|
||||
```json Output
|
||||
{
|
||||
"message": "Webhook deleted successfully"
|
||||
}
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## Event Types
|
||||
|
||||
Mem0 supports the following event types for webhooks:
|
||||
|
||||
- `memory_add`: Triggered when a memory is added.
|
||||
- `memory_update`: Triggered when an existing memory is updated.
|
||||
- `memory_delete`: Triggered when a memory is deleted.
|
||||
|
||||
## Webhook Payload
|
||||
|
||||
When a memory event occurs, Mem0 sends an HTTP POST request to your webhook URL with the following payload:
|
||||
|
||||
```json
|
||||
{
|
||||
"event_details": {
|
||||
"id": "a1b2c3d4-e5f6-4g7h-8i9j-k0l1m2n3o4p5",
|
||||
"data": {
|
||||
"memory": "Name is Alex"
|
||||
},
|
||||
"event": "ADD"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Implement Retry Logic**: Ensure your webhook endpoint can handle temporary failures by implementing retry logic.
|
||||
|
||||
2. **Verify Webhook Source**: Implement security measures to verify that webhook requests originate from Mem0.
|
||||
|
||||
3. **Process Events Asynchronously**: Process webhook events asynchronously to avoid timeouts and ensure reliable handling.
|
||||
|
||||
4. **Monitor Webhook Health**: Regularly review your webhook logs to ensure functionality and promptly address any delivery failures.
|
||||
|
||||
If you have any questions, please feel free to reach out to us using one of the following methods:
|
||||
|
||||
<Snippet file="get-help.mdx" />
|
||||
Reference in New Issue
Block a user