Overview
Enhance your memory system with graph-based knowledge representation and retrieval
🔐 Mem0 is now SOC 2 and HIPAA compliant! We're committed to the highest standards of data security and privacy, enabling secure memory for enterprises, healthcare, and beyond. Learn more
Mem0 now supports Graph Memory. With Graph Memory, users can now create and utilize complex relationships between pieces of information, allowing for more nuanced and context-aware responses. This integration enables users to leverage the strengths of both vector-based and graph-based approaches, resulting in more accurate and comprehensive information retrieval and generation.
NodeSDK now supports Graph Memory. 🎉
Installation
To use Mem0 with Graph Memory support, install it using pip:
This command installs Mem0 along with the necessary dependencies for graph functionality.
Try Graph Memory on Google Colab.
Initialize Graph Memory
To initialize Graph Memory you’ll need to set up your configuration with graph store providers. Currently, we support Neo4j and Memgraph as graph store providers.
Initialize Neo4j
You can setup Neo4j locally or use the hosted Neo4j AuraDB.
User can also customize the LLM for Graph Memory from the Supported LLM list with three levels of configuration:
- Main Configuration: If
llm
is set in the main config, it will be used for all graph operations. - Graph Store Configuration: If
llm
is set in the graph_store config, it will override the main configllm
and be used specifically for graph operations. - Default Configuration: If no custom LLM is set, the default LLM (
gpt-4o-2024-08-06
) will be used for all graph operations.
Here’s how you can do it:
If you are using NodeSDK, you need to pass enableGraph
as true
in the config
object.
Initialize Memgraph
Run Memgraph with Docker:
The --schema-info-enabled
flag is set to True
for more performant schema
generation.
Additional information can be found on Memgraph documentation.
User can also customize the LLM for Graph Memory from the Supported LLM list with three levels of configuration:
- Main Configuration: If
llm
is set in the main config, it will be used for all graph operations. - Graph Store Configuration: If
llm
is set in the graph_store config, it will override the main configllm
and be used specifically for graph operations. - Default Configuration: If no custom LLM is set, the default LLM (
gpt-4o-2024-08-06
) will be used for all graph operations.
Here’s how you can do it:
Initialize Neptune Analytics
Mem0 now supports Amazon Neptune Analytics as a graph store provider. This integration allows you to use Neptune Analytics for storing and querying graph-based memories.
Instance Setup
Create an Amazon Neptune Analytics instance in your AWS account following the AWS documentation.
- Public connectivity is not enabled by default, and if accessing from outside a VPC, it needs to be enabled.
- Once the Amazon Neptune Analytics instance is available, you will need the graph-identifier to connect.
- The Neptune Analytics instance must be created using the same vector dimensions as the embedding model creates. See: https://docs.aws.amazon.com/neptune-analytics/latest/userguide/vector-index.html
Attach Credentials
Configure your AWS credentials with access to your Amazon Neptune Analytics resources by following the Configuration and credentials precedence.
- For example, add your SSH access key session token via environment variables:
- The IAM user or role making the request must have a policy attached that allows one of the following IAM actions in that neptune-graph:
- neptune-graph:ReadDataViaQuery
- neptune-graph:WriteDataViaQuery
- neptune-graph:DeleteDataViaQuery
Usage
The Neptune memory store uses AWS LangChain Python API to connect to Neptune instances. For additional configuration options for connecting to your Amazon Neptune Analytics instance see AWS LangChain API documentation.
Troubleshooting
-
For issues connecting to Amazon Neptune Analytics, please refer to the Connecting to a graph guide.
-
For issues related to authentication, refer to the boto3 client configuration options.
-
For more details on how to connect, configure, and use the graph_memory graph store, see the Neptune Analytics example notebook.
Graph Operations
The Mem0’s graph supports the following operations:
Add Memories
Mem0 with Graph Memory supports both “user_id” and “agent_id” parameters. You can use either or both to organize your memories. Use “userId” and “agentId” in NodeSDK.
Get all memories
Search Memories
Delete all Memories
Example Usage
Here’s an example of how to use Mem0’s graph operations:
- First, we’ll add some memories for a user named Alice.
- Then, we’ll visualize how the graph evolves as we add more memories.
- You’ll see how entities and relationships are automatically extracted and connected in the graph.
Add Memories
Below are the steps to add memories and visualize the graph:
Add memory 'I like going to hikes'
Add memory 'I love to play badminton'
Add memory 'I hate playing badminton'
Add memory 'My friend name is john and john has a dog named tommy'
Add memory 'My name is Alice'
Add memory 'John loves to hike and Harry loves to hike as well'
Add memory 'My friend peter is the spiderman'
Search Memories
Below graph visualization shows what nodes and relationships are fetched from the graph for the provided query.
Note: The Graph Memory implementation is not standalone. You will be adding/retrieving memories to the vector store and the graph store simultaneously.
Using Multiple Agents with Graph Memory
When working with multiple agents, you can use the “agent_id” parameter to organize memories by both user and agent. This allows you to:
- Create agent-specific knowledge graphs
- Share common knowledge between agents
- Isolate sensitive or specialized information to specific agents
Example: Multi-Agent Setup
If you want to use a managed version of Mem0, please check out Mem0. If you have any questions, please feel free to reach out to us using one of the following methods: