Answer-span hit-rate@k
# grade this stage (from your course directory)
npx theinference test --stage hit-rate --watchImplement the answer-span oracle as a metric. For each question, check whether any retrieved top-k chunk contains the gold answer span (normalized). The mean over all questions is hit-rate@k — the "is the answer even retrievable" gate.
What to build
Implement hitRateAtK
Implement hitRateAtK(retrievedTexts, goldAnswers, k): for each question normalize the gold answer and each of the top-k chunk texts, mark a hit if any normalized chunk text includes the normalized gold span, and return the mean hit fraction. The hit-rate <k> command runs it over the whole QA set.
export function hitRateAtK(
retrievedTexts: string[][], goldAnswers: string[], k: number,
): number {
// hit if some normalize(top-k text).includes(normalize(goldAnswer)); return mean
}
./your_program.sh hit-rate 5
# -> { hitRate } (0.9355 on this corpus)
process mode, stdout_json_match (tight tolerance). Your printed hitRate must equal the frozen reference value exactly. The real-world target is hit-rate@5 >= 0.78; the grade is an exact match to the measured reference (0.9355 here).