概述
RAGAS 是一個計算這些指標的開源框架,主要使用 LLM 作為裁判。獨立的分數之所以重要,是因為它們能顯示出不佳的回答是由於擷取了錯誤的段落,還是由於誤用了正確的段落。
深入探討
A RAG system can fail in two places: retrieval can fetch the wrong passages, or generation can ignore or distort the right ones. A single overall quality score hides which happened, so RAG evaluation splits the pipeline into measurable parts. RAGAS, an open-source framework introduced in a 2023 paper by Es and colleagues, popularized a set of core metrics that cover both halves. Faithfulness asks whether every claim in the answer is supported by the retrieved context; it catches hallucination even when the answer sounds plausible. Answer relevance asks whether the answer actually addresses the question, penalizing evasive or padded replies. Context precision asks whether the retrieved chunks that matter are ranked near the top rather than buried among noise. Context recall asks whether the retrieved context contains everything needed to produce a reference answer, so it requires a ground-truth answer for each test question. Most of these scores are computed by an LLM acting as a judge, broken into small steps. For faithfulness, the judge extracts individual statements from the answer and checks each against the context; the score is the fraction supported. For answer relevance, RAGAS generates questions that the answer would respond to and compares them with the original question using embeddings. Similar ideas appear in other tools, such as the TruLens RAG triad (context relevance, groundedness and answer relevance) and DeepEval. Two misconceptions are common. First, faithful does not mean correct: an answer can faithfully repeat an outdated or wrong document. Second, LLM-judge scores are not ground truth. They vary with the judge model and prompt, so teams spot-check them against human labels and compare systems under identical settings rather than treating a score like 0.85 as an absolute grade.
現實世界的實施
某家銀行的政策助理在上下文召回率上獲得 0.95 分,但在忠實度上為 0.70 分,這告訴團隊檢索功能運作良好,但模型正在新增未受支援的細節,因此他們會調整提示詞而不是重建索引。
某個支援團隊在相同的 200 個問題測試集上比較兩個嵌入模型,並保留上下文召回率與上下文精確度較高的一個。
某家醫院的知識工具會對每日真實問題的樣本進行忠實度評分,並在模式擴散之前,將包含未受支援說詞的回答標記出來供人工審查。
一家新創公司在看到高上下文召回率但低上下文精確度後,加入了一個重排序器(reranker),這意味著正確的段落被檢索到了,但排在不相關的段落後面。
RAG 評估指標與 RAGAS 的未來
RAG 評估正從偶爾的離線報告轉向持續性檢查,在此過程中會對生產環境流量的樣本進行評分,而效能退化則會觸發警報。框架一直在為多輪對話、代理(agents)和工具使用新增指標,且指標定義在不同的程式庫版本之間可能會有所變動,因此鎖定版本對於獲得可比較的結果至關重要。最大的未決問題是裁判的可靠性:LLM 裁判可能會表現出偏見,例如偏好較長的回答,且與人工審查員的一致性會因領域而異。使用小型人工標記集來校準裁判,並將其與確定性檢索指標相搭配,很可能會繼續成為良好的實務做法。
付諸實踐
為什麼這很重要
- 成本與預算. 多年來,架構決策決定著效能和營運成本。
- 更明確的決策. 技術教育幫助團隊選擇正確的堆疊,而不僅僅是最新的堆疊。
- 品質管控. 更好的工程選擇可以減少生產中的可靠性事故。
留意
- 優化一項基準測試可以隱藏更廣泛的系統弱點。
- 基礎設施和維護成本常常被低估。
- 隨著系統變得更加複雜,安全性和可觀察性差距可能會擴大。
後續步驟
- 在實施之前定義延遲、品質和成本目標。
- 在實際負載和資料條件下進行基準測試。
- 儀器監控錯誤、漂移和使用者影響。
- 在擴展之前準備回滾和事件回應路徑。
不斷探索
常見問題
什麼是 RAG 評估指標與 RAGAS?
RAG 評估會分別針對檢索與生成來為檢索增強生成系統評分,最常見的四個指標為:忠實度(faithfulness)、回答相關性(answer relevance)、上下文精確度(context precision)以及上下文召回率(context recall)。RAGAS 是一個計算這些指標的開源框架,主要使用 LLM 作為裁判。獨立的分數之所以重要,是因為它們能顯示出不佳的回答是由於擷取了錯誤的段落,還是由於誤用了正確的段落。
哪个指标检查答案中的每个主张是否得到检索到的上下文的支持?
忠誠度衡量的是由上下文支持的答案主張的比例,其目標是幻覺。
这些指标中的哪一个需要每个测试问题的真实参考答案?
上下文回忆检查检索到的上下文是否包含参考答案所需的内容,因此参考必须存在。
上下文精確度衡量什麼?
上下文精度奖励将有用的块放在排名靠前的位置,而不是将它们埋在不相关的块中。
RAGAS 如何估計答案相關性?
如果答案产生的问题与真实问题相似,则答案符合主题;嵌入可以衡量这种相似性。
系统表现出较高的上下文召回率但较低的上下文精确度。最有可能的修復是什麼?
正在检索正确的块,但排名不佳,这是重新排名器经常解决的排名问题。