RAG Evaluation and ragas

What is RAG Evaluation and ragas?

RAG Evaluation is the systematic process of measuring how well your Retrieval-Augmented Generation pipeline performs. ragas (Retrieval Augmented Generation Assessment) is an open-source framework specifically built for evaluating RAG systems without requiring manual human rating of every answer.

CN: RAG评估是系统性地衡量你的检索增强生成管道表现如何的过程。ragas(检索增强生成评估)是一个专为评估RAG系统而构建的开源框架,无需人工对每个答案进行评分。

ragas Metrics System Explained

The Core Four Metrics

指标 (Metric)衡量什么 (What it measures)需要什么数据 (Data required)
Faithfulness (忠实性)生成的答案是否基于检索到的上下文(有无幻觉)question, contexts, answer
Answer Relevancy (答案相关性)答案与问题的相关程度question, answer
Context Precision (上下文精确度)检索到的内容与问题的相关程度question, contexts
Context Recall (上下文召回率)检索是否找回了所有相关信息question, contexts, ground_truth

Detailed explanation

EN: Faithfulness – Scores from 0.0 to 1.0. Measures whether the generated answer is grounded in the retrieved context. If the LLM says something not in the context, faithfulness drops. This is your primary hallucination detector.

CN: 忠实性 – 得分0.0到1.0。衡量生成的答案是否基于检索到的上下文。 如果LLM说了上下文中没有的内容,忠实性就会下降。这是你主要的幻觉检测器。

EN: Answer Relevancy – Measures how pertinent the generated answer is to the given prompt. Low scores mean the answer is incomplete or contains redundant information.

CN: 答案相关性 – 衡量生成的答案与给定提示的相关程度。低分意味着答案不完整或包含冗余信息。

EN: Context Precision – Measures whether all relevant items retrieved are ranked higher than irrelevant ones. This evaluates your retrieval pipeline’s ranking quality.

CN: 上下文精确度 – 衡量所有检索到的相关项是否排在无关项之前。 这评估你的检索管道的排序质量。

EN: Context Recall – Estimates how many of the relevant chunks were actually retrieved. This evaluates your retrieval pipeline’s coverage.

CN: 上下文召回率 – 估算实际检索到了多少相关块。 这评估你的检索管道的覆盖率。

Key Takeaways

要点 (Key Point)ENCN
ragas是什么ragas is an open-source evaluation framework for RAG systems that uses LLM-as-judgeragas是一个开源的RAG系统评估框架,使用LLM作为评委
四大核心指标The four core metrics are Faithfulness, Answer Relevancy, Context Precision, and Context Recall四大核心指标是:忠实性、答案相关性、上下文精确度、上下文召回率
Faithfulness用途Faithfulness detects hallucinations by checking if answer is grounded in context忠实性通过检查答案是否基于上下文来检测幻觉
Context Precision用途Context Precision measures retrieval ranking quality上下文精确度衡量检索排序质量
Context Recall用途Context Recall measures retrieval coverage (requires ground_truth)上下文召回率衡量检索覆盖率(需要ground_truth)
评估数据格式Evaluation data needs question, contexts (list), answer; ground_truth is optional评估数据需要question、contexts(列表)、answer;ground_truth可选
LLM-as-judgeragas uses an LLM (e.g., gpt-4o) as a judge to score metricsragas使用LLM(如gpt-4o)作为评委来给指标打分
开始简单Start with simple, focused metrics that directly measure your core use case从简单、聚焦的指标开始,直接衡量你的核心用例
Eval First原则Evaluate before and after every change to catch regressions每次改动前后都要评估,以捕捉回归问题

Advanced RAG

What is Advanced RAG?

Advanced RAG (Advanced Retrieval-Augmented Generation) is an evolutionary upgrade over the basic “Naive RAG” pipeline. It adds a suite of optimization techniques at every stage of the RAG workflow — pre-retrieval, retrieval, post-retrieval, and evaluation — to systematically improve retrieval precision, recall, and generation quality.

Naive RAG is like sending a junior intern to the library with a single, vague question, grabbing the first 5 books they find, and copying paragraphs directly. Advanced RAG is like sending a team of expert researchers who:

  • Rephrase the question in 5 different ways (Query Rewrite)
  • Write a fake “perfect answer” first to know exactly what to look for (HyDE)
  • Search both the card catalog AND the full-text index (Hybrid Search)
  • Have a senior editor re-rank the top results (Reranker)
  • Summarize and compress the findings before presenting them (Context Compression)
  • And finally, run a quality check on the entire process (Evaluation)

CN: 朴素 RAG 就像派一个初级实习生去图书馆,带着一个模糊的问题,抓起前5本书,直接抄段落。Advanced RAG 就像派一队专家研究员:

  • 把问题用5种不同方式重新表述(查询重写)
  • 先写一篇“完美的假答案”来明确要找什么(HyDE)
  • 同时搜索卡片目录和全文索引(混合检索)
  • 让高级编辑对结果重新排名(重排序器)
  • 在呈现之前总结和压缩发现(上下文压缩)
  • 最后对整个流程做质量检查(评估)

What does Advanced RAG include?

Layer 1: Chunking Strategies

Chunking 策略

ENCN
Recursive Chunking: Split text by paragraphs/sentences with overlap递归分块:按段落/句子分割,带重叠
Semantic Chunking: Split by semantic boundaries using embedding similarity语义分块:用嵌入相似度按语义边界分割
Parent-Child Retrieval: Retrieve child chunks, return parent chunks for context父子检索:检索子块,返回父块作为上下文

Layer 2:Retrieval Strategies

检索策略

ENCN
Hybrid Search: Combine dense (vector) + sparse (BM25) retrieval混合检索:结合稠密(向量)+ 稀疏(BM25)检索
RRF (Reciprocal Rank Fusion): Merge multi-strategy results by rankRRF(倒数排名融合):按排名位置合并多路结果
Vector DB Selection: Chroma, Pinecone, Milvus, Azure AI Search向量数据库选型:Chroma, Pinecone, Milvus, Azure AI Search

Layer 3: Post-Retrieval Optimization

检索后优化

ENCN
Reranker: Cross-encoder models to re-score retrieved documents重排序器:用交叉编码器模型重新给检索文档打分
Query Rewrite: Rephrase queries for better embedding alignment查询重写:改写查询以更好地对齐嵌入
HyDE: Generate hypothetical answer → embed that → retrieveHyDE:生成假设答案 → 嵌入假设答案 → 检索
Multi-Query Retrieval: Generate multiple query variants, search in parallel多查询检索:生成多个查询变体,并行搜索
Context Compression: Summarize or filter retrieved docs to fit context window上下文压缩:总结或过滤检索文档以适应上下文窗口

Layer 4: Evaluation

评估体系

ENCN
RAG Eval Metrics (ragas): Context Relevancy, Answer Relevancy, FaithfulnessRAG评估指标(ragas):上下文相关性、答案相关性、忠实度
Golden Dataset: Human-annotated Q&A pairs for regression testing黄金数据集:人工标注的问答对,用于回归测试

Advanced RAG differences from Naive RAG

维度ENCN
检索次数Naive: 1 single retrieval call. Advanced: Multiple parallel retrievals + reranking.朴素:单次检索调用。Advanced:多次并行检索 + 重排序。
查询处理Naive: Embed query directly. Advanced: Query Rewrite / HyDE / Multi-Query.朴素:直接嵌入查询。Advanced:查询重写 / HyDE / 多查询。
检索类型Naive: Vector search only. Advanced: Hybrid (Vector + BM25 + RRF).朴素:仅向量搜索。Advanced:混合(向量 + BM25 + RRF)。
排序Naive: Raw similarity scores. Advanced: Cross-encoder reranker (more accurate).朴素:原始相似度分数。Advanced:交叉编码器重排序器(更精确)。
分块Naive: Fixed-size chunking (e.g., 512 tokens). Advanced: Semantic / Parent-Child.朴素:固定大小分块(如512 token)。Advanced:语义 / 父子分块。
上下文窗口利用Naive: Dump all retrieved chunks into prompt. Advanced: Compress / filter / summarize.朴素:把所有检索块塞进提示词。Advanced:压缩 / 过滤 / 总结。
评估Naive: None or manual. Advanced: Automated Eval with ragas + Golden Dataset.朴素:无或手动。Advanced:用 ragas + 黄金数据集自动评估。
失败处理Naive: If retrieval fails, LLM hallucinates. Advanced: Query rewrite retries, multi-query fallback.朴素:检索失败则LLM幻觉。Advanced:查询重写重试、多查询降级。

Example: You’re building a customer support RAG for a cloud provider’s documentation.

阶段Naive RAGAdvanced RAG
用户查询“how fix 503 error”“how fix 503 error”
处理直接嵌入查询Query Rewrite → “how to troubleshoot HTTP 503 service unavailable error”, “503 error resolution steps”
检索向量搜索返回5个块,其中3个是关于”503″但不相关的(如负载均衡器通用文档)混合检索(BM25+向量) + RRF,返回15个候选
重排Cross-encoder reranker 重新打分,选出最相关的3个块
上下文5个块全部塞入(可能超过窗口)Context compression 总结每个块,只保留关键步骤
生成答案可能泛泛而谈答案精确指出: “检查service mesh sidecar, 重启x, 检查Y”