fix: memory recall crashes on a non-dict row from the vector store (#1705)
This commit is contained in:
@@ -103,6 +103,7 @@ class MemoryService:
|
|||||||
metadata=r.get("metadata", {}),
|
metadata=r.get("metadata", {}),
|
||||||
)
|
)
|
||||||
for r in results
|
for r in results
|
||||||
|
if isinstance(r, dict)
|
||||||
]
|
]
|
||||||
return MemorySearchResult(memories=memories, query=query, total=len(memories))
|
return MemorySearchResult(memories=memories, query=query, total=len(memories))
|
||||||
|
|
||||||
|
|||||||
26
tests/test_memory_recall_nondict_rows.py
Normal file
26
tests/test_memory_recall_nondict_rows.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import asyncio
|
||||||
|
|
||||||
|
from services.memory.service import MemoryService
|
||||||
|
|
||||||
|
|
||||||
|
class _FakeVectorStore:
|
||||||
|
"""Stands in for MemoryVectorStore.search, which reconstructs rows from a
|
||||||
|
vector index + metadata store. A stale or corrupt index can yield a
|
||||||
|
non-dict row mixed in with the good ones."""
|
||||||
|
|
||||||
|
def search(self, query, k=5):
|
||||||
|
return [
|
||||||
|
{"id": "1", "text": "real memory", "timestamp": 5},
|
||||||
|
"corrupt-row",
|
||||||
|
None,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_recall_skips_non_dict_vector_rows(tmp_path):
|
||||||
|
svc = MemoryService(str(tmp_path))
|
||||||
|
svc.vector_store = _FakeVectorStore()
|
||||||
|
res = asyncio.run(svc.recall("anything"))
|
||||||
|
# old code did r.get(...) on the str/None rows and raised AttributeError,
|
||||||
|
# losing the whole recall; now only the well-formed row survives.
|
||||||
|
assert [m.id for m in res.memories] == ["1"]
|
||||||
|
assert res.total == 1
|
||||||
Reference in New Issue
Block a user