feat(oss): accept text in Memory.update(), deprecate data (#6044)

This commit is contained in:
Kartik
2026-07-09 19:32:51 +05:30
committed by GitHub
parent 5dbf071356
commit 99206f0c64
17 changed files with 657 additions and 81 deletions
+22
View File
@@ -190,6 +190,28 @@ class TestAsyncUpdate:
"test_id", "Updated memory", {"Updated memory": [0.1, 0.2, 0.3]}, {}
)
@pytest.mark.asyncio
async def test_async_update_data_is_deprecated_alias_for_text(self, mock_async_memory, mocker, caplog):
mock_async_memory.embedding_model = Mock()
mock_async_memory.embedding_model.embed = Mock(return_value=[0.1, 0.2, 0.3])
mock_async_memory._update_memory = mocker.AsyncMock()
# `data=` still works but emits a deprecation warning
with caplog.at_level(logging.WARNING):
await mock_async_memory.update("test_id", data="via data")
assert any("deprecated" in record.message for record in caplog.records)
mock_async_memory._update_memory.assert_called_once_with(
"test_id", "via data", {"via data": [0.1, 0.2, 0.3]}, None
)
# `text` takes precedence when both are passed
mock_async_memory._update_memory.reset_mock()
await mock_async_memory.update("test_id", text="preferred", data="ignored")
mock_async_memory._update_memory.assert_called_once_with(
"test_id", "preferred", {"preferred": [0.1, 0.2, 0.3]}, None
)
@pytest.mark.asyncio
async def test_async_update_can_change_expiration_date_without_changing_text(self, mock_async_memory, mocker):
mock_async_memory.embedding_model.embed = Mock(return_value=[0.1, 0.2, 0.3])
+19
View File
@@ -1,3 +1,4 @@
import logging
import os
from unittest.mock import Mock, patch
@@ -212,6 +213,24 @@ def test_update_with_empty_metadata(memory_instance):
)
def test_update_data_is_deprecated_alias_for_text(memory_instance, caplog):
memory_instance.embedding_model = Mock()
memory_instance.embedding_model.embed = Mock(return_value=[0.1, 0.2, 0.3])
memory_instance._update_memory = Mock()
# `data=` still works but emits a deprecation warning
with caplog.at_level(logging.WARNING):
memory_instance.update("test_id", data="via data")
assert any("deprecated" in record.message for record in caplog.records)
memory_instance._update_memory.assert_called_once_with("test_id", "via data", {"via data": [0.1, 0.2, 0.3]}, None)
# `text` takes precedence when both are passed
memory_instance._update_memory.reset_mock()
memory_instance.update("test_id", text="preferred", data="ignored")
memory_instance._update_memory.assert_called_once_with("test_id", "preferred", {"preferred": [0.1, 0.2, 0.3]}, None)
@pytest.mark.parametrize(
("expiration_date", "expected_expiration_date"),
[