Update Docs (#3520)

This commit is contained in:
Deshraj Yadav
2025-09-30 08:41:36 -07:00
committed by GitHub
parent 135883935f
commit d68ed11d58
134 changed files with 2193 additions and 2090 deletions
+7 -7
View File
@@ -7,7 +7,7 @@ iconType: "solid"
## AsyncMemory
The `AsyncMemory` class is a direct asynchronous interface to Mem0's in-process memory operations. Unlike the memory, which interacts with an API, `AsyncMemory` works directly with the underlying storage systems. This makes it ideal for applications where you want to embed Mem0 directly into your codebase.
The `AsyncMemory` class is a direct asynchronous interface to Mem0's in-process memory operations. Unlike the synchronous memory class, which interacts with an API, `AsyncMemory` works directly with the underlying storage systems. This makes it ideal for applications where you want to embed Mem0 directly into your codebase.
### Initialization
@@ -30,10 +30,10 @@ memory = AsyncMemory(config=custom_config)
### Key Features
1. **Non-blocking Operations** - All memory operations use `asyncio` to avoid blocking the event loop
2. **Concurrent Processing** - Parallel execution of vector store and graph operations
3. **Efficient Resource Utilization** - Better handling of I/O bound operations
4. **Compatible with Async Frameworks** - Seamless integration with FastAPI, aiohttp, and other async frameworks
1. **Non-blocking Operations**: All memory operations use `asyncio` to avoid blocking the event loop.
2. **Concurrent Processing**: Parallel execution of vector store and graph operations.
3. **Efficient Resource Utilization**: Better handling of I/O-bound operations.
4. **Compatible with Async Frameworks**: Seamless integration with FastAPI, aiohttp, and other async frameworks.
### Methods
@@ -182,7 +182,7 @@ except Exception as e:
### Example: Concurrent Usage with Other APIs
`AsyncMemory` can be effectively combined with other async operations. Here's an example showing how to use it alongside OpenAI API calls in separate threads:
`AsyncMemory` can be effectively combined with other async operations. Here's an example showing how to use it alongside OpenAI API calls:
```python Python
import asyncio
@@ -199,7 +199,7 @@ async def chat_with_memories(message: str, user_id: str = "default_user") -> str
relevant_memories = search_result["results"]
memories_str = "\n".join(f"- {entry['memory']}" for entry in relevant_memories)
# Generate Assistant response
# Generate assistant response
system_prompt = f"You are a helpful AI. Answer the question based on query and memories.\nUser Memories:\n{memories_str}"
messages = [{"role": "system", "content": system_prompt}, {"role": "user", "content": message}]
response = await async_openai_client.chat.completions.create(model="gpt-4o-mini", messages=messages)
@@ -7,8 +7,7 @@ iconType: "solid"
## Introduction to Custom Fact Extraction Prompt
Custom fact extraction prompt allow you to tailor the behavior of your Mem0 instance to specific use cases or domains.
By defining it, you can control how information is extracted from the user's message.
Custom fact extraction prompts allow you to tailor the behavior of your Mem0 instance to specific use cases or domains. By defining them, you can control how information is extracted from the user's messages.
To create an effective custom fact extraction prompt:
1. Be specific about the information to extract.
@@ -146,8 +145,7 @@ await memory.add('Yesterday, I ordered a laptop, the order id is 12345', { userI
### Example 2
In this example, we are adding a memory of a user liking to go on hikes. This add message is not specific to the use-case mentioned in the custom prompt.
Hence, the memory is not added.
In this example, we are adding a memory of a user liking to go on hikes. This message is not specific to the use case mentioned in the custom prompt. Hence, the memory is not added.
<CodeGroup>
```python Python
@@ -5,23 +5,18 @@ iconType: "solid"
---
Update memory prompt is a prompt used to determine the action to be performed on the memory.
By customizing this prompt, you can control how the memory is updated.
The update memory prompt is used to determine the action to be performed on the memory. By customizing this prompt, you can control how the memory is updated.
## Introduction
The Mem0 memory system compares newly retrieved facts with existing memory and determines the action to be performed. The types of actions are:
- **Add**: Add the newly retrieved facts to the memory.
- **Update**: Update the existing memory with the newly retrieved facts.
- **Delete**: Delete the existing memory.
- **No Change**: Do not make any changes to the memory.
## Introduction
Mem0 memory system compares the newly retrieved facts with the existing memory and determines the action to be performed on the memory.
The kinds of actions are:
- Add
- Add the newly retrieved facts to the memory.
- Update
- Update the existing memory with the newly retrieved facts.
- Delete
- Delete the existing memory.
- No Change
- Do not make any changes to the memory.
### Example
Example of a custom update memory prompt:
<CodeGroup>
@@ -178,7 +173,8 @@ Please note to return the IDs in the output from the input IDs only and do not g
```
</CodeGroup>
## Output format
## Output Format
The prompt needs to guide the output to follow the structure as shown below:
<CodeGroup>
```json Add
@@ -232,10 +228,10 @@ The prompt needs to guide the output to follow the structure as shown below:
</CodeGroup>
## custom update memory prompt vs custom prompt
## Custom Update Memory Prompt vs Custom Prompt
| Feature | `custom_update_memory_prompt` | `custom_prompt` |
|---------|-------------------------------|-----------------|
| Use case | Determine the action to be performed on the memory | Extract the facts from messages |
| Use case | Determine the action to be performed on the memory | Extract facts from messages |
| Reference | Retrieved facts from messages and old memory | Messages |
| Output | Action to be performed on the memory | Extracted facts |
@@ -69,10 +69,10 @@ client.add(messages, user_id="alice")
## Supported Image Formats
Mem0 supports common image formats:
- **JPEG/JPG** - Standard photos and images
- **PNG** - Images with transparency support
- **WebP** - Modern web-optimized format
- **GIF** - Animated and static graphics
- **JPEG/JPG**: Standard photos and images
- **PNG**: Images with transparency support
- **WebP**: Modern web-optimized format
- **GIF**: Animated and static graphics
## Local Files vs URLs
@@ -224,9 +224,9 @@ client.add(messages, user_id="user123")
- **Resolution**: Images are automatically resized if needed
### Performance Tips
1. **Compress large images** before sending to reduce processing time
2. **Use appropriate formats** - JPEG for photos, PNG for graphics with text
3. **Batch processing** - Send multiple images in separate requests for better reliability
1. **Compress large images** before sending to reduce processing time.
2. **Use appropriate formats**: JPEG for photos, PNG for graphics with text.
3. **Batch processing**: Send multiple images in separate requests for better reliability.
## Error Handling
@@ -291,19 +291,19 @@ try {
## Best Practices
### Image Selection
- **Use high-quality images** with clear, readable text and details
- **Ensure good lighting** in photos for better text extraction
- **Avoid heavily stylized fonts** that may be difficult to read
- **Use high-quality images** with clear, readable text and details.
- **Ensure good lighting** in photos for better text extraction.
- **Avoid heavily stylized fonts** that may be difficult to read.
### Memory Context
- **Provide context** about what information you want extracted
- **Combine with text** to give Mem0 better understanding of the image's purpose
- **Be specific** about what aspects of the image are important
- **Provide context** about what information you want extracted.
- **Combine with text** to give Mem0 better understanding of the image's purpose.
- **Be specific** about what aspects of the image are important.
### Privacy and Security
- **Avoid sensitive information** in images (SSN, passwords, private data)
- **Use secure image hosting** for URLs to prevent unauthorized access
- **Consider local processing** for highly sensitive visual content
- **Avoid sensitive information** in images (SSN, passwords, private data).
- **Use secure image hosting** for URLs to prevent unauthorized access.
- **Consider local processing** for highly sensitive visual content.
Using these methods, you can seamlessly incorporate various visual content types into your interactions, further enhancing Mem0's multimodal capabilities for more comprehensive memory management.
@@ -6,7 +6,7 @@ iconType: "solid"
Mem0 can be easily integrated into chat applications to enhance conversational agents with structured memory. Mem0's APIs are designed to be compatible with OpenAI's, with the goal of making it easy to leverage Mem0 in applications you may have already built.
If you have a `Mem0 API key`, you can use it to initialize the client. Alternatively, you can initialize Mem0 without an API key if you're using it locally.
If you have a Mem0 API key, you can use it to initialize the client. Alternatively, you can initialize Mem0 without an API key if you're using it locally.
Mem0 supports several language models (LLMs) through integration with various [providers](https://litellm.vercel.app/docs/providers).
@@ -21,7 +21,7 @@ client = Mem0(api_key="m0-xxx")
messages = [
{
"role": "user",
"content": "I love indian food but I cannot eat pizza since allergic to cheese."
"content": "I love Indian food but I cannot eat pizza since I'm allergic to cheese."
},
]
user_id = "alice"
@@ -51,7 +51,7 @@ print(chat_completion.choices[0].message.content)
In this example, you can see how the second response is tailored based on the information provided in the first interaction. Mem0 remembers the user's preference for Indian food and their cheese allergy, using this information to provide more relevant and personalized restaurant suggestions in San Francisco.
### Use Mem0 OSS
## Use Mem0 OSS
```python
config = {
+1 -1
View File
@@ -54,4 +54,4 @@ Choose your preferred approach:
- Check out our [examples](/examples) for practical implementations
- Join our [Discord community](https://mem0.dev/DiD) for support
We're excited to see what you'll build with Mem0 open-source. Let's create smarter, more personalized AI experiences together!
We're excited to see what you'll build with Mem0 open-source.
+7 -7
View File
@@ -12,13 +12,13 @@ Mem0 provides a REST API server (written using FastAPI). Users can perform all o
## Features
- **Create memories:** Create memories based on messages for a user, agent, or run.
- **Retrieve memories:** Get all memories for a given user, agent, or run.
- **Search memories:** Search stored memories based on a query.
- **Update memories:** Update an existing memory.
- **Delete memories:** Delete a specific memory or all memories for a user, agent, or run.
- **Reset memories:** Reset all memories for a user, agent, or run.
- **OpenAPI Documentation:** Accessible via `/docs` endpoint.
- **Create memories**: Create memories based on messages for a user, agent, or run.
- **Retrieve memories**: Get all memories for a given user, agent, or run.
- **Search memories**: Search stored memories based on a query.
- **Update memories**: Update an existing memory.
- **Delete memories**: Delete a specific memory or all memories for a user, agent, or run.
- **Reset memories**: Reset all memories for a user, agent, or run.
- **OpenAPI Documentation**: Accessible via `/docs` endpoint.
## Running Locally