rohitg00/ai-engineering-from-scratch · error · ValueError

no positive weights match the eval names

Error message

no positive weights match the eval names

What it means

The weighted aggregate divided by the total matched weight after filtering the weight dict against the eval names in the results, and no key both matched and carried a positive weight, making the normalised sum undefined.

Solutions

  1. Pass weights whose keys match the metric names actually present in the results
  2. Omit the weights argument to fall back to DEFAULT_WEIGHTS
  3. Ensure every weight value is > 0
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at phases/19-capstone-projects/41-eval-pipeline/code/main.py:662 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/9cd3226ee6a151e0. Report an issue: GitHub.

Appendix: source

Thrown at phases/19-capstone-projects/41-eval-pipeline/code/main.py:662

    aggregate: float
    details: Dict[str, EvalResult] = field(default_factory=dict)

    def to_dict(self) -> Dict[str, Any]:
        return {
            "per_eval": self.per_eval,
            "normalised": self.normalised,
            "weights": self.weights,
            "aggregate": self.aggregate,
            "details": {k: v.to_dict() for k, v in self.details.items()},
        }


def aggregate(results: Sequence[EvalResult], weights: Optional[Dict[str, float]] = None) -> FinalReport:
    weights = dict(weights or DEFAULT_WEIGHTS)
    # Normalise weights so they sum to 1.
    total_w = sum(weights.get(r.name, 0.0) for r in results)
    if total_w <= 0:
        raise ValueError("no positive weights match the eval names")
    norm_weights = {r.name: weights.get(r.name, 0.0) / total_w for r in results}
    per_eval = {r.name: r.metric for r in results}
    normalised = {r.name: normalise_metric(r.name, r.metric) for r in results}
    agg = sum(normalised[name] * norm_weights[name] for name in normalised)
    return FinalReport(
        per_eval=per_eval,
        normalised=normalised,
        weights=norm_weights,
        aggregate=agg,
        details={r.name: r for r in results},
    )


# ---------------------------------------------------------------------------
# Pretty printer
# ---------------------------------------------------------------------------

View on GitHub (pinned to 39ea8a1c6d)