feat: add candidate ranker with confidence gate

This commit is contained in:
Jonathan
2026-07-10 18:31:09 +02:00
parent 3888d2ab8a
commit ffc4d1f483
2 changed files with 57 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
from dataclasses import replace
from lyra_worker.confidence import score_confidence
from lyra_worker.quality import rank_key
from lyra_worker.types import Candidate, MBTarget
def rank_candidates(
target: MBTarget, candidates: list[Candidate], min_confidence: float = 0.7
) -> list[Candidate]:
"""Score, gate by confidence, and sort best-first (quality, then confidence)."""
scored = [replace(c, confidence=score_confidence(target, c)) for c in candidates]
kept = [c for c in scored if c.confidence >= min_confidence]
kept.sort(key=lambda c: (rank_key(c), c.confidence), reverse=True)
return kept