Sometimes a part of system prompt is saved as a memory.
🐛 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.
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.
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?
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.
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?
If it helps, I also tested with gpt-4o-mini-2024-07-18 this morning, I managed to reproduce that same issue too.
Hey, thanks! This issue has been fixed now. You should be able to try it out.
Thank you very much! I tested the fix and it seems that the issue is now gone!