Memory Operations with Mem0
View Notebook on Github
This example demonstrates how to use Mem0’s memory management capabilities with both synchronous and asynchronous operations to store, search, and manage conversational context and user preferences.
This example showcases practical memory management operations where we:
By using async operations, you can perform multiple memory operations simultaneously instead of waiting for each one to complete sequentially. This is particularly beneficial when dealing with multiple memory additions or searches.
Import the required libraries for local memory management with Mem0. We’ll use both Memory and AsyncMemory classes to demonstrate different execution patterns for memory operations.
Set up environment variables for API keys. These are essential for authenticating with AgentOps for tracing and OpenAI for the language model used in memory operations.
Set up the configuration for local memory storage and define sample user data. The configuration specifies the LLM provider and model settings for processing memories.
This function demonstrates sequential memory operations using the synchronous Memory class. While straightforward to implement, each operation must complete before the next begins, which can impact performance.
This function showcases concurrent memory operations using AsyncMemory. By leveraging asyncio.gather(), multiple operations execute simultaneously, significantly reducing total execution time for I/O-bound tasks.
Run both synchronous and asynchronous demonstrations to compare their execution patterns and performance. The async version demonstrates the benefits of concurrent execution for multiple memory operations.
Memory Operations with Mem0
View Notebook on Github
This example demonstrates how to use Mem0’s memory management capabilities with both synchronous and asynchronous operations to store, search, and manage conversational context and user preferences.
This example showcases practical memory management operations where we:
By using async operations, you can perform multiple memory operations simultaneously instead of waiting for each one to complete sequentially. This is particularly beneficial when dealing with multiple memory additions or searches.
Import the required libraries for local memory management with Mem0. We’ll use both Memory and AsyncMemory classes to demonstrate different execution patterns for memory operations.
Set up environment variables for API keys. These are essential for authenticating with AgentOps for tracing and OpenAI for the language model used in memory operations.
Set up the configuration for local memory storage and define sample user data. The configuration specifies the LLM provider and model settings for processing memories.
This function demonstrates sequential memory operations using the synchronous Memory class. While straightforward to implement, each operation must complete before the next begins, which can impact performance.
This function showcases concurrent memory operations using AsyncMemory. By leveraging asyncio.gather(), multiple operations execute simultaneously, significantly reducing total execution time for I/O-bound tasks.
Run both synchronous and asynchronous demonstrations to compare their execution patterns and performance. The async version demonstrates the benefits of concurrent execution for multiple memory operations.