generate-rag-dataset
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerate a RAG Evaluation Dataset
生成 RAG 评估数据集
This recipe analyzes your RAG knowledge base and generates a comprehensive Q&A evaluation dataset.
本流程会分析你的 RAG 知识库,并生成一套全面的问答评估数据集。
Step 1: Analyze the Knowledge Base
第 1 步:分析知识库
Read the codebase to find the knowledge base:
- Document files (PDFs, markdown, text files)
- Database schemas (if documents are stored in a DB)
- Vector store configuration (what's being embedded)
- Chunking strategy (how documents are split)
Read every document you can access. Understand:
- What topics does the knowledge base cover?
- What's the depth of information?
- What terminology is used?
- What are the boundaries (what's NOT covered)?
读取代码库以查找知识库:
- 文档文件(PDF、markdown、文本文件)
- 数据库 schema(如果文档存储在 DB 中)
- 向量存储配置(对哪些内容进行嵌入)
- 分块策略(如何拆分文档)
读取所有可访问的文档。了解:
- 知识库涵盖哪些主题?
- 信息深度如何?
- 使用了哪些术语?
- 边界在哪里(哪些内容不在涵盖范围内)?
Step 2: Generate Diverse Question Types
第 2 步:生成多样化的问题类型
Create questions across these categories:
创建以下类别的问题:
Factual Recall
事实召回
Direct questions answerable from a single passage:
- "What is the recommended threshold for X?"
- "When should Y be applied?"
可通过单个段落回答的直接问题:
- “X 的推荐阈值是什么?”
- “Y 应在什么时候应用?”
Multi-Hop Reasoning
多跳推理
Questions requiring information from multiple passages:
- "Given condition A and condition B, what should be done?"
- "How do X and Y interact when Z occurs?"
需要从多个段落获取信息的问题:
- “给定条件 A 和条件 B,应该采取什么措施?”
- “当 Z 发生时,X 和 Y 如何相互作用?”
Comparison
对比
Questions comparing concepts within the knowledge base:
- "What's the difference between approach A and approach B?"
- "When should you use X instead of Y?"
比较知识库中不同概念的问题:
- “方法 A 和方法 B 有什么区别?”
- “何时应使用 X 而不是 Y?”
Edge Cases
边界情况
Questions about boundary conditions or unusual scenarios:
- "What happens if the measurement is outside normal range?"
- "What if two recommendations conflict?"
关于边界条件或异常场景的问题:
- “如果测量值超出正常范围,会发生什么?”
- “如果两条建议相互冲突,该怎么办?”
Negative Cases
负向案例
Questions about topics NOT covered by the knowledge base:
- "Does the system support Z?" (when it doesn't)
- Questions requiring external knowledge the KB doesn't have
These help test that the agent correctly says "I don't know" rather than hallucinating.
关于知识库未涵盖主题的问题:
- “系统是否支持 Z?”(当系统不支持时)
- 需要使用知识库中不存在的外部知识的问题
这些问题有助于测试 Agent 能否正确回答“我不知道”,而不是产生幻觉。
Step 3: Include Context Per Row
第 3 步:为每一行包含上下文
For each Q&A pair, include the relevant document chunk(s) that contain the answer. This enables:
- Platform experiments without the full RAG pipeline
- Evaluating answer quality independent of retrieval quality
- Testing with different prompts using the same retrieved context
Format:
python
{
"input": "When should I irrigate apple orchards?",
"expected_output": "Irrigate to maintain soil moisture between 25-35 kPa...",
"context": "## Irrigation Management\nSoil moisture threshold for apple orchards: maintain between 25-35 kPa...",
"question_type": "factual_recall"
}对于每个问答对,包含包含答案的相关文档块。这可以:
- 无需运行完整的 RAG 流水线即可开展平台实验
- 独立于检索质量评估答案质量
- 使用相同的检索上下文测试不同 prompt
格式:
python
{
"input": "When should I irrigate apple orchards?",
"expected_output": "Irrigate to maintain soil moisture between 25-35 kPa...",
"context": "## Irrigation Management\nSoil moisture threshold for apple orchards: maintain between 25-35 kPa...",
"question_type": "factual_recall"
}Step 4: Export Formats
第 4 步:导出格式
Create both:
同时创建以下两种格式:
Python DataFrame (for SDK experiments)
Python DataFrame(用于 SDK 实验)
python
import pandas as pd
df = pd.DataFrame(dataset)
df.to_csv("rag_evaluation_dataset.csv", index=False)python
import pandas as pd
df = pd.DataFrame(dataset)
df.to_csv("rag_evaluation_dataset.csv", index=False)Platform-Ready CSV
可直接导入的 CSV
Export with columns: , , ,
This can be imported directly into LangWatch platform datasets.
inputexpected_outputcontextquestion_type使用以下列导出:、、、
inputexpected_outputcontextquestion_type可以直接将其导入 LangWatch 平台数据集。
Step 5: Validate Dataset Quality
第 5 步:验证数据集质量
Before using the dataset:
- Check topic coverage: are all knowledge base topics represented?
- Verify answers are actually in the context, with no hallucinated expected outputs
- Check question diversity: not all the same type
- Verify negative cases have appropriate "I don't know" expected outputs
- Run a quick experiment to baseline accuracy
使用数据集前:
- 检查主题覆盖情况:知识库中的所有主题是否都已体现?
- 验证答案确实存在于上下文中,且预期输出没有幻觉。
- 检查问题多样性:是否并非所有问题都属于同一类型。
- 验证负向案例是否具有恰当的“我不知道”预期输出。
- 运行一次快速实验,建立准确率基线。
Common Mistakes
常见错误
- Do NOT generate questions without reading the actual knowledge base first
- Do NOT skip negative cases. Testing "I don't know" is crucial for RAG
- Do NOT use the same question pattern for every entry. Diversify types
- Do NOT forget to include the relevant context per row
- Do NOT generate expected outputs that aren't actually in the knowledge base
- 不要在未先阅读实际知识库的情况下生成问题。
- 不要跳过负向案例。测试“我不知道”对 RAG 至关重要。
- 不要让每个条目都使用相同的问题模式。确保类型多样化。
- 不要忘记为每一行包含相关上下文。
- 不要生成知识库中实际不存在的预期输出。