资源 · 09
RAG 质量:使用证据评估知识助手
分别衡量语料库、检索、引用、答案、弃权和偏差,以便了解真正需要改进的地方。
已更新 · 15 min
本指南有助于实现的目标
- 确定失败是源于语料库、检索还是模型
- 追踪每一条引用
- 奖励适当的弃权
- 检测变更后的偏差
快速检查
- 参考来源是否已获得授权且为最新版本?
- 正确的段落是否出现在顶部附近?
- 每个决定性论断都有依据吗?
- 助手能否表示不知道?
- 敏感案例是否已升级?
分步指南
- 1
定义有用的任务
收集真实问题、其变体以及预期的业务结果。 添加歧义、来源冲突、过期文档和超出范围的请求。
交付成果:案例和风险分类。
- 2
清理语料库
为每个来源分配所有者、权限、有效期和状态。 删除重复项、孤立片段和来源不明的文档。
交付成果:语料库注册表。
- 3
评估检索效果。
在评估最终措辞之前,衡量是否已找到并排序必要的段落。 检查不存在证据的查询。
交付成果:覆盖率和相关性指标。
- 4
评估答案和引用。
检查对原文的忠实度、完整性、局限性、引用与论点之间的关系以及标记矛盾的能力。
交付成果:忠实度和实用性评价标准。
- 5
测试拒绝和攻击。
添加间接注入、禁止的数据请求、恶意来源、虚假优先级文档和不可逆操作。 定义人工升级机制。
交付成果:安全结果和防护措施。
- 6
监控变更。
对语料库、索引、设置、模型和指令进行版本控制。 每次更改后都重放稳定集,并分析真实反馈,不保留不必要的数据。
交付成果:漂移仪表板和审查流程。
理解、计算与判断
AI回答:区分质量、覆盖率与拒答
分别统计测试问题数、生成回答数和通过验证的回答数。这是CIE的教学计算框架,不是NIST评分,也不设定通用的准入阈值。
这里只输入预期应该得到回答的问题。测试前定义验证标准:答案正确、引用段落确实支持主张、访问经过授权、来源足够新。对预期拒答、来源矛盾和严重错误应另行评估。
指标与证据
| 指标 | 含义 | 所需证据 |
|---|---|---|
| 测试问题 | 预期应该得到回答的问题集合 | 问题、标准与固定的版本 |
| 生成回答 | 得到回答的问题 | 保存的回答文本与拒答记录 |
| 通过验证的回答 | 满足既定标准的回答 | 判定与支持性段落 |
虚构示例
虚构示例:100个问题,80个回答,72个通过验证。回答质量为90%,覆盖率为80%,全体问题成功率为72%。只展示90%会掩盖20个未回答问题和8个未通过验证的回答。
- 72 / 100 · 通过验证
- 8 / 100 · 未通过验证
- 20 / 100 · 未回答
100 = 72 + 8 + 20。未回答的问题仍然可见;这些不是本网站的测量数据。
计算规则
质量 = 通过验证 / 生成回答。覆盖率 = 生成回答 / 测试问题。成功率 = 通过验证 / 测试问题。分母为零时无法计算比例。
虚构示例
示例情境
内部助手根据一些已过期的程序进行回答。 测试集包含常规、模糊和无法回答的问题;每个引用都会与文档版本进行核对。
决策及预期证据
发布会等待,直到排除过期的来源、拒绝不支持的答案并确定语料库所有者。
管理指标
| 指标 | 衡量内容 | 首要行动 |
|---|---|---|
| 检索覆盖率 | 找到所需段落的问题 | 在模型运行前修复语料库、组块或查询 |
| 忠实度 | 引用来源真正支持的说法 | 屏蔽或重写无依据的答案 |
| 有效的回避 | 正确拒绝或升级无证据的案例 | 调整置信度阈值 |
| 回归 | 同一数据集不同版本之间的质量差异 | 确定导致问题的更改 |
常见错误
- 仅测量写作流畅性
- 混淆检索失败和幻觉
- 使用过于简单的评估集
- 未经比较就更改多个组件
常见问题解答
需要多少个问题?
从涵盖重要风险的具有代表性的版本化数据集开始。 多样性和质量比人为增加数量更重要。
单一的自动化指标就足够了吗?
不够。它能加快分诊速度,但敏感、模糊和领域性案例需要明确的标准和人工审核。
是否应该保留所有对话记录?
不应该。仅保留目的明确、访问权限和期限明确的必要记录。 为了改进,建议优先处理匿名案例。
RAG:访问权限、引用与缓存
此语言版本的详细参考说明以英语提供。
Evaluate an answer alongside its document rights
A relevant citation can support an accurate answer while revealing a forbidden document. RAG evaluation should separate faithfulness, freshness and authorisation of passages actually supplied to the model.
- Annotate permitted documents for each test identity.
- Remove a group and replay an existing conversation and citation.
- Track incorrect answers, missing evidence and out-of-scope exposure separately.
Explore the RAG access matrix and replay cases →
References consulted on · OWASP · LLM08:2025 Vector and Embedding Weaknesses OWASP · API1:2023 Broken Object Level Authorization
AI:验证JSON结果
此语言版本的详细参考说明以英语提供。
A retrieved reference does not prove the extracted value
A RAG system can find the right document and return schema-valid JSON that misstates a field. Separate retrieval, the output contract and passage reconciliation to locate what needs correction.
- Keep an independent reference for decisive fields.
- Test missing values, contradictions and unavailable documents.
- Retain unexecuted checks as such instead of counting them as passes.
Compare the 14 outputs and their reasons →
Sources reviewed on · IETF · RFC 8259 · JSON Schema · Object reference · JSON Schema · Draft 2020-12 validation · Python 3.12 · json decoder · python-jsonschema · Schema validation · OWASP · LLM05:2025 Improper Output Handling
RAG相关性与排序
此语言版本的详细参考说明以英语提供。
A RAG system can retrieve useful documents and still produce an incorrect answer. Retrieval evaluation therefore needs its own questions, relevance judgments and defined reading depth. This dossier explains four ranking measures without confusing them with answer faithfulness, access permissions or guaranteed business outcomes.
Documentary references: Stanford CS276’s evaluation material from the 2019 archive and NIST TREC’s reciprocal-rank definition. The CIE workshop uses binary judgments and one query at a time. RR@k here is truncated at k; MRR is a mean RR across multiple queries and is not computed by this workshop.
Stanford CS276 · Retrieval evaluation · 2019 course archive · PDF pp. 3, 5–6 · consulted 2026-10-23
Four measures, four different questions
| Measure | Workshop calculation | Useful reading | Condition or limitation |
|---|---|---|---|
| Precision@k | Relevant results in the first k / k | Measures the useful proportion in the inspected window. | Unavailable if any judgment is missing in the first k. |
| Recall@k | Relevant results in the first k / R | R is the number of relevant records in the entire small judged corpus. | If R is unknown, publish a value only when it is defined and identical in every possible case. |
| RR@k | 1 / rank of the first relevant result within k | Equals 0 when no relevant record appears in that fully judged window. | An unjudged record before the first relevant result makes that rank uncertain. |
| nDCG@k | DCG@k / IDCG@k | Compares ranking gain with the ideal order at the same k. | Unavailable if the value changes across possible cases or any case has a zero ideal. |
Explicit convention: judgment rᵢ is 0 or 1; DCG@k = Σᵢ₌₁ᵏ rᵢ / log₂(i + 1). With binary relevance, gain 2ʳⁱ − 1 also equals rᵢ. IDCG@k puts min(R, k) relevant records first using the same discount. nDCG@k = DCG@k / IDCG@k when that ideal is defined and nonzero. Keep gain, discount, depth and conventions with any published score.
NIST TREC · Reciprocal rank definition · Repository snapshot 35cf096ba6d5ae08ca4803c056b31ed61a56a6d4 · consulted 2026-10-23
A fictional six-record corpus with declared judgments
Titles and judgments below are created for this exercise. They are neither real search results nor automatic title-based judgments. 1 means relevant, 0 nonrelevant and ? unjudged. Columns Q1–Q5 correspond to the needs displayed in the workshop.
- Q1 · Prepare a restoration test
- Q2 · Authorise a document read
- Q3 · Check a quantum sensor
- Q4 · Restoration test: C judgment missing
- Q5 · Restoration: B unjudged, other records off-topic
| Fictional record | Q1 | Q2 | Q3 | Q4 | Q5 |
|---|---|---|---|---|---|
| A · Restoration procedure | 1 | 0 | 0 | 1 | 1 |
| B · Recovery budget | 1 | 0 | 0 | 1 | ? |
| C · Restoration test log | 1 | 0 | 0 | ? | 0 |
| D · Account and permission guide | 0 | 1 | 0 | 0 | 0 |
| E · Archiving policy | 0 | 0 | 0 | 0 | 0 |
| F · Publication schedule | 0 | 0 | 0 | 0 | 0 |
文档排序练习
Choose a need and enter an ordered list of A–F identifiers separated by commas. Change k to inspect only the first k results. The list may omit documents, but each identifier must be unique and k cannot exceed its length. Calculation stays local without collection, import, transmission, storage or export.
This reader queries no search engine, private corpus or AI model. It measures neither answer truth, correct citation nor permission security. Scores concern declared judgments in this small fictional universe. Do not present an exercise value as a benchmark of your system or a universal deployment threshold.
A–F, no duplicates, separated by commas; ASCII spaces allowed. k is an integer from 1 to 6, no greater than list length.
结果
Unjudged and nonrelevant are different states ↓
| Rank | Fictional record | Judgment | Discount | DCG contribution |
|---|
Unjudged and nonrelevant are different states
| Situation | CIE educational convention |
|---|---|
| Missing judgment within k | Precision may vary. Reciprocal rank remains known if the first relevant record is identified before any unjudged record. |
| Missing judgment elsewhere | R becomes a range of possibilities. Do not assume recall and nDCG are always unknown: a value may remain constant, for example when the order is ideal in every case. |
| No relevant record in a fully judged corpus | Precision@k and RR@k are 0. The reader shows Recall@k and nDCG@k as unavailable for this zero-denominator case. |
| CIE publication rule | Explore every binary assignment of missing judgments, at most 64 for six records. Publish a measure only if it is defined and identical in every assignment. These are possibilities, with no probabilities assigned and no actual imputation. |
Ten explained scenarios, available without JavaScript
K01 · Relevant records first
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q1 | A,B,C,D,E,F | 3 | Precision@3 = 1, Recall@3 = 1, RR@3 = 1 and nDCG@3 = 1 in this fully judged corpus. |
K02 · Relevant records after cutoff
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q1 | D,E,F,A,B,C | 3 | All four measures are 0 at k = 3. Relevant records exist but are placed after the inspected window. |
K03 · First relevant record at rank two
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q1 | D,A,E,B,F,C | 3 | Precision@3 and Recall@3 are 1/3; RR@3 is 1/2. nDCG considers position and the ideal order. |
K04 · Relevant records omitted
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q1 | A,D,E,F | 3 | R remains 3 in the corpus even though B and C are absent from the list. Recall must not use only returned results as its denominator. |
K05 · Duplicate identifier
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q1 | A,A,B | 3 | Input rejected: A must not be counted twice. Correct the ranking rather than inflating the relevant count. |
K06 · Unjudged before the first relevant record
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q4 | C,A,D,E,B,F | 3 | C is unjudged. Precision@3, Recall@3, RR@3 and nDCG@3 are unavailable under the declared conventions. |
K07 · Unjudged after the window
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q4 | A,B,D,E,F,C | 3 | Precision@3 is 2/3 and RR@3 is 1. Recall@3 and nDCG@3 remain unavailable because C’s corpus judgment is missing. |
K08 · Need with no relevant record
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q3 | A,B,C,D,E,F | 3 | Precision@3 and RR@3 are 0. Recall and nDCG remain unavailable; this is an explicit convention rather than division by zero. |
K09 · Change reading depth
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q2 | A,D,B,C,E,F | 1 | At k = 1 no relevant record is visible. At k = 2, D appears: precision 1/2, recall 1 and RR@2 = 1/2. |
K10 · Unknown relevance, always ideal ordering
| Need | Supplied order | k | Expected reading |
|---|---|---|---|
| Q5 | A,B,C,D,E,F | 2 | B may be relevant or not. Either way, all relevant records are within the first two ranks and the order stays ideal: recall, RR and nDCG are 1. Precision remains unknown. |
Prepare a reproducible evaluation
| Suggested check | Record to retain |
|---|---|
| Needs | Representative and unanswerable questions; specify the documentary need behind each wording. |
| Corpus | Document and index versions, accessible scope and deletion or revocation rules. |
| Judgments | Relevance rule, assessors, disagreements and unjudged state; do not equate clicks with documentary truth. |
| Protocol | Same k, filters, data and conventions before and after a retrieval change. |
| Regression | Per-query and per-need-family results, gaining and losing cases, hypothesis and checks on new documents. |
| Final answer | Evaluate faithfulness, citations, useful refusals and permissions separately; better retrieval scores do not validate this stage. |
For a reviewable decision, keep the question, ranking, judgments, k and corpus limitations with the score. One average can conceal a regression on a critical need. Error tracking and answer review remain necessary even when the first records are relevant.
Sources, editions and credits
Original CIE explanations, six documents, five needs, judgments and scenarios. Conceptual references: Stanford CS276 and NIST TREC’s reciprocal-rank definition. No source chart, ranking example or code is reproduced. The CIE program and its unavailable-value conventions are not a complete trec_eval implementation.
Stanford CS276 · Retrieval evaluation · 2019 course archive · PDF pp. 3, 5–6 · consulted 2026-10-23
SHA-256 : be38261a8cdbc95551a502504d0a1c146ea453ffd9712243ea067ac8538c1826
NIST TREC · Reciprocal rank definition · Repository snapshot 35cf096ba6d5ae08ca4803c056b31ed61a56a6d4 · consulted 2026-10-23
SHA-256 : 64159909e6e1e4e9e4dd3c569b119fdc90696d0b03cd902e6a9358dcd6e84677
官方参考文献
参考文献支持该方法。 请根据您的实际情况调整检查;它们并非认证。 原始参考文献标题和源文档可能使用其他语言。
参考资料查阅日期 .
- NIST — AI Risk Management Framework
- NIST — Generative AI Profile
- OWASP · LLM08:2025 Vector and Embedding Weaknesses
- OWASP · API1:2023 Broken Object Level Authorization
- IETF · RFC 8259
- JSON Schema · Object reference
- JSON Schema · Draft 2020-12 validation
- Python 3.12 · json decoder
- python-jsonschema · Schema validation
- OWASP · LLM05:2025 Improper Output Handling
- Stanford CS276 · Retrieval evaluation
- NIST TREC · Reciprocal rank definition
