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.

Installation

To use Mem0 with Graph Memory support, install it using pip:

pip install mem0ai[graph]

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 as a graph store provider. You can setup Neo4j locally or use the hosted Neo4j AuraDB. Moreover, you also need to set the version to v1.1 (prior versions are not supported).

If you are using Neo4j locally, then you need to install APOC plugins.

User can also customize the LLM for Graph Memory from the Supported LLM list with three levels of configuration:

  1. Main Configuration: If llm is set in the main config, it will be used for all graph operations.
  2. Graph Store Configuration: If llm is set in the graph_store config, it will override the main config llm and be used specifically for graph operations.
  3. 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:

Graph Operations

The Mem0’s graph supports the following operations:

Add Memories

Get all memories

Search Memories

Delete all Memories

m.delete_all(user_id="alice")

Example Usage

Here’s an example of how to use Mem0’s graph operations:

  1. First, we’ll add some memories for a user named Alice.
  2. Then, we’ll visualize how the graph evolves as we add more memories.
  3. 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:

1

Add memory 'I like going to hikes'

m.add("I like going to hikes", user_id="alice123")

2

Add memory 'I love to play badminton'

m.add("I love to play badminton", user_id="alice123")

3

Add memory 'I hate playing badminton'

m.add("I hate playing badminton", user_id="alice123")

4

Add memory 'My friend name is john and john has a dog named tommy'

m.add("My friend name is john and john has a dog named tommy", user_id="alice123")

5

Add memory 'My name is Alice'

m.add("My name is Alice", user_id="alice123")

6

Add memory 'John loves to hike and Harry loves to hike as well'

m.add("John loves to hike and Harry loves to hike as well", user_id="alice123")

7

Add memory 'My friend peter is the spiderman'

m.add("My friend peter is the spiderman", user_id="alice123")

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.

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: