fix: data quality query and suppression fallback in recommendation worker

- Fix _DATA_QUALITY_QUERY: remove nonexistent d.source_id/s.source_class,
  use d.source_type directly
- Fix LIMIT 1 applied after jsonb expansion by restructuring as CTE
- Fix fallback build_quality_context_from_summary returning empty
  source_types which always triggered LOW_SOURCE_DIVERSITY suppression
- Update test to reflect corrected fallback behavior
This commit is contained in:
Celes Renata
2026-04-14 06:57:46 +00:00
parent 4fbddc307a
commit b478022ba3
3 changed files with 22 additions and 20 deletions
+3 -2
View File
@@ -107,7 +107,8 @@ def build_quality_context_from_summary(
This is a fallback when full document-level quality metrics aren't
available. It uses the trend summary's evidence counts and confidence
as proxies.
as proxies. We assume at least one source type contributed so that
the fallback does not automatically trigger LOW_SOURCE_DIVERSITY.
"""
total = len(summary.top_supporting_evidence) + len(summary.top_opposing_evidence)
return DataQualityContext(
@@ -116,7 +117,7 @@ def build_quality_context_from_summary(
failed_documents=0,
avg_extraction_confidence=summary.confidence,
newest_evidence_at=summary.generated_at,
source_types=set(),
source_types={"unknown"},
)