The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
fix(mongodb): wrap list() return in outer list to match interface contract (#5729)
Hrushikesh Yadavce0531a13e3d
diff --git a/mem0/vector_stores/mongodb.py b/mem0/vector_stores/mongodb.pyindex 5d959c29f..43c61e9f0 100644--- a/mem0/vector_stores/mongodb.py+++ b/mem0/vector_stores/mongodb.py@@ -382,10 +382,10 @@ class MongoDB(VectorStoreBase):cursor = self.collection.find(query).limit(top_k)results = [OutputData(id=str(doc["_id"]), score=None, payload=doc.get("payload")) for doc in cursor]logger.info(f"Retrieved {len(results)} documents from collection '{self.collection_name}'.")- return results+ return [results]except PyMongoError as e:logger.error(f"Error listing documents: {e}")- return []+ return [[]]def reset(self):"""Reset the index by deleting and recreating it."""diff --git a/tests/vector_stores/test_mongodb.py b/tests/vector_stores/test_mongodb.pyindex aea9382b0..5ec96ca55 100644--- a/tests/vector_stores/test_mongodb.py+++ b/tests/vector_stores/test_mongodb.py@@ -322,9 +322,10 @@ def test_list(mongo_vector_fixture):mock_collection.find.assert_called_once_with({})mock_cursor.limit.assert_called_once_with(2)- assert len(results) == 2- assert results[0].id == "id1"- assert results[0].payload == {"key": "value1"}+ assert len(results) == 1+ assert len(results[0]) == 2+ assert results[0][0].id == "id1"+ assert results[0][0].payload == {"key": "value1"}def test_list_with_filters(mongo_vector_fixture):@@ -338,7 +339,7 @@ def test_list_with_filters(mongo_vector_fixture):filters = {"user_id": "alice", "agent_id": "agent1", "run_id": "run1"}results = mongo_vector.list(filters=filters, top_k=2)-+# Verify that the find method was called with the correct queryexpected_query = {"$and": [@@ -349,11 +350,12 @@ def test_list_with_filters(mongo_vector_fixture):}mock_collection.find.assert_called_once_with(expected_query)mock_cursor.limit.assert_called_once_with(2)-+assert len(results) == 1- assert results[0].payload["user_id"] == "alice"- assert results[0].payload["agent_id"] == "agent1"- assert results[0].payload["run_id"] == "run1"+ assert len(results[0]) == 1+ assert results[0][0].payload["user_id"] == "alice"+ assert results[0][0].payload["agent_id"] == "agent1"+ assert results[0][0].payload["run_id"] == "run1"def test_list_with_single_filter(mongo_vector_fixture):@@ -367,7 +369,7 @@ def test_list_with_single_filter(mongo_vector_fixture):filters = {"user_id": "alice"}results = mongo_vector.list(filters=filters, top_k=2)-+# Verify that the find method was called with the correct queryexpected_query = {"$and": [@@ -376,9 +378,10 @@ def test_list_with_single_filter(mongo_vector_fixture):}mock_collection.find.assert_called_once_with(expected_query)mock_cursor.limit.assert_called_once_with(2)-+assert len(results) == 1- assert results[0].payload["user_id"] == "alice"+ assert len(results[0]) == 1+ assert results[0][0].payload["user_id"] == "alice"def test_list_with_no_filters(mongo_vector_fixture):@@ -391,9 +394,10 @@ def test_list_with_no_filters(mongo_vector_fixture):]results = mongo_vector.list(filters=None, top_k=2)-+# Verify that the find method was called with empty querymock_collection.find.assert_called_once_with({})mock_cursor.limit.assert_called_once_with(2)-+assert len(results) == 1+ assert len(results[0]) == 1