"""Lab 03 practice: rank embeddings and decide when to hand off.

The vectors in the ranking tests are small made-up examples; the scores in the cutoff tests
are recorded text-embedding-3-small results from the chapter's FAQ. Fill in the four TODOs.
"""

from math import sqrt


def cosine(a: list[float], b: list[float]) -> float:
    """Dot product divided by both vector lengths. Return 0 for a zero vector.

    TODO 1: Reject vectors of different lengths with ValueError.
    """
    return 0.0


def rank(query: list[float], entries: list[tuple[str, list[float]]]) -> list[str]:
    """Return labels ordered by cosine similarity, highest first.

    TODO 2: Keep input order when scores tie (Python's sort is stable).
    """
    return []


def gate(score: float, cutoff: float) -> str:
    """TODO 3: Return 'answer' at or above the cutoff, else 'handoff'."""
    return "handoff"


def cutoff_report(cases: list[tuple[float, bool]], cutoff: float) -> dict[str, int]:
    """Each case is (top_score, should_answer). Return
    {"kept": answerable questions at or above the cutoff,
     "stopped": off-topic questions below it,
     "false_handoffs": answerable questions below it}.

    TODO 4
    """
    return {"kept": 0, "stopped": 0, "false_handoffs": 0}
