Mem0 1.0.0 (#3545)

This commit is contained in:
Parshva Daftari
2025-10-16 15:50:20 +05:30
committed by GitHub
parent 8f5151c344
commit 394203d1b5
77 changed files with 3445 additions and 990 deletions
+15 -11
View File
@@ -62,7 +62,7 @@ def test_search_vectors_with_filters(chromadb_instance, mock_chromadb_client):
results = chromadb_instance.search(query="", vectors=vectors, limit=2, filters=filters)
# Verify that _generate_where_clause was called with the filters
expected_where = {"$and": [{"user_id": "alice"}, {"agent_id": "agent1"}, {"run_id": "run1"}]}
expected_where = {"$and": [{"user_id": {"$eq": "alice"}}, {"agent_id": {"$eq": "agent1"}}, {"run_id": {"$eq": "run1"}}]}
chromadb_instance.collection.query.assert_called_once_with(
query_embeddings=vectors, where=expected_where, n_results=2
)
@@ -87,9 +87,10 @@ def test_search_vectors_with_single_filter(chromadb_instance, mock_chromadb_clie
filters = {"user_id": "alice"}
results = chromadb_instance.search(query="", vectors=vectors, limit=2, filters=filters)
# Verify that single filter is passed as-is (no $and wrapper)
# Verify that single filter is passed with $eq operator
expected_where = {"user_id": {"$eq": "alice"}}
chromadb_instance.collection.query.assert_called_once_with(
query_embeddings=vectors, where=filters, n_results=2
query_embeddings=vectors, where=expected_where, n_results=2
)
assert len(results) == 1
@@ -182,7 +183,7 @@ def test_list_vectors_with_filters(chromadb_instance):
results = chromadb_instance.list(filters=filters, limit=2)
# Verify that _generate_where_clause was called with the filters
expected_where = {"$and": [{"user_id": "alice"}, {"agent_id": "agent1"}, {"run_id": "run1"}]}
expected_where = {"$and": [{"user_id": {"$eq": "alice"}}, {"agent_id": {"$eq": "agent1"}}, {"run_id": {"$eq": "run1"}}]}
chromadb_instance.collection.get.assert_called_once_with(where=expected_where, limit=2)
assert len(results[0]) == 1
@@ -203,8 +204,9 @@ def test_list_vectors_with_single_filter(chromadb_instance):
filters = {"user_id": "alice"}
results = chromadb_instance.list(filters=filters, limit=2)
# Verify that single filter is passed as-is (no $and wrapper)
chromadb_instance.collection.get.assert_called_once_with(where=filters, limit=2)
# Verify that single filter is passed with $eq operator
expected_where = {"user_id": {"$eq": "alice"}}
chromadb_instance.collection.get.assert_called_once_with(where=expected_where, limit=2)
assert len(results[0]) == 1
assert results[0][0].payload["user_id"] == "alice"
@@ -215,7 +217,8 @@ def test_generate_where_clause_multiple_filters():
filters = {"user_id": "alice", "agent_id": "agent1", "run_id": "run1"}
result = ChromaDB._generate_where_clause(filters)
expected = {"$and": [{"user_id": "alice"}, {"agent_id": "agent1"}, {"run_id": "run1"}]}
# ChromaDB accepts filters in {"$and": [{"field": {"$eq": "value"}}, ...]} format
expected = {"$and": [{"user_id": {"$eq": "alice"}}, {"agent_id": {"$eq": "agent1"}}, {"run_id": {"$eq": "run1"}}]}
assert result == expected
@@ -224,8 +227,9 @@ def test_generate_where_clause_single_filter():
filters = {"user_id": "alice"}
result = ChromaDB._generate_where_clause(filters)
# Single filter should be returned as-is
assert result == filters
# ChromaDB accepts single filters in {"field": {"$eq": "value"}} format
expected = {"user_id": {"$eq": "alice"}}
assert result == expected
def test_generate_where_clause_no_filters():
@@ -242,6 +246,6 @@ def test_generate_where_clause_non_string_values():
filters = {"user_id": "alice", "count": 5, "active": True}
result = ChromaDB._generate_where_clause(filters)
# Only string values should be included in $and array
expected = {"$and": [{"user_id": "alice"}]}
# ChromaDB accepts non-string values in filters
expected = {"$and": [{"user_id": {"$eq": "alice"}}, {"count": {"$eq": 5}}, {"active": {"$eq": True}}]}
assert result == expected
+2 -3
View File
@@ -4,7 +4,6 @@ import unittest
from unittest.mock import MagicMock, patch
import dotenv
import pytest
try:
from opensearchpy import AWSV4SignerAuth, OpenSearch
@@ -102,10 +101,12 @@ class TestOpenSearchDB(unittest.TestCase):
self.client_mock.indices.create = MagicMock()
self.client_mock.indices.delete = MagicMock()
self.client_mock.indices.get_alias = MagicMock()
self.client_mock.indices.refresh = MagicMock()
self.client_mock.get = MagicMock()
self.client_mock.update = MagicMock()
self.client_mock.delete = MagicMock()
self.client_mock.search = MagicMock()
self.client_mock.index = MagicMock(return_value={"_id": "doc1"})
patcher = patch("mem0.vector_stores.opensearch.OpenSearch", return_value=self.client_mock)
self.mock_os = patcher.start()
@@ -148,7 +149,6 @@ class TestOpenSearchDB(unittest.TestCase):
self.os_db.create_index()
self.client_mock.indices.create.assert_not_called()
@pytest.mark.skip(reason="This test is not working as expected")
def test_insert(self):
vectors = [[0.1] * 1536, [0.2] * 1536]
payloads = [{"key1": "value1"}, {"key2": "value2"}]
@@ -183,7 +183,6 @@ class TestOpenSearchDB(unittest.TestCase):
self.assertEqual(results[1].id, "id2")
self.assertEqual(results[1].payload, payloads[1])
@pytest.mark.skip(reason="This test is not working as expected")
def test_get(self):
mock_response = {"hits": {"hits": [{"_id": "doc1", "_source": {"id": "id1", "payload": {"key1": "value1"}}}]}}
self.client_mock.search.return_value = mock_response