跪拜 Guibai
← Back to the summary

DeepEval brings assertion gates to RAG evaluation: a two-stage workflow for CI

Many people who run the four RAGAS metrics have the same question: can we build an assertion-based gate? If metrics don't meet the threshold, can we fail the pipeline directly in CI? Can safety items like toxicity, bias, and hallucination be checked separately?

Today I'll use my locally built Agent platform, following the same two-stage approach as the RAGAS evaluation, to fully run through DeepEval.

First, the most important premise: the tested knowledge base has a total of 16 corpus entries, and the evaluation samples reuse the previous rag_samples_20261125.jsonl; DeepEval itself does not retrieve the knowledge base or generate answers; it only reads our exported JSONL samples and performs scoring and judgment.

Real experiment information:

What you'll get from this article:

  1. The complete pipeline for DeepEval knowledge base evaluation: organize knowledge base → collect [question + context + answer] samples → DeepEval performs assertion checks
  2. Clarify boundaries: DeepEval excels at assertion scoring and CI exit gates; it cannot replace retrieval hit@3, nor can it replace Langfuse for trace tracking
  3. Fully reusable commands, metric interpretation, and pitfalls checklist


First, distinguish: what DeepEval can and cannot do

Capability Description
✅ Supported Multi-metric assertion checks, CI non-zero exit code gates; covers answer relevancy, faithfulness, contextual relevancy, hallucination, toxicity, bias, summary quality, etc.
❌ Not supported It cannot call the knowledge base retrieval or generate LLM answers; it cannot replace document-level hit@3 retrieval metrics, nor can it replace Langfuse for seeing the full call trace

To summarize the division of labor with RAGAS: with the same sample, RAGAS leans toward outputting multi-dimensional average scores for observing overall quality; DeepEval leans toward pass/fail assertion gates, and can also extend to safety metric gates.


Step 1: Organize the tested knowledge base and lock the acceptance anchors

After the local platform starts, the tested knowledge base has a fixed 16 documents, divided into 3 categories:

Important reminder: all evaluation conclusions only correspond to the current version of the knowledge base corpus. This is the same tested object as the previous RAGAS and Langfuse articles, which facilitates horizontal comparison.

We first manually ask questions in the chat page to verify that the platform can correctly retrieve the knowledge base and output correct answers, then automate sample collection.


Step 2: Install DeepEval, choose between two judge modes

Working directory: skills-agent

One-click deployment script:

cd skills-agent
bash skills/quality-eval/deepeval-eval/scripts/setup_deepeval.sh
# Or directly pip install
pip install deepeval

There are two options for the judge model. I hit pitfalls here; recommend option 1 first:

  1. OpenAI compatible interface (used this time)

    Set environment: OPENAI_BASE_URL=https://api.deepseek.com/v1, specify model deepseek-chat Advantage: stable output, less likely to get JSON parse exceptions

  2. DEEPEVAL_USE_PLATFORM=1

    The judge reuses the Agent platform's own conversation capability for scoring ⚠️ Pitfall: if the platform model's output format is unstable, it easily throws invalid JSON, increasing debugging cost


Step 3: Collect samples first, then let DeepEval score (core two-stage approach)

Remember this logic:

Sample collection command (reuses the same sampling script as RAGAS, producing the same file):

python3 scripts/rag_collect_samples.py \
  --out output/rag_samples_20261125.jsonl

This time we extract 3 cases with context for testing: product price, API integration, supported models.

Basic scoring command:

python3 skills/quality-eval/deepeval-eval/scripts/run_deepeval.py \
  --samples output/rag_samples_deepeval_kb3.jsonl \
  --metrics answer_relevancy faithfulness \
  --output output/deepeval_kb_20261126.json

Pitfall avoidance: the --golden parameter passes in hardcoded standard answers, which is scripted scoring. Do not use this parameter for real knowledge base testing; the tested system does not actually participate.

CI gate mode (returns non-zero exit code if metrics don't meet threshold, blocks pipeline):

python3 skills/quality-eval/deepeval-eval/scripts/run_deepeval.py \
  --samples output/rag_samples_deepeval_kb3.jsonl \
  --metrics answer_relevancy faithfulness contextual_relevancy \
  --ci

Step 4: How to read metric results? Correct answer ≠ no retrieval problem

Let me be clear first: 0.7 is our business-defined passing line. DeepEval itself has no mandatory passing standard; you can adjust it according to business needs.

Summary of current results:

Metric Plain interpretation Passing line Current mean Judgment Troubleshooting direction
Answer Relevancy Whether the output answer aligns with the user's question ≥0.7 0.83 ✅ Pass —
Faithfulness Whether the answer content can find support in the given context ≥0.7 1.00 ✅ Pass —
Contextual Relevancy The overall quality and relevance of the retrieved context fragments ≥0.7 0.28 ❌ Fail Retrieval noise, chunking strategy issues

Per-item details:

Question Relevancy Faithfulness Interpretation
What is the product pricing system? 0.89 1.00 Knowledge base anchor question, both pass
How to integrate the API? 0.89 1.00 Pass
Which models are supported? 0.73 1.00 Relevancy just passes the line, faithful without hallucination

Three core phrases, don't confuse them:

Key distinction: four capabilities each have their own role, don't mix them up

One more common misconception: don't directly compare DeepEval and RAGAS scores on the same sample. Previously, the same dataset had a RAGAS faithfulness mean of 0.47, while this DeepEval subset had faithfulness 1.00—the scoring formulas, evaluation logic, and evaluation subsets are all different. What we do compare is not the numbers, but whether the metric passes the line and, if it fails, which layer to locate (retrieval layer / generation layer).

Extension: safety metrics can also be gated

Beyond RAG base metrics, DeepEval also supports hallucination, toxicity, bias, and summary quality checks. Previously we ran a round of five safety evaluations, and all passed:

Metric Score Direction (higher is better or lower is better) Judgment
Faithfulness 1.00 Higher is better ✅
Hallucination 0.00 Lower is better ✅
Toxicity 0.00 Lower is better ✅
Bias 0.00 Lower is better ✅
Summary 1.00 Higher is better ✅

Evidence from the chat page (screenshot at the time):

List copy: 平台截图/raw/结果清单-20261005五项.md


Common pitfalls checklist

  1. Platform returns invalid JSON as judge: frequently happens with DEEPEVAL_USE_PLATFORM=1; prefer switching to an OpenAI-compatible judge
  2. Hallucination metric error: sample missing context field will throw a None exception
  3. Summarization evaluation blocked by safety guardrails: replace with non-sensitive test text before running (see 05-summarization-refused.png)
  4. Misusing --golden: becomes static scripted scoring, losing the meaning of evaluating a real knowledge base
  5. Cross-tool score comparison: don't directly compare DeepEval and RAGAS scores

A reusable knowledge base DeepEval evaluation workflow

① Surface the knowledge base → ② Install the engine → ③ Collect samples → ④ Score and interpret

  1. ① Surface the knowledge base: Confirm the knowledge base version, record core anchor information
  2. ② Install the engine: Run the deployment script, verify the judge model can stably output JSON
  3. ③ Collect samples: Use self-built script to call the platform, export JSONL samples
  4. ④ Score and interpret: Run the evaluation script; judge according to thresholds, and if it fails, locate the retrieval side or generation side based on the metric

Reproduction commands:

cd skills-agent
bash skills/quality-eval/deepeval-eval/scripts/setup_deepeval.sh

python3 scripts/rag_collect_samples.py \
  --out output/rag_samples.jsonl

python3 skills/quality-eval/deepeval-eval/scripts/run_deepeval.py \
  --samples output/rag_samples.jsonl \
  --metrics answer_relevancy faithfulness contextual_relevancy \
  --output output/deepeval_report.json

Report copies for this run: 平台截图/raw/deepeval_kb_20261126.json, 平台截图/raw/deepeval_kb_ctx_20261126.json


Summary of this run

On these 3 test samples, answer relevancy and faithfulness passed smoothly, but contextual relevancy seriously failed. This confirms a very realistic problem: the LLM can answer correctly using a small amount of valid information in the context, but the retrieved fragments are mixed with a lot of irrelevant noise.

DeepEval perfectly fills the assertion gate capability that RAGAS lacks, and can be integrated into CI pipelines; together with RAGAS and Langfuse, it forms a complete RAG evaluation solution of "sample collection → quality scoring → trace backtracking".


I'm 测试员周周, transitioning from traditional functional testing to full-stack Agent testing, building my own Agent platform. I'll continue to post practical content on Agent platform implementation, evaluation systems, and pitfall troubleshooting. Follow me and let's exchange ideas on AI testing.