Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions services/docs/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ async def query(self, query: str, top_k: int = 5) -> List[DocChunk]:
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)
Expand All @@ -73,8 +76,8 @@ async def index(self, directory: str) -> IndexResult:
"""
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", []),
)

Expand Down
21 changes: 20 additions & 1 deletion tests/test_docs_query_nondict_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]