fix(librarian): map live HybridRAG response fields correctly

The client parsed field names the live library-desk service never
returns, so every result rendered as "unknown (score: 0.00)":

- source_type/sources -> source + sources (icons key off sources values)
- rrf_score -> score
- context -> formatted_context
- related_dossiers are per-result; top level aggregates unique titles
- synonyms live inside the keywords dict as a {term: [synonyms]} map

Also stop sending zero limits (service 422s on limit < 1); disabled
legs now rely on the enable_* flags with limits clamped to >= 1.

Adds a recorded live response as a fixture plus contract tests that
pin the mapping (non-unknown sources, non-zero scores, icon coverage).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-14 10:00:10 +02:00
co-authored by Claude Fable 5
parent 6ec77091b6
commit 59f5b54ac9
5 changed files with 500 additions and 21 deletions
+16 -7
View File
@@ -9,6 +9,18 @@ from src.core.logging_config import get_logger
logger = get_logger(__name__)
# Icons keyed by the values library-desk emits in each result's `sources`
# list (search legs) and `source_type` (result origin).
SOURCE_ICONS = {
"vector": "📄",
"graph": "🔗",
"web": "🌐",
"document": "📑",
"documents": "📑",
"volatile": "⚡",
"wiki": "📄",
}
# ============================================================================
# HybridRAG Search
@@ -76,13 +88,10 @@ async def hybrid_search(
# Add results
for i, result in enumerate(response.results, 1):
source_icon = {
"vector": "📄",
"graph": "🔗",
"web": "🌐",
"document": "📑",
"volatile": "⚡",
}.get(result.source, "•")
source_keys = result.sources or [result.source]
source_icon = "".join(
dict.fromkeys(SOURCE_ICONS.get(key, "•") for key in source_keys)
)
output_parts.append(
f"{i}. {source_icon} **{result.title}** (score: {result.score:.2f})"