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

empty metric

Error message

empty metric

What it means

Error "empty metric" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/19-capstone-projects/50-hypothesis-generator/code/main.py:95

    return [v / norm for v in vec]


def cosine_distance(a: list[float], b: list[float]) -> float:
    dot = sum(x * y for x, y in zip(a, b))
    dot = max(-1.0, min(1.0, dot))
    return 1.0 - dot


def parse_response(raw: str) -> dict:
    match = TAG_RE.search(raw)
    if match is None:
        raise ParserError("no hypothesis block found")
    text = match.group("text").strip()
    if not text:
        raise ParserError("empty text")
    metric = match.group("metric").strip()
    if not metric:
        raise ParserError("empty metric")
    raw_vars = match.group("variables").strip()
    variables = [v.strip() for v in raw_vars.split(",") if v.strip()]
    if not variables:
        raise ParserError("empty variables")
    baseline = match.group("baseline")
    baseline_ref = baseline.strip() if baseline and baseline.strip() else None
    return {
        "text": text,
        "variables": variables,
        "metric": metric,
        "baseline_ref": baseline_ref,
    }


def temperature_bucket(temperature: float) -> int:
    """Map a continuous temperature to a discrete bucket index."""
    if temperature < 0.35:
        return 0

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/19-capstone-projects/50-hypothesis-generator/code/main.py:95 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/40d11ed54b6553fe. Report an issue: GitHub.