跳到主要内容

评测:不测就不知道改了什么

这一章讲三件事: 为什么必须评测(以及为什么肉眼不行);公开基准和自建评测各管哪一段; 用 ragas 对一条真实管道打分的完整流程,包括那套值得记住的真实数字。 原书一句话立论:改了什么、变好没变好,不测就永远不知道1

1. 评测管两件事

开发期: RAG 管道每个零件都有多个选项(embedding 模型、向量库、检索算法、LLM), 组合起来更是天文数字。系统性地换组合、测结果,才能知道哪套搭配最适合你的任务—— 比如「免费的开源 embedding 到底比付费 API 差多少?差的那点值不值差价?」这类问题, 只有评测能回答2

部署后: 系统会悄悄变坏。原书给了个具体场景:一家财富管理公司的 RAG, 语料是各大机构过去五年的分析报告——突然一场五级飓风登陆,用户问「这场飓风对我持仓明年有什么影响」, 五年语料里根本没这种事。数据的价值随时间衰减,不持续监控就发现不了3

出错时评测还能定位问题出在哪一段:检索器?提示词?还是 LLM 本身?4

2. 第一层:公开基准,只管初选

还没写代码时,可以用公开榜单缩小候选范围。三类零件各有榜单5:

零件榜单测什么
embedding 模型MTEB十几个检索数据集上的平均表现(ArguAna、FiQA2018 金融问答、HotpotQA 多跳、SciFact 科学断言……),可按单项排序
向量搜索ANN-Benchmarks / BEIR搜索精度、速度、内存;BEIR 还做 zero-shot(不给任何示例)跨域评测
LLMArtificial Analysis / Open LLM Leaderboard能力分项 + 吞吐(每秒能处理多少 token)/延迟/价格;开源模型看 ARC、MMLU、GSM8K 等分项

但原书把话说得很清楚:基准只够做初选。它测不到「你的输入、你的输出」的表现; 要真正知道自己的系统好不好,必须自建评测6

3. 第二层:ground truth,评测的地基

ground truth(标准答案集)= 「如果系统处于巅峰状态,理想回答长什么样」的数据。 定义朴实,造起来最难7

原书的例子:做一个「狗狗癌症最新兽医研究」问答系统,语料是 PubMed 的相关论文—— 那 ground truth 就是「目标用户真实会问的问题 + 你心目中的理想答案」,一问一答一组8

四个来源,成本与质量各不同9:

来源做法代价
人工标注(标注即由人逐条给出判断)人工写理想回答质量最高,最贵最慢
领域专家 + 规则模板SME 填模板;例:手机客服模板「To resolve [issue], you can try [solution]」,专家填入「battery drain → 调低亮度、关后台应用」折中
众包MTurk 等平台外包量大,需质控
合成用 LLM 生成问答对最快最便宜,要人工抽查

4. 第三层:ragas,给整条链打分

4.1 它是什么

ragas 是专为 RAG 设计的评测平台。核心能力两个:从你的文档自动合成测试集; 按检索、生成、端到端三段给管道打分。作者用它评测的正是第 05 章留下的那个问题: 同一个语料,dense 检索和 hybrid 检索,到底谁好?10

4.2 先说成本,这是书里少见的醒目警告

ragas 是「LLM 辅助评测」——生成每个测试样本、算每个指标,背后都在调 LLM API,真金白银。 作者的实际账单:10 个样本、6 个指标,跑一轮 2 到 2.5 美元;样本更多则显著上涨。 他的对策:结果立刻存 CSV(一种以逗号分隔的表格文件格式),避免重跑11

4.3 走查:一轮评测从头到尾

  1. 合成测试集: 用生成 LLM 从文档造 10 组问答(实际生成 7 组——合成也会失败,7 组就用 7 组,省钱)12;
  2. 跑两条管道: 同一批问题分别喂给 dense 链与 hybrid 链,收集各自的回答与检索内容;
  3. 打分: 三个层面六个指标,全部落在 0 到 1 之间;

4.4 真实结果

下表是原书跑出的全部数字(相似度检索 vs 混合检索)13:

层面指标densehybrid差值
检索context_precision(检索信噪比)0.9060.841+0.065
检索context_recall(该找到的都找到了吗)0.9500.925+0.025
生成faithfulness(回答忠于检索材料吗)0.9780.946+0.032
生成answer_relevancy(回答切题吗)0.9680.965+0.003
端到端answer_correctness(对照标准答案对不对)0.7760.717+0.059
端到端answer_similarity(与标准答案语义像不像)0.9700.969+0.001

结果:这一局 dense 完胜 hybrid。 这本身就是一堂评测课——第 05 章讲混合检索千好万好, 放到这份数据上一测,六个指标全输。作者的解读保持了克制:测试集和语料都太小, 别过度解读这些数字;这个实验真正示范的是方法论——换组件前先测, 用数字而不是感觉做决策14

顺带把六个指标说人话15:

  • context_precision: 检索回来的东西里,相关的排得靠前吗(信噪比);
  • context_recall: 该找到的相关材料,都找到了吗;
  • faithfulness: 生成的话,是不是都出自检索材料(幻觉的反向指标);
  • answer_relevancy: 回答切题吗,有没有废话冗余;
  • answer_correctness / answer_similarity: 整条链的最终输出对照标准答案,比事实正确度和语义接近度。

这三个层面正好对应管道的分段:检索坏了修检索,生成坏了修生成——混合评测的分段价值就在这。

4.5 没有标准答案时怎么办:reference-free

ragas 联合创始人 Shahul Es 在书里分享了一个关键区分:有参考(reference)指标需要 ground truth 才能算; 无参考(reference-free)指标不需要。部署后的真实流量没有标准答案, 此时 faithfulness(回答是否忠于检索材料)这类无参考指标仍然可用——这让「上线后持续评测」成为可能16

他还给了两条实战经验:合成测试集生成后要人工过一遍,剔掉不像话的问题; 用户反馈分流式(明确出错)与隐式(点赞、重述、放弃),隐式的噪声大但可用17

5. 边界与局限

  • ragas 迭代(即循环着一次次更新版本)极快,「新特性和 API 变更频繁」,以官方文档为准18;
  • 小测试集上的指标差异(±0.03 量级)可能只是噪声——样本要够多才有统计意义,而样本多了钱也多;
  • 人工评测仍是自动指标的补充:语气、连贯性、矛盾检测,自动指标覆盖不了19

6. 可带走的

  1. 不测就不知道改了什么——评测是「换组件」这种决策的唯一依据。
  2. 基准初选 → ground truth 对照 → 全链打分,三层各管一段。
  3. ground truth 四来源:人工/SME 模板/众包/合成,质量和成本互为镜像。
  4. ragas 六指标按检索/生成/端到端分段,坏了知道修哪段。
  5. 那组数字的教训:dense 在自己的数据上赢了 hybrid——别人的结论不能替代你的评测。
  6. 评测本身烧钱(10 样本 6 指标约 2-2.5 美元一轮),结果要落盘复用。
  7. 上线后没有标准答案,用 reference-free 指标继续评(faithfulness 等)。

7. 原文地图

主题原书章原文位置
开发期评测与组件组合Evaluating RAG Quantitatively and with Visualizationstext/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:55(搜「systematically evaluating different combinations」)
飓风例(数据价值衰减)Evaluating RAG Quantitatively and with Visualizationstext/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:79(搜「Category 5 hurricane」)
不测不知道Evaluating RAG Quantitatively and with Visualizationstext/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:94(搜「measure where you are」)
定位错误在哪段Evaluating RAG Quantitatively and with Visualizationstext/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:97(搜「Was it your retrieval mechanism」)
MTEB 与数据集Embedding model benchmarkstext/51-fm-embedding-model-benchmarks.txt:4(搜「Massive Text Embedding Benchmark」)
ANN-Benchmarks/BEIRVector store and vector search benchmarkstext/52-fm-vector-store-and-vector-search-benchmarks.txt:4(搜「ANN-Benchmarks」)
LLM 榜单LLM benchmarkstext/53-fm-llm-benchmarks.txt:4(搜「Artificial Analysis」)
基准只管初选Final thoughts on standardized evaluation frameworkstext/54-fm-final-thoughts-on-standardized-evaluation-framew.txt:7(搜「initial component selection」)
ground truth 定义Final thoughts on standardized evaluation frameworkstext/54-fm-final-thoughts-on-standardized-evaluation-framew.txt:16(搜「ground-truth data is data that represents」)
狗癌症兽医例Final thoughts on standardized evaluation frameworkstext/54-fm-final-thoughts-on-standardized-evaluation-framew.txt:19(搜「veterinarian medicine for dogs」)
人工标注/众包Human annotation · Crowdsourcingtext/57-fm-human-annotation.txt:4(搜「human annotators」) · text/59-fm-crowdsourcing.txt:4(搜「Mechanical Turk」)
SME+规则模板(电池例子)Expert knowledgetext/58-fm-expert-knowledge.txt:7(搜「rule-based generation」) · text/58-fm-expert-knowledge.txt:10(搜「battery drain」)
ragas 定位与实验目的Synthetic ground truthtext/60-fm-synthetic-ground-truth.txt:21(搜「evaluation platform designed specifically for RAG」) · text/60-fm-synthetic-ground-truth.txt:24(搜「hybrid search」)
成本警告Generating the synthetic ground truthtext/62-fm-generating-the-synthetic-ground-truth.txt:11(搜「2 to $2.50」)
10 组只成 7 组Generating the synthetic ground truthtext/62-fm-generating-the-synthetic-ground-truth.txt:59(搜「seven examples」)
检索指标结果Retrieval evaluationtext/64-fm-retrieval-evaluation.txt:12(搜「0.906113」)
信噪比与召回定义Retrieval evaluationtext/64-fm-retrieval-evaluation.txt:26(搜「signal-to-noise ratio」)
与传统 precision/recall 的异同Retrieval evaluationtext/64-fm-retrieval-evaluation.txt:33(搜「conceptually similar」)
别过度解读小数据Retrieval evaluationtext/64-fm-retrieval-evaluation.txt:48(搜「small dataset for our ground truth」)
生成指标结果与定义Generation evaluationtext/65-fm-generation-evaluation.txt:9(搜「0.977500」) · text/65-fm-generation-evaluation.txt:23(搜「factual consistency」)
端到端结果Generation evaluationtext/65-fm-generation-evaluation.txt:44(搜「0.776018」)
组件级补充指标Generation evaluationtext/65-fm-generation-evaluation.txt:84(搜「Context entity recall」)
创始人访谈:合成数据/隐式反馈Ragas founder insightstext/66-fm-ragas-founder-insights.txt:8(搜「Synthetic data generation」) · text/66-fm-ragas-founder-insights.txt:11(搜「Feedback metrics」)
reference-free 与部署评测Ragas founder insightstext/66-fm-ragas-founder-insights.txt:14(搜「reference-free」) · text/66-fm-ragas-founder-insights.txt:17(搜「Deployment evaluation」)
ragas 论文Ragas founder insightstext/66-fm-ragas-founder-insights.txt:14(搜「2309.15217」)
BLEU/ROUGE/语义相似Bilingual Evaluation Understudy (BLEU) 等text/67-fm-bilingual-evaluation-understudy-bleu.txt:4(搜「n-grams」) · text/68-fm-recall-oriented-understudy-for-gisting-evaluatio.txt:4(搜「recall」) · text/69-fm-semantic-similarity.txt:4(搜「cosine similarity」)
人工评测不可替Human evaluationtext/70-fm-human-evaluation.txt:4(搜「human evaluation remains important」)

Footnotes

  1. 出处:「Evaluating RAG Quantitatively and with Visualizations」第 94 段(text/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:94,搜「measure where you are」)。

  2. 出处:「Evaluating RAG Quantitatively and with Visualizations」第 55 段(text/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:55,搜「systematically evaluating different combinations」)与第 58 段(同文件,搜「cloud API service is better」)。

  3. 出处:「Evaluating RAG Quantitatively and with Visualizations」第 76-81 段(text/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:79,搜「Category 5 hurricane」)。

  4. 出处:「Evaluating RAG Quantitatively and with Visualizations」第 97 段(text/50-fm-evaluating-rag-quantitatively-and-with-visualiza.txt:97,搜「Was it your retrieval mechanism」)。

  5. 出处:「Embedding model benchmarks」第 4-57 段(text/51-fm-embedding-model-benchmarks.txt:4,搜「Massive Text Embedding Benchmark」);「Vector store and vector search benchmarks」第 4-11 段(text/52-fm-vector-store-and-vector-search-benchmarks.txt:4,搜「ANN-Benchmarks」);「LLM benchmarks」第 4-33 段(text/53-fm-llm-benchmarks.txt:4,搜「Artificial Analysis」)。

  6. 出处:「Final thoughts on standardized evaluation frameworks」第 7 段(text/54-fm-final-thoughts-on-standardized-evaluation-framew.txt:7,搜「initial component selection」)。

  7. 出处:「Final thoughts on standardized evaluation frameworks」第 16 段(text/54-fm-final-thoughts-on-standardized-evaluation-framew.txt:16,搜「ground-truth data is data that represents」)。

  8. 出处:「Final thoughts on standardized evaluation frameworks」第 19 段(text/54-fm-final-thoughts-on-standardized-evaluation-framew.txt:19,搜「veterinarian medicine for dogs」)。

  9. 出处:「Human annotation」第 4 段(text/57-fm-human-annotation.txt:4,搜「human annotators」);「Expert knowledge」第 7-10 段(text/58-fm-expert-knowledge.txt:7,搜「rule-based generation」);「Crowdsourcing」第 4 段(text/59-fm-crowdsourcing.txt:4,搜「Mechanical Turk」);「Synthetic ground truth」第 4-11 段(text/60-fm-synthetic-ground-truth.txt:4,搜「synthetic ground truth」)。

  10. 出处:「Synthetic ground truth」第 21 段(text/60-fm-synthetic-ground-truth.txt:21,搜「evaluation platform designed specifically for RAG」)与第 24 段(text/60-fm-synthetic-ground-truth.txt:24,搜「hybrid search」)。

  11. 出处:「Generating the synthetic ground truth」第 11 段(text/62-fm-generating-the-synthetic-ground-truth.txt:11,搜「2 to $2.50」)。

  12. 出处:「Generating the synthetic ground truth」第 59 段(text/62-fm-generating-the-synthetic-ground-truth.txt:59,搜「seven examples」)。

  13. 出处:「Retrieval evaluation」第 12 段(text/64-fm-retrieval-evaluation.txt:12,搜「0.906113」);「Generation evaluation」第 9 段(text/65-fm-generation-evaluation.txt:9,搜「0.977500」)与第 44 段(text/65-fm-generation-evaluation.txt:44,搜「0.776018」)。

  14. 出处:「Retrieval evaluation」第 48 段(text/64-fm-retrieval-evaluation.txt:48,搜「small dataset for our ground truth」)与第 50 段(同文件,搜「real-world challenges」)。

  15. 出处:「Retrieval evaluation」第 26-29 段(text/64-fm-retrieval-evaluation.txt:26,搜「signal-to-noise ratio」);「Generation evaluation」第 23-28 段(text/65-fm-generation-evaluation.txt:23,搜「factual consistency」);「Generation evaluation」第 58-64 段(text/65-fm-generation-evaluation.txt:58,搜「factual_correctness」)。

  16. 出处:「Ragas founder insights」第 14 段(text/66-fm-ragas-founder-insights.txt:14,搜「reference-free」)与第 17 段(text/66-fm-ragas-founder-insights.txt:17,搜「Deployment evaluation」)。ragas 论文为 arXiv:2309.15217(原书同段给出链接)。

  17. 出处:「Ragas founder insights」第 8 段(text/66-fm-ragas-founder-insights.txt:8,搜「Synthetic data generation」)与第 11 段(text/66-fm-ragas-founder-insights.txt:11,搜「Feedback metrics」)。

  18. 出处:「Synthetic ground truth」第 27 段(text/60-fm-synthetic-ground-truth.txt:27,搜「highly evolving project」)。

  19. 出处:「Human evaluation」第 4 段(text/70-fm-human-evaluation.txt:4,搜「human evaluation remains important」)。