5.9 KiB
5.9 KiB
In [1]:
from mem0 import Memory
import os
os.environ["OPENAI_API_KEY"] = ""In [2]:
config = {
"embedder": {
"provider": "openai",
"config": {"model": "text-embedding-3-large", "embedding_dims": 1536},
},
"graph_store": {
"provider": "neo4j",
"config": {
"url": "bolt://54.87.227.131:7687",
"username": "neo4j",
"password": "causes-bins-vines",
},
},
}In [3]:
m = Memory.from_config(config_dict=config)In [4]:
messages = [
{
"role": "user",
"content": "I'm planning to watch a movie tonight. Any recommendations?",
},
{
"role": "assistant",
"content": "How about a thriller movies? 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.",
},
]In [5]:
# Store inferred memories (default behavior)
result = m.add(messages, user_id="alice")In [6]:
for result in m.search("what does alice love?", user_id="alice")["results"]:
print(result["memory"], result["score"])Loves sci-fi movies 0.3153664287340898 Planning to watch a movie tonight 0.09683349296551162 Not a big fan of thriller movies 0.09468540071789466
In [6]:
