Skip to content

armgit / mem0

Public Imported from GitHub
0

The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.

fix: Prevent Mock object issues in graph memory tests (#3627)

Ronak Bhalgamieb2f8a37385d
diff --git a/tests/memory/test_kuzu.py b/tests/memory/test_kuzu.py
index 38a1a9ea0..5cb3f2bce 100644
--- a/tests/memory/test_kuzu.py
+++ b/tests/memory/test_kuzu.py
@@ -7,11 +7,25 @@ from mem0.memory.kuzu_memory import MemoryGraph
class TestKuzu:
"""Test that Kuzu memory works correctly"""
+ # Create distinct embeddings that won't match with threshold=0.7
+ # Each embedding is mostly zeros with ones in different positions to ensure low similarity
+ alice_emb = np.zeros(384)
+ alice_emb[0:96] = 1.0
+
+ bob_emb = np.zeros(384)
+ bob_emb[96:192] = 1.0
+
+ charlie_emb = np.zeros(384)
+ charlie_emb[192:288] = 1.0
+
+ dave_emb = np.zeros(384)
+ dave_emb[288:384] = 1.0
+
embeddings = {
- "alice": np.random.uniform(0.0, 0.9, 384).tolist(),
- "bob": np.random.uniform(0.0, 0.9, 384).tolist(),
- "charlie": np.random.uniform(0.0, 0.9, 384).tolist(),
- "dave": np.random.uniform(0.0, 0.9, 384).tolist(),
+ "alice": alice_emb.tolist(),
+ "bob": bob_emb.tolist(),
+ "charlie": charlie_emb.tolist(),
+ "dave": dave_emb.tolist(),
}
@pytest.fixture
@@ -26,6 +40,7 @@ class TestKuzu:
# Mock graph store config
config.graph_store.config.db = ":memory:"
+ config.graph_store.threshold = 0.7
# Mock LLM config
config.llm.provider = "mock_llm"
diff --git a/tests/memory/test_neptune_analytics_memory.py b/tests/memory/test_neptune_analytics_memory.py
index c69f9c115..46d8ec90d 100644
--- a/tests/memory/test_neptune_analytics_memory.py
+++ b/tests/memory/test_neptune_analytics_memory.py
@@ -15,6 +15,7 @@ class TestNeptuneMemory(unittest.TestCase):
self.config = MagicMock()
self.config.graph_store.config.endpoint = "neptune-graph://test-graph"
self.config.graph_store.config.base_label = True
+ self.config.graph_store.threshold = 0.7
self.config.llm.provider = "openai_structured"
self.config.graph_store.llm = None
self.config.graph_store.custom_prompt = None
@@ -298,8 +299,8 @@ class TestNeptuneMemory(unittest.TestCase):
# Verify the method calls
self.assertEqual(self.mock_embedding_model.embed.call_count, 2)
- self.memory_graph._search_source_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.9)
- self.memory_graph._search_destination_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.9)
+ self.memory_graph._search_source_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.7)
+ self.memory_graph._search_destination_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.7)
self.memory_graph._add_entities_cypher.assert_called_once()
self.mock_graph.query.assert_called_once_with(mock_cypher, params=mock_params)
diff --git a/tests/memory/test_neptune_memory.py b/tests/memory/test_neptune_memory.py
index e690ac721..be711164f 100644
--- a/tests/memory/test_neptune_memory.py
+++ b/tests/memory/test_neptune_memory.py
@@ -15,6 +15,7 @@ class TestNeptuneMemory(unittest.TestCase):
self.config = MagicMock()
self.config.graph_store.config.endpoint = "neptune-db://test-graph"
self.config.graph_store.config.base_label = True
+ self.config.graph_store.threshold = 0.7
self.config.llm.provider = "openai_structured"
self.config.graph_store.llm = None
self.config.graph_store.custom_prompt = None
@@ -351,8 +352,8 @@ class TestNeptuneMemory(unittest.TestCase):
# Verify the method calls
self.assertEqual(self.mock_embedding_model.embed.call_count, 2)
- self.memory_graph._search_source_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.9)
- self.memory_graph._search_destination_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.9)
+ self.memory_graph._search_source_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.7)
+ self.memory_graph._search_destination_node.assert_called_once_with(mock_embedding, self.user_id, threshold=0.7)
self.memory_graph._add_entities_cypher.assert_called_once()
self.mock_graph.query.assert_called_once_with(mock_cypher, params=mock_params)