An eval harness: exact match, F1 and a second judge
Six questions with known answers are enough to stop judging by eye: exact match, token F1 and two judges that have to agree.
GOLDEN is a reference set: { id, question, expected }, where expected lists the answers that count as right. ANSWERS holds an assistant's answers by id; the one for q6 is missing. We wrote the data for the exercise: it is not a measurement. Write five functions:
normalize(s): lower case, no accents (normalize('NFD')), anything that is not a letter or digit turned into one space, and no spaces at either end.exactMatch(pred, golds):1when the normalised prediction equals any normalised right answer; otherwise0.f1(pred, golds): for each right answer, count the common tokens (each token as many times as it appears in both), work out precision (common / tokens in the prediction), recall (common / tokens in the right answer) and2PR / (P + R); with no common tokens,0. Return the best value.evaluate(golden, answers):{ n, em, f1 }, with the means over all the questions. A missing answer scores0on both. With no questions,{ n: 0, em: 0, f1: 0 }.agreement(a, b):JUDGE_AandJUDGE_Bare the verdicts of two automatic judges on the same answers. Return{ agree, disputed }: the share of ids inaon which they agree, and the sorted list of the ids on which they do not. Those are the ones a person has to look at.
Challenges 0/5
- normalize removes capitals, accents and punctuation
- exactMatch accepts any of the right answers
- f1 gives partial credit and keeps the best right answer
- evaluate averages over every question, the unanswered one included
- agreement says how far two judges agree and which ids to review
function normalize(s) {
// lower case, no accents, anything that is not a letter or digit becomes one space, trimmed
return String(s);
}
function exactMatch(pred, golds) {
// 1 when the normalised prediction equals any normalised gold answer, else 0
return golds.includes(pred) ? 1 : 0;
}
function f1(pred, golds) {
// per gold answer: common tokens, precision, recall, 2PR / (P + R); return the best one
return 0;
}
function evaluate(golden, answers) {
// means over ALL the questions; a missing answer scores 0 on both
return { n: golden.length, em: 0, f1: 0 };
}
function agreement(a, b) {
// agree: share of the ids of a where both verdicts match; disputed: the other ids, sorted
return { agree: 1, disputed: [] };
}
console.log(evaluate(GOLDEN, ANSWERS), agreement(JUDGE_A, JUDGE_B));Tab indents, Ctrl+Z undoes. To leave the editor with the keyboard: Esc, then Tab.
Why this matters
Without a reference set, every change of model, prompt or chunk size is decided by the last answer you happened to see. With twenty questions and these two measures you can already say whether the new version is better or worse. Exact match is harsh on long answers and F1 treats them better, but neither understands synonyms; that is where a judge model comes in, and it makes mistakes too. That is why you use two from different families and review by hand where they disagree. In local RAG with Qdrant and bge-m3, measured we apply the same method to retrieval, with hit@5 and MRR.
Go deeper: the related guide →
This in production, with your data? Let's talk for 15 minutes →