Mem0
Mem0 is a framework for managing memory in AI applications. Its graph memory can use Memgraph as the backend, so an agent’s memories are stored and searched as a graph.
Mem0 graph memory with Memgraph works only in Mem0 1.x. Mem0 2.0 removed graph memory from the open-source package, so install a 1.x version, as shown below.
Installation
Install Mem0 1.x with graph memory support:
pip install "mem0ai[graph]<2"Start Memgraph. Mem0 stores embeddings in a Memgraph vector index:
docker run -p 7687:7687 memgraph/memgraph-mage:latestConfiguration
Set your OpenAI API key:
from mem0 import Memory
import os
os.environ["OPENAI_API_KEY"] = "YOUR_OPENAI_API_KEY"Configure OpenAI for embeddings and Memgraph as the graph store:
config = {
"embedder": {
"provider": "openai",
"config": {
"model": "text-embedding-3-large",
"embedding_dims": 1536,
},
},
"graph_store": {
"provider": "memgraph",
"config": {
"url": "bolt://localhost:7687",
"username": "memgraph",
"password": "mem0graph",
},
},
}Create the memory store. Mem0 connects to Memgraph and creates the vector index it needs:
m = Memory.from_config(config_dict=config)Store memories
Add a conversation as memories for a user, with metadata:
messages = [
{"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"},
{"role": "assistant", "content": "How about a thriller movie? They can be quite engaging."},
{"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."},
{"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."},
]
result = m.add(messages, user_id="alice", metadata={"category": "movie_recommendations"})Search memories
Search a user’s memories with a question:
for result in m.search("what does alice love?", user_id="alice")["results"]:
print(result["memory"], result["score"])The output looks like this:
Loves sci-fi movies 0.315
Planning to watch a movie tonight 0.096
Not a big fan of thriller movies 0.094For the full example, see Mem0’s Memgraph notebook from the 1.0.5 release.