fix: docs RAG query crashes on a non-dict row from the index (#1706)

This commit is contained in:
Afonso Coutinho
2026-06-03 05:35:01 +01:00
committed by GitHub
parent 076607c9b9
commit 86d3af743a
2 changed files with 27 additions and 0 deletions

View File

@@ -57,6 +57,7 @@ class DocsService:
metadata=r.get("metadata"),
)
for r in results
if isinstance(r, dict)
]
async def index(self, directory: str) -> IndexResult:

View File

@@ -0,0 +1,26 @@
import asyncio
from services.docs.service import DocsService
class _FakeRag:
"""Stands in for RAGManager.search. A corrupt or stale Chroma index can
return a non-dict row alongside the well-formed ones."""
def search(self, query, k=5):
return [
{"text": "alpha", "source": "a.txt", "score": 0.9},
"corrupt-row",
None,
]
def test_query_skips_non_dict_rag_rows():
# Bypass __init__ (it builds a real RAGManager / Chroma client) and inject
# a fake search backend.
svc = DocsService.__new__(DocsService)
svc.rag = _FakeRag()
out = asyncio.run(svc.query("anything"))
# old code called r.get(...) on the str/None rows and raised AttributeError.
assert [c.text for c in out] == ["alpha"]
assert out[0].source == "a.txt"