Update Docs (#3520)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user