For question answering and RAG, answers rarely match the gold answer character for character. The SQuAD metrics normalise text first:
a, an and the as whole words,Then:
Implement normalize_answer, exact_match and f1_score, then score(prediction, gold_answers), which returns the max EM and the max F1 over all gold answers: {"em": ..., "f1": ...}.