eval.score_calculator

chunktuner.eval.score_calculator

Weighted scalar score from EvalMetrics for a use case.

ScoreCalculator

ScoreCalculator(
    use_case,
    custom_weights=None,
    *,
    retrieval_scope="document",
)

Weighted sum of EvalMetrics fields for a use-case profile.

retrieval_scope selects which ranking feeds the rank-based keys: with "corpus", mrr reads corpus_mrr and recall_at_1 reads corpus_recall_at_k[1] (missing corpus values count as 0.0). No weight profile references nDCG. token_recall / token_iou / token_precision / duplication_ratio and the length metrics are always document-based: they measure what fits in the context budget for the query's own document, not ranking against distractors.

Source code in src/chunktuner/eval/score_calculator.py
def __init__(
    self,
    use_case: str,
    custom_weights: dict[str, float] | None = None,
    *,
    retrieval_scope: RetrievalScope = "document",
):
    self.use_case = use_case
    self.retrieval_scope: RetrievalScope = retrieval_scope
    self.user_custom_weights: dict[str, float] | None = (
        dict(custom_weights) if custom_weights is not None else None
    )
    self.weights = dict(custom_weights) if custom_weights else score_profile_weights(use_case)
    if custom_weights is not None:
        pos = sum(w for w in self.weights.values() if w > 0)
        if pos <= 0:
            raise ValueError(
                f"custom_weights must contain at least one positive weight; got {self.weights}"
            )

score

score(metrics)

Return a scalar score from weighted metric contributions (missing keys skipped).

Source code in src/chunktuner/eval/score_calculator.py
def score(self, metrics: EvalMetrics) -> float:
    """Return a scalar score from weighted metric contributions (missing keys skipped)."""
    total = 0.0
    for key, w in self.weights.items():
        val = _metric_value(metrics, key, self.retrieval_scope)
        if val is None:
            continue
        total += w * float(val)
    return total