Judge a RAG Answer Without an Answer Key
Score a RAG system's answers with no answer key, the RAGAS way: a model breaks each answer into claims and checks each one against the retrieved context, and judges which retrieved chunks were useful. Implement faithfulness(question, answer, contexts, split, judge), context_precision(question, answer, contexts, judge) and evaluate(rows, split, judge). split(prompt) and judge(prompt) are models; each returns a string.
- Claims. Call
splitonce withCLAIMS_PROMPT(fieldsquestion,answer). The claims are the reply's non-blank lines, stripped. - Support. For each claim, in order, call
judgewithSUPPORT_PROMPT(fieldscontext: the contexts joined with"\n\n", andclaim). - A verdict is yes when the reply's first word, lowercased and with punctuation stripped from its ends, is
yes. Anything else is a no. faithfulnessis the yes count over the claim count.context_precisioncallsjudgeonce per chunk, in order, withUSEFUL_PROMPT(fieldsquestion,answer,chunk). It is the mean of precision@k (useful chunks among the first k, over k) taken over the ranks k whose chunk is useful. No useful chunk gives0.0.evaluatetakes rows of{"question", "answer", "contexts"}and does faithfulness, then context precision, for each. It returns{"rows": [{"faithfulness": f, "context_precision": p}, ...], "faithfulness": mean, "context_precision": mean}.
The catch. An answer with no claims, such as a refusal, is neither faithful nor unfaithful: 0 would punish a system for declining, 1 would reward it for saying nothing. Its faithfulness is None, with no judge call, and a mean skips None instead of counting it as 0. A mean with nothing to average is None.