mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-26 18:12:21 +02:00
fix(docs): map live VectorRAG result shapes (#5960)
* fix(docs): map live VectorRAG result shapes * fix(docs): normalize optional VectorRAG fields --------- Co-authored-by: Alexandre Teixeira <alexandremagteixeira@gmail.com>
This commit is contained in:
co-authored by
Alexandre Teixeira
parent
ee252e7cd9
commit
8cb8b074a4
@@ -9,11 +9,18 @@ class _FakeRag:
|
||||
|
||||
def search(self, query, k=5):
|
||||
return [
|
||||
{"text": "alpha", "source": "a.txt", "score": 0.9},
|
||||
{
|
||||
"document": "alpha",
|
||||
"metadata": {"source": "a.txt"},
|
||||
"similarity": 0.9,
|
||||
},
|
||||
"corrupt-row",
|
||||
None,
|
||||
]
|
||||
|
||||
def index_personal_documents(self, directory):
|
||||
return {"indexed_count": 7, "failed_count": 2, "errors": ["bad.pdf"]}
|
||||
|
||||
|
||||
def test_query_skips_non_dict_rag_rows():
|
||||
# Bypass __init__ (it builds a real RAGManager / Chroma client) and inject
|
||||
@@ -24,3 +31,65 @@ def test_query_skips_non_dict_rag_rows():
|
||||
# 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"
|
||||
assert out[0].score == 0.9
|
||||
|
||||
|
||||
def test_index_maps_live_vectorrag_result_shape():
|
||||
svc = DocsService.__new__(DocsService)
|
||||
svc.rag = _FakeRag()
|
||||
|
||||
out = asyncio.run(svc.index("/documents"))
|
||||
|
||||
assert out.indexed == 7
|
||||
assert out.failed == 2
|
||||
assert out.errors == ["bad.pdf"]
|
||||
|
||||
|
||||
def test_query_normalizes_null_canonical_fields_and_malformed_metadata():
|
||||
class _MalformedRag:
|
||||
def search(self, query, k=5):
|
||||
return [
|
||||
{
|
||||
"document": None,
|
||||
"text": "legacy text",
|
||||
"source": None,
|
||||
"similarity": None,
|
||||
"score": 0.4,
|
||||
"metadata": "not-a-dict",
|
||||
},
|
||||
{
|
||||
"document": "canonical zero",
|
||||
"similarity": 0.0,
|
||||
"metadata": {"source": "nested.txt"},
|
||||
},
|
||||
{
|
||||
"document": None,
|
||||
"text": None,
|
||||
"content": "content fallback",
|
||||
"similarity": 0.2,
|
||||
"metadata": ["unexpected"],
|
||||
},
|
||||
]
|
||||
|
||||
svc = DocsService.__new__(DocsService)
|
||||
svc.rag = _MalformedRag()
|
||||
|
||||
out = asyncio.run(svc.query("query"))
|
||||
|
||||
assert [chunk.text for chunk in out] == [
|
||||
"legacy text",
|
||||
"canonical zero",
|
||||
"content fallback",
|
||||
]
|
||||
|
||||
assert out[0].source == "unknown"
|
||||
assert out[0].score == 0.4
|
||||
assert out[0].metadata == {}
|
||||
|
||||
assert out[1].source == "nested.txt"
|
||||
assert out[1].score == 0.0
|
||||
assert out[1].metadata == {"source": "nested.txt"}
|
||||
|
||||
assert out[2].source == "unknown"
|
||||
assert out[2].score == 0.2
|
||||
assert out[2].metadata == {}
|
||||
|
||||
Reference in New Issue
Block a user