mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
22.76k stars 2.09k forks source link

Add method and search method bug #1645

Closed lemon-little closed 3 months ago

lemon-little commented 3 months ago

🐛 Describe the bug

import os
from mem0 import Memory
m = Memory()
# Store a memory from any unstructured text
result = m.add("I am working on improving my tennis skills. Suggest some online courses.", user_id="alice", metadata={"category": "hobbies"})
# print(f"result: {result}")
all_memories = m.get_all()
print(all_memories)
print(f"all_memories length: {len(all_memories)}")
result = m.add("I like working with my cumputer", user_id="alice", metadata={"category": "work"})
all_memories = m.get_all()
print(all_memories)
print(f"all_memories length: {len(all_memories)}")

Running the code for the first time: image image

Then I added the following code to run the code a second time:

# Search memories
related_memories = m.search(query="What are Alice's hobbies?", user_id="alice")
print(related_memories)
related_memories = m.search(query="What does alice like to work with?", user_id="alice")
print(related_memories)

image image image image

The questions are as follows:

  1. Most of the time, mem0 merges two unrelated memories into one memory. After adding multiple memories using the add method, when I use the get_all method, I can only get 1 memory, and occasionally I can get two memories. In my local test, I added dozens of different memories, and the get_all method only returned 1 memory.
  2. When I use the search method to look for a memory, I expect to find a specific memory. See the screenshot of my second run of the code. The answer to 'query="What are Alice's hobbies?"' is in the memory, but the corresponding memory is not found. It lost its memory.
cxycxm commented 3 months ago

def add( self, data, user_id=None, agent_id=None, run_id=None, metadata=None, filters=None, prompt=None, ):

existing_memories = [ MemoryItem( id=mem.id, score=mem.score, metadata=mem.payload, memory=mem.payload["data"], ) for mem in existing_memories ] serialized_existing_memories = [ item.model_dump(include={"id", "text", "score"}) for item in existing_memories ]

memory=mem.payload["data"], update: text=mem.payload["data"],

lemon-little commented 3 months ago

def add( self, data, user_id=None, agent_id=None, run_id=None, metadata=None, filters=None, prompt=None, ):

existing_memories = [ MemoryItem( id=mem.id, score=mem.score, metadata=mem.payload, memory=mem.payload["data"], ) for mem in existing_memories ] serialized_existing_memories = [ item.model_dump(include={"id", "text", "score"}) for item in existing_memories ]

memory=mem.payload["data"], update: text=mem.payload["data"],

What's the meaning?

lemon-little commented 3 months ago

1644 solved this problem