跪拜 Guibai
← All articles
Artificial Intelligence

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

By 测试员周周 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

A single RAG score hides the real failure point: even when the answer is correct, retrieval can be polluted with noise, and without a CI gate that noise ships undetected. DeepEval turns evaluation into a hard check that fails the build at the right layer, giving teams a concrete way to enforce RAG quality beyond dashboards.

Summary

Running RAGAS four metrics and averaging the scores leaves a gap: no hard gate to fail a build when quality drops. DeepEval fills that gap by reading pre-collected JSONL samples (question, context, answer) and returning non-zero exit codes when assertions violate a threshold. It does not touch the retrieval system or generate answers, so it composes cleanly with existing pipelines.

A real experiment on a 16-document knowledge base with three test cases shows the value of separating generation quality from retrieval quality. Answer relevancy averaged 0.83 and faithfulness 1.00, both passing a 0.7 gate, but contextual relevancy scored only 0.28. That means the model answered correctly using a few relevant chunks buried in noisy retrieval, which a single answer-focused metric would miss. DeepEval identifies the failure layer, steering debugging toward retrieval and chunking rather than the LLM.

The workflow is two-stage: first collect samples with a self-built script that calls the platform's retrieval and Q&A, then run DeepEval with metrics like answer relevancy, faithfulness, and contextual relevancy under a --ci flag. The article also distinguishes DeepEval from hit@3, RAGAS, and Langfuse, and warns against comparing scores across tools because formulas and subsets differ. A pitfall list includes avoiding --golden for real knowledge bases, handling JSON parse errors from platform judges, and ensuring samples carry a context field for hallucination checks.

Takeaways
— DeepEval only scores pre-collected JSONL samples; it does not retrieve from a knowledge base or generate answers.
— It supports assertion metrics including answer relevancy, faithfulness, contextual relevancy, hallucination, toxicity, bias, and summary quality, with non-zero exit codes for CI blocking.
— In the test, answer relevancy averaged 0.83 (pass), faithfulness 1.00 (pass), and contextual relevancy 0.28 (fail) against a 0.7 threshold.
— The two-stage workflow is: collect samples with a custom script, then run DeepEval with --ci to gate on assertions.
— The --golden parameter turns evaluation into scripted scoring and should not be used for real knowledge base testing.
— Do not directly compare DeepEval and RAGAS scores because scoring formulas and evaluation subsets differ.
— A low contextual relevancy score points to retrieval noise or chunking issues, not a problem with the scoring engine.
Conclusions

A correct answer can mask a broken retrieval pipeline: the model only needs a few relevant chunks among many noisy ones, so answer relevancy alone is insufficient as a quality gate.

DeepEval and RAGAS measure different things; using the same sample for both produces incomparable numbers, so teams must define gates per metric rather than compare raw scores.

The --golden pitfall highlights a common evaluation trap: hardcoding expected answers validates nothing about the actual system, turning the test into a static exercise that misses regressions.

Concepts & terms
Assertion gate
A pass/fail check on evaluation metrics that returns a non-zero exit code when a threshold is not met, allowing CI pipelines to block a release or build automatically.
Contextual relevancy
A metric that measures how relevant the retrieved context fragments are to the user's question; a low score indicates noisy retrieval or poor chunking even if the final answer is correct.
hit@3
A document-level retrieval metric that checks whether the correct document appears in the top 3 retrieved results, independent of generation quality.
Langfuse
A tracing tool that records the full call sequence of an LLM application, used to backtrack through retrieval and generation steps when failures occur.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗