Files
mem0/tests
Varun Chawla 211a7570e7 Fix: prevent double embedding in mem0.add (fixes #3723)
This fix addresses issue #3723 where mem0.add() was calling the
embedding API twice, unnecessarily doubling costs and latency.

Changes made:
1. Modified _create_memory() to accept embeddings as either a dict
   (for caching) or a precomputed vector, preventing redundant calls
2. Updated infer=False path to pass embeddings as a dict
3. Added caching for action_text embeddings in infer=True path for
   both ADD and UPDATE operations, since the LLM may rephrase facts
4. Applied same fixes to both sync and async Memory classes
5. Added regression test to verify embedding is called only once

The root cause was that when infer=False, embeddings were passed
directly to _create_memory without a dict wrapper, causing it to
re-embed. When infer=True, if the LLM rephrased extracted facts,
the action_text wouldn't match the cache key, triggering re-embedding.
2026-03-23 14:15:05 +05:30
..
2025-10-15 11:19:52 -07:00