Event schema
Fields the query expects
| Field | Type | Why it exists |
|---|---|---|
| timestamp_utc | Timestamp | Evaluation completion time in UTC. |
| pipeline_version | Utf8 | Versioned retriever, index, and prompt configuration. |
| test_case_id | Utf8 | Stable evaluation-case identifier. |
| evaluation_run_id | Utf8 | One comparison run shared across the candidate pipelines. |
| dataset_version | Utf8 | Frozen evaluation dataset version. |
| evaluator_version | Utf8 | Versioned grader, rubric, and threshold configuration. |
| relevant_document_retrieved | Boolean | Reviewed retrieval relevance outcome. |
| answer_grounded | Boolean | Reviewed grounded-answer outcome. |
| retrieval_latency_ms | Int64 | Retrieval-stage latency in milliseconds. |
| cost_usd | Float64 | Versioned estimated evaluation cost in USD. |
| environment | Utf8 | Evaluation or production environment. |
Copy the query
WITH cases AS (
SELECT
pipeline_version,
test_case_id,
COUNT(*) AS records,
MAX(CASE WHEN relevant_document_retrieved THEN 1
WHEN relevant_document_retrieved = false THEN 0 END) AS retrieved,
MAX(CASE WHEN answer_grounded THEN 1
WHEN answer_grounded = false THEN 0 END) AS grounded,
MAX(retrieval_latency_ms) AS retrieval_latency_ms,
MAX(cost_usd) AS cost_usd
FROM rag_evaluation_events
WHERE timestamp_utc >= now() - INTERVAL '30 days'
AND environment = 'evaluation'
AND evaluation_run_id = 'release-check-001'
AND dataset_version = 'faq-v1'
AND evaluator_version = 'grounding-rubric-v1'
AND pipeline_version IS NOT NULL AND pipeline_version <> ''
AND test_case_id IS NOT NULL AND test_case_id <> ''
GROUP BY pipeline_version, test_case_id
)
SELECT
pipeline_version,
SUM(CASE WHEN records = 1 THEN 1 ELSE 0 END) AS test_cases,
SUM(CASE WHEN records > 1 THEN 1 ELSE 0 END) AS conflicting_test_cases,
COUNT(CASE WHEN records = 1 THEN retrieved END) AS retrieval_reviewed_cases,
COUNT(CASE WHEN records = 1 THEN grounded END) AS grounding_reviewed_cases,
100.0 * SUM(CASE WHEN records = 1 THEN retrieved END)
/ NULLIF(COUNT(CASE WHEN records = 1 THEN retrieved END), 0) AS retrieval_relevance_pct,
100.0 * SUM(CASE WHEN records = 1 THEN grounded END)
/ NULLIF(COUNT(CASE WHEN records = 1 THEN grounded END), 0) AS grounded_answer_pct,
AVG(CASE WHEN records = 1 THEN retrieval_latency_ms END) AS avg_retrieval_latency_ms,
SUM(CASE WHEN records = 1 THEN cost_usd END) AS evaluation_cost_usd
FROM cases
GROUP BY pipeline_version
ORDER BY grounded_answer_pct DESC NULLS LAST,
retrieval_relevance_pct DESC NULLS LAST, pipeline_version;This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. We review the synthetic sample output separately. Check field types, thresholds, and counting rules against your own data. Read the testing methodology.
Query result
Grounded-answer rate by pipeline
Bars show grounded-answer rates only. The table reports retrieval relevance and each reviewed-case denominator separately.
| pipeline_version | test_cases | conflicting_test_cases | retrieval_reviewed_cases | grounding_reviewed_cases | retrieval_relevance_pct | grounded_answer_pct | avg_retrieval_latency_ms | evaluation_cost_usd |
|---|---|---|---|---|---|---|---|---|
| rag-v2 | 4 | 0 | 4 | 4 | 75 | 75 | 95 | 0.05 |
| rag-v1 | 4 | 0 | 4 | 4 | 50 | 50 | 120 | 0.04 |
Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.
Reproduce the example
Download the sample data
The JSON bundle includes the event schema with field types, reproducible input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.
How the SQL works
- 1Replace the run, dataset, and evaluator filters with one frozen comparison. Keep prompts and answers in the evaluation system.
- 2Only one terminal record per pipeline and case is counted. Conflicting cases are reported and excluded from rates, latency, and cost.
- 3Null reviews remain unknown. Each quality rate uses its own reviewed-case denominator; missing cases require a separate comparison with the planned test set.
- 4Pipeline version should identify the retriever, index snapshot, reranker, and answer prompt used for the test.
- 5Retrieval relevance and answer grounding remain separate because a good document can still produce an unsupported answer.
- 6Latency and cost keep the quality comparison connected to production constraints.
Edge cases to check
- A run must use the same frozen case list and grader configuration across pipelines. Different grader versions measure different things.
- The linked rag_retrieval_evaluated schema is a different contract. Add the fields listed above before using this query. Its duration_ms is end-to-end time, not retrieval_latency_ms; retrieval_score needs an explicit relevance rubric before becoming a Boolean review.
- Investigate conflicting_test_cases before a release decision. Missing identifiers are excluded; no result row does not mean a zero failure rate.
- Latency and cost cover only nonconflicting records with those values present, not necessarily the complete run.
- Use the same versioned test cases across pipelines and report newly added or removed cases.
- Human and model-based graders need documented rubrics, calibration, and disagreement review.
- Do not store private source passages or raw answers in general telemetry by default.
Recommended dashboard
- Bar chart: grounded_answer_pct by pipeline, with retrieval relevance and reviewed counts in the table
- Trend: evaluation outcomes as the test set changes
- Table: latency, cost, test count, and grader version
Alert guidance
Use an evaluation release gate with minimum test count and reviewed regression tolerance rather than a production paging alert.
Read alert setupSet up the events this query needs
Related instrumentation and guides
Define the source data
Event schemas for this analysis
Continue the analysis
Calculate LLM cost by feature and model
Attribute model spend, tokens, request volume, and cost per request to product features.
Open recipeMeasure accepted AI outputs per dollar
Connect model spend to accepted, saved, or otherwise useful product outcomes.
Open recipeMeasure LLM cache savings and retry cost
Compare cached requests, retry volume, and estimated spend by model to find avoidable AI cost.
Open recipeRun it on your events
Create a table, adapt the fields, and save the result
Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.