mem0 icon indicating copy to clipboard operation
mem0 copied to clipboard

Sometimes a part of system prompt is saved as a memory.

Open ssipasseuth opened this issue 7 months ago • 5 comments

🐛 Describe the bug

In Memory._add_to_vector_store(), it seems that when retrieved_old_memory and new_retrieved_facts are empty, mem0ai misidentifies a part of the system prompt ("The new retrieved facts are mentioned in the triple backticks.") as a new memory.

Image Image Image

The attached screenshots show that "The new retrieved facts are mentioned in the triple backticks." has been misinterpreted as a new memory. I managed to reproduce it quite frequently unfortunately.

ssipasseuth avatar May 21 '25 00:05 ssipasseuth

Thanks for reporting this issue @ssipasseuth. We will definitely look into this. Seems like the GPT-4.1-mini is hallucinating in this case sadly. Have you tried any other model?

deshraj avatar May 21 '25 00:05 deshraj

You can try the Mem0 Platform in the meantime to resolve the issue if you want to use the hosted service: https://app.mem0.ai/

We have trained our own models to do better memory extraction.

deshraj avatar May 21 '25 00:05 deshraj

Hi, thanks for your prompt response. I have not tried the hosted services yet sorry, because it is only a personal project for now, I cannot afford to pay for the subs and I am afraid that the free tier is too limiting for my testing.

FYI, I patched my local setup to temporarily fix the issue. In mem0/memory/main.py, I did the following change on AsyncMemory._add_to_vector_store and Memory._add_to_vector_store // ... existing code ... unique_data = {} for item in retrieved_old_memory: unique_data[item["id"]] = item retrieved_old_memory = list(unique_data.values()) logging.info(f"Total existing memories: {len(retrieved_old_memory)}")

    # Return empty list if both retrieved_old_memory and new_retrieved_facts are empty
    if not retrieved_old_memory and not new_retrieved_facts:
        return []

    temp_uuid_mapping = {}

// ... existing code ...

Indeed I find somewhat strange to send a new update memory request to the llm when there is no old nor new memory to compare. Maybe this might be a solution worth considering?

ssipasseuth avatar May 21 '25 08:05 ssipasseuth

If it helps, I also tested with gpt-4o-mini-2024-07-18 this morning, I managed to reproduce that same issue too.

ssipasseuth avatar May 21 '25 09:05 ssipasseuth

Hey, thanks! This issue has been fixed now. You should be able to try it out.

chaithanyak42 avatar May 23 '25 12:05 chaithanyak42

Thank you very much! I tested the fix and it seems that the issue is now gone!

ssipasseuth avatar May 29 '25 13:05 ssipasseuth