mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-08-09 10:39:11 +02:00
fix(docs): map live VectorRAG result shapes
This commit is contained in:
parent
42da399b4d
commit
f3d911b58a
2 changed files with 29 additions and 7 deletions
|
|
@ -52,10 +52,13 @@ class DocsService:
|
|||
results = self.rag.search(query, k=top_k)
|
||||
return [
|
||||
DocChunk(
|
||||
text=r.get("text", r.get("content", "")),
|
||||
source=r.get("source", r.get("metadata", {}).get("source", "unknown")),
|
||||
score=r.get("score", 0.0),
|
||||
metadata=r.get("metadata"),
|
||||
text=r.get("document", r.get("text", r.get("content", ""))),
|
||||
source=r.get(
|
||||
"source",
|
||||
(r.get("metadata") or {}).get("source", "unknown"),
|
||||
),
|
||||
score=r.get("similarity", r.get("score", 0.0)),
|
||||
metadata=r.get("metadata") or {},
|
||||
)
|
||||
for r in results
|
||||
if isinstance(r, dict)
|
||||
|
|
@ -73,8 +76,8 @@ class DocsService:
|
|||
"""
|
||||
result = self.rag.index_personal_documents(directory)
|
||||
return IndexResult(
|
||||
indexed=result.get("indexed", 0),
|
||||
failed=result.get("failed", 0),
|
||||
indexed=result.get("indexed_count", result.get("indexed", 0)),
|
||||
failed=result.get("failed_count", result.get("failed", 0)),
|
||||
errors=result.get("errors", []),
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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,15 @@ 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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue