Graph Memory
Enable graph-based memory retrieval for more contextually relevant results
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:
- Mem0 automatically builds a graph representation of entities
- Retrieval considers graph relationships between entities
- 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:
The graph memory would look like this:
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.
Searching with Graph Memory
When searching memories, Graph Memory helps retrieve entities that are contextually important even if they’re not direct semantic matches.
Retrieving All Memories with Graph Memory
When retrieving all memories, Graph Memory provides additional relationship context:
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: