Event contract
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. |
| 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
SELECT
pipeline_version,
COUNT(*) AS test_cases,
100.0 * SUM(CASE WHEN relevant_document_retrieved THEN 1 ELSE 0 END)
/ NULLIF(COUNT(*), 0) AS retrieval_relevance_pct,
100.0 * SUM(CASE WHEN answer_grounded THEN 1 ELSE 0 END)
/ NULLIF(COUNT(*), 0) AS grounded_answer_pct,
AVG(retrieval_latency_ms) AS avg_retrieval_latency_ms,
SUM(cost_usd) AS evaluation_cost_usd
FROM rag_evaluation_events
WHERE timestamp_utc >= now() - INTERVAL '30 days'
AND environment = 'evaluation'
GROUP BY pipeline_version
ORDER BY grounded_answer_pct DESC, retrieval_relevance_pct DESC, pipeline_version;This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions against your own data. Read the testing methodology.
Query result
RAG retrieval and grounding outcomes
Version two improves both reviewed rates in the synthetic evaluation set while costing slightly more.
| pipeline_version | test_cases | retrieval_relevance_pct | grounded_answer_pct | avg_retrieval_latency_ms | evaluation_cost_usd |
|---|---|---|---|---|---|
| rag-v2 | 4 | 75 | 75 | 95 | 0.05 |
| rag-v1 | 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 public fixture
The JSON bundle includes the typed event contract, reproducible input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.
How the SQL works
- 1Pipeline version should identify the retriever, index snapshot, reranker, and answer prompt used for the test.
- 2Retrieval relevance and answer grounding remain separate because a good document can still produce an unsupported answer.
- 3Latency and cost keep the quality comparison connected to production constraints.
Edge cases to decide
- 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
- Stacked bars: retrieval_relevance_pct and grounded_answer_pct by version
- 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 setupPut the recipe to work
Related instrumentation and guides
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 real 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.