Schedule icon
Webhook icon
Script icon
If icon
SlackIncomingWebhook icon
OutputValues icon

Continuous RAG Evaluation and Faithfulness Gate with Ragas

Continuously evaluate RAG pipelines using Ragas. Detect hallucinations, measure context precision, enforce quality gates, and dispatch Slack audit cards.

Categories
AI

Deploying Retrieval-Augmented Generation (RAG) systems into production introduces unique reliability risks: Large Language Models can hallucinate statements unsupported by retrieved context, or vector search engines can return noisy and irrelevant document chunks. When engineers tweak system prompts, adjust chunking strategies, or switch underlying LLMs, manual spot-checking is insufficient to detect regressions across edge cases.

This blueprint automates continuous RAG pipeline evaluation and quality gating orchestrated by Kestra using the open-source Ragas framework. It dynamically accepts custom domain evaluation datasets via file upload (JSON or CSV), evaluates candidate answers against retrieved context chunks across reference-free dimensions (Faithfulness for hallucination detection, and Context Precision for retrieval noise), blocks releases if quality thresholds drop, and sends itemized incident cards to Slack.

How it works

  1. Dynamic Dataset Ingestion: The flow accepts a custom domain dataset file (evaluation_dataset_file) in JSON or CSV format. If omitted, it automatically falls back to a built-in enterprise sample benchmark for zero-setup execution.
  2. Factual Claim Decomposition: Ragas extracts individual factual claims made by the candidate LLM response and tests whether each claim is logically entailed by the retrieved context chunks.
  3. Mathematical Scoring:
    • Faithfulness (0.0 to 1.0): Ratio of claims supported by context over total claims made (detects hallucinations).
    • Context Precision (0.0 to 1.0): Ratio of relevant information chunks retrieved over total chunks fetched (detects vector retrieval noise).
  4. Conditional Quality Gating: An io.kestra.plugin.core.flow.If condition checks if mean_faithfulness < faithfulness_threshold or mean_context_precision < context_relevance_threshold:
    • On Regression (Fail): Sends a Slack alert itemizing the exact question ID, failing score, and the fabricated statements.
    • On Compliance (Pass): Sends a green AI Health Scorecard confirming zero hallucinations.
  5. Typed Downstream Outputs: Exposes evaluation variables (mean_faithfulness, gate_verdict) via OutputValues so upstream CI/CD jobs can automatically approve or block deployment.

What you get

  • Automated Hallucination Prevention: Replaces subjective human review with deterministic claim verification.
  • Reference-Free Evaluation: Evaluates factual accuracy directly against retrieved documentation without requiring labor-intensive human-written reference answers.
  • Custom Domain Flexibility: Any business (fintech, e-commerce, healthcare) can upload its own domain dataset without modifying flow logic.
  • CI/CD Quality Guardrail: Automatically blocks prompt regressions or unfaithful model releases before they reach end users.
  • Retrieval Observability: Identifies whether poor answers stem from LLM generation flaws or vector database retrieval noise.

Custom Evaluation Dataset Format

To benchmark your own domain RAG assistant, upload a .json or .csv file via the evaluation_dataset_file input matching this structure:

JSON Array Format (dataset.json):

[
  {
    "id": "q-101",
    "question": "What is the maximum international wire limit for business accounts?",
    "contexts": [
      "Section 2.1: Daily wire transfers for verified Tier-2 business accounts are capped at $50,000 USD."
    ],
    "answer": "The maximum daily wire transfer limit for verified Tier-2 business accounts is $50,000 USD."
  },
  {
    "id": "q-102",
    "question": "Can customers return opened skincare items?",
    "contexts": [
      "Policy 14: Cosmetics and skincare items may only be returned if unopened and in original packaging within 30 days."
    ],
    "answer": "Opened skincare products cannot be returned under Policy 14."
  }
]

CSV Format (dataset.csv):

The CSV file should contain four column headers: id, question, contexts, answer.

Expected outputs

Downstream CI/CD stages or monitoring dashboards can reference the typed metrics produced by output_ragas_metrics:

Output Variable Description Expression Example
mean_faithfulness Average factual entailment score across evaluated queries {{ outputs.output_ragas_metrics.values.mean_faithfulness }}
mean_context_precision Average vector search relevance score {{ outputs.output_ragas_metrics.values.mean_context_precision }}
hallucinated_samples_count Number of test cases that failed factual verification {{ outputs.output_ragas_metrics.values.hallucinated_samples_count }}
gate_verdict Overall quality decision (PASS or FAIL) {{ outputs.output_ragas_metrics.values.gate_verdict }}
dataset_source Whether a custom upload or built-in benchmark was evaluated {{ outputs.output_ragas_metrics.values.dataset_source }}
duration_seconds Total evaluation batch execution time {{ outputs.output_ragas_metrics.values.duration_seconds }}

Who it's for

  • AI Engineers & LLMOps Teams maintaining production RAG assistants, customer support chatbots, and internal search engines.
  • Data Platform Architects benchmarking vector databases, chunking strategies, and embedding models across business domains.
  • Compliance & AI Governance Officers requiring verifiable audit trails for enterprise AI factual accuracy.

Why orchestrate this with Kestra

Running ad-hoc Python evaluation scripts on developer laptops results in inconsistent benchmarking and missed regressions. Kestra provides:

  • Native File Upload Ingestion: Allows engineers to upload custom test datasets directly through the Kestra UI modal via type: FILE.
  • Containerized Isolation: Packages Ragas, PyTorch, and LangChain dependencies in clean Docker environments without version clashes.
  • Unified Event & Schedule Triggers: Supports nightly scheduled batch sweeps (0 2 * * *) alongside real-time CI/CD pre-deployment webhooks.
  • Enterprise Slack Incident Triage: Instantly notifies engineering teams with execution logs and failing queries when quality gates trip.

Prerequisites

  • An API key for an evaluation judge model (e.g., Google Gemini or OpenAI).
  • An incoming Slack webhook URL for triage alerts and health scorecards.

Secrets

Configure the following secrets in your Kestra namespace or instance settings:

Secret Name Description Example
GEMINI_API_KEY Google Gemini API key used for evaluation judge entailment scoring AIzaSyD-••••••••••••
OPENAI_API_KEY (Optional) OpenAI API key if using GPT-4o-mini as evaluation judge sk-proj-••••••••••••
SLACK_WEBHOOK_URL Incoming webhook URL for destination Slack channel https://hooks.slack.com/services/T00/B00/X00
WEBHOOK_KEY Secret authentication key for CI/CD pre-deployment webhook trigger whk_live_f8a31c920d

Quick start

  1. Import this blueprint into your Kestra instance under the company.ai namespace.
  2. Add your judge API key and Slack webhook URL into Settings > Secrets.
  3. Run the flow manually with the default parameters to inspect the evaluation scorecard on the built-in benchmark dataset.
  4. To evaluate your company's domain queries, click Execute, select your custom dataset.json file in the Custom Evaluation Dataset File picker, and click Run.
  5. Integrate the ci_cd_pre_deploy_webhook URL into your GitHub Actions / GitLab CI pipeline to gate prompt updates.

Common pitfalls & notes

  • JSON Structure: Ensure your uploaded JSON contains an array of objects where contexts is a list of strings representing the retrieved document chunks.
  • Judge Model Selection: Use fast, cost-effective models (such as gemini-2.5-flash or gpt-4o-mini) for evaluation to keep benchmarking latency under 30 seconds.
  • Threshold Calibration: A faithfulness threshold of 0.85 is recommended for general enterprise search. For medical or financial compliance, increase to 0.95.
  • Schedule State: The nightly evaluation schedule is shipped disabled: true by default so it does not trigger until API keys are configured.

How to extend

  • Custom S3 Dataset Ingestion: Add an upstream io.kestra.plugin.aws.s3.Download task to pull production query logs directly from cloud storage.
  • Multi-Metric Expansion: Add answer_relevance and aspect_critic metrics to evaluate conciseness and tone.
  • GitHub Pull Request Bot: Chain a downstream task to post the Ragas evaluation scorecard directly as a GitHub PR comment.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.