Spaces:
Sleeping
Sleeping
fix(search): resolve KeyError by adding fallback score logic
Browse files
services/search_service.py
CHANGED
|
@@ -94,10 +94,11 @@ class HybridSearchService:
|
|
| 94 |
# 6. Top-K Truncation and Mapping to Pydantic Schema (SearchResultItem) Specification
|
| 95 |
final_results = []
|
| 96 |
for doc in reranked_docs[:top_k]:
|
|
|
|
| 97 |
final_results.append(SearchResultItem(
|
| 98 |
chunk_id=doc["chunk_id"],
|
| 99 |
text=doc["text"],
|
| 100 |
-
score=round(
|
| 101 |
metadata=DocumentMetadata(**doc["metadata"])
|
| 102 |
).model_dump()) # Convert to dict for FastAPI compatibility
|
| 103 |
|
|
|
|
| 94 |
# 6. Top-K Truncation and Mapping to Pydantic Schema (SearchResultItem) Specification
|
| 95 |
final_results = []
|
| 96 |
for doc in reranked_docs[:top_k]:
|
| 97 |
+
display_score = doc.get("rerank_score") if use_reranking else doc.get("rrf_score", 0.0)
|
| 98 |
final_results.append(SearchResultItem(
|
| 99 |
chunk_id=doc["chunk_id"],
|
| 100 |
text=doc["text"],
|
| 101 |
+
score=round(display_score, 4), # Neatly rounded to 4 decimal places
|
| 102 |
metadata=DocumentMetadata(**doc["metadata"])
|
| 103 |
).model_dump()) # Convert to dict for FastAPI compatibility
|
| 104 |
|