test: add regression tests for Redis vector store update() embedding corruption fix

This commit is contained in:
kartik-mem0
2026-03-20 14:44:48 +05:30
parent 269394d72d
commit e92021f688
@@ -7,24 +7,27 @@ when vector is None.
""" """
from datetime import datetime from datetime import datetime
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock
import numpy as np import numpy as np
import pytz import pytz
@patch("mem0.vector_stores.redis.SearchIndex") def _make_redis_db():
@patch("mem0.vector_stores.redis.redis.from_url") """Create a RedisDB instance with mocked internals, bypassing __init__
def test_update_with_none_vector_preserves_embedding(mock_redis, mock_search_index): to avoid the redis module name collision with mem0.vector_stores.redis."""
"""update() with vector=None should not include embedding in the data."""
mock_index = MagicMock()
mock_search_index.return_value = mock_index
from mem0.vector_stores.redis import RedisDB from mem0.vector_stores.redis import RedisDB
db = RedisDB.__new__(RedisDB) db = RedisDB.__new__(RedisDB)
mock_index = MagicMock()
db.index = mock_index db.index = mock_index
db.schema = {"index": {"prefix": "mem0:test"}} db.schema = {"index": {"prefix": "mem0:test"}}
return db, mock_index
def test_update_with_none_vector_preserves_embedding():
"""update() with vector=None should not include embedding in the data."""
db, mock_index = _make_redis_db()
payload = { payload = {
"hash": "test_hash", "hash": "test_hash",
@@ -45,18 +48,9 @@ def test_update_with_none_vector_preserves_embedding(mock_redis, mock_search_ind
assert data_dict["memory_id"] == "test_id" assert data_dict["memory_id"] == "test_id"
@patch("mem0.vector_stores.redis.SearchIndex") def test_update_with_vector_includes_embedding():
@patch("mem0.vector_stores.redis.redis.from_url")
def test_update_with_vector_includes_embedding(mock_redis, mock_search_index):
"""update() with a real vector should include embedding in the data.""" """update() with a real vector should include embedding in the data."""
mock_index = MagicMock() db, mock_index = _make_redis_db()
mock_search_index.return_value = mock_index
from mem0.vector_stores.redis import RedisDB
db = RedisDB.__new__(RedisDB)
db.index = mock_index
db.schema = {"index": {"prefix": "mem0:test"}}
vector = np.random.rand(1536).tolist() vector = np.random.rand(1536).tolist()
payload = { payload = {