NumPy allowed · plain Python earns 10 bonus points
Cosine-like similarity scores ranked before context assembly
Implement the RAG faithfulness metric: what fraction of a generated answer's claims are actually grounded in retrieved sources.
Implement faithfulness_score(answer_sentences, grounded_flags). Both lists are the same length (one flag per sentence, True meaning that sentence is grounded). Return sum(grounded_flags) / len(answer_sentences). Return 1.0 for an empty answer (vacuously faithful).
faithfulness_score(answer_sentences: list[str], grounded_flags: list[bool]) -> float