Vaibhav Mahore

02/ 03Case study

AIRE: AI Reliability & Evaluation Engine

A trace-based evaluation engine that turns LLM/RAG behavior into replayable evidence: deterministic metrics, a failure taxonomy, and a statistical regression gate that runs in CI.

Aug - Oct 2026Solo project - design, implementation, evaluationGitHub repository
  • Python
  • asyncio
  • OpenTelemetry
  • pytest
  • GitHub Actions
  • Docker

Lab/See it run

QUERY01RETRIEVE02RESPOND03TRACE04METRICS05TAXONOMY06REGRESSION07REPORT08150 cases · 130 answerable · 20 unanswerable · dataset SHA-256 stored

QueryA fixed 150-case JSONL suite goes in: 130 answerable questions and 20 unanswerable ones. Every run manifest stores the dataset's SHA-256.

01 / 10

01/Overview

What this is.

AIRE runs a system under test once over a fixed JSONL suite, stores schema-validated traces, and scores the stored traces with deterministic metrics and pluggable judges, never re-running the system. Runs are compared metric by metric with paired significance tests, and every failure lands in one class of a fixed taxonomy.

The core is zero-dependency and reproducible offline: a deterministic RAG stack (keyword retrieval and an extractive responder) produces every committed number. Adapters for Gemini, OpenAI, Anthropic and local OpenAI-compatible servers run through an async runner with its own rate limiter, retries and cache.

02/Problem

What motivated it.

AI systems are easy to build and hard to trust. Outputs are nondeterministic, reference answers are scarce and every call costs money, so most testing happens once, informally, and never again.

The gap this project attacks: make evaluation an artifact, and make the gate trustworthy. Store the evidence, re-score it as metrics change, and call something a regression only when the change is beyond tolerance and a paired test supports it.

03/System

How it is built.

runner/dataset.py
EvalDataset: the fixed 150-case JSONL suite. Every run manifest embeds the dataset's SHA-256, so traces are attributable to an exact suite version.
llm/ + providers/
The SystemUnderTest interface, a deterministic stack (KeywordRetriever with overlap or IDF weighting plus ExtractiveRAG), and adapters for Gemini, OpenAI, Anthropic and a stdlib OpenAI-compatible client, with SDK retries turned off.
providers/client.py + ratelimit.py
ModelClient owns retries: a two-bucket AIMD rate limiter that halves on a 429, full-jitter backoff that honours Retry-After, a quota circuit breaker and an exact-request response cache.
runner/async_runner.py
A worker pool with real cancellation. Harness sleeps (pacing and backoff) happen outside the timed region and are recorded separately, and cache hits are excluded from latency.
tracing/
TraceRecorder and RunStore: traces are streamed to manifest.json plus traces.jsonl and written atomically, so an interrupted run keeps what it finished.
evaluator/
Groundedness, citation precision and recall, Recall@K, MRR and abstention metrics; agent trajectory metrics; rubric and pairwise judges; and stats.py with seeded bootstrap CIs, a paired bootstrap, McNemar's exact test and Holm adjustment.
regression/compare.py + gate.py
Direction-aware comparison with per-case attribution. aire-gate exits 0 on a pass, 1 on a regression and 2 when the inputs are unusable or the gate itself fails.
telemetry/ + report/
OpenTelemetry GenAI span export (OTLP/HTTP and JSON lines), ingestion of foreign OTLP traces, and escaped static HTML diff reports.

04/Approach

The mechanisms that matter.

  • Run once, replay forever

    Traces carry the dataset hash and full invocation records, so new metrics apply to old runs at zero API cost and comparisons never re-invoke the system.

  • Metrics that score what they claim

    An audit found that a citation placed after the period was attached to the next sentence, so verbatim quotes scored 0.5. With that fixed, faithful quoting scores 1.0, and a test asserts it.

  • Recall at a fixed K

    v1 returned one document and v2 three, so recall is now reported at K=1 and K=3. A retrieval ablation at a fixed K shows the v2 gain comes from retrieving three documents, not from IDF weighting.

  • Tolerance plus significance

    A metric regresses only when the change is beyond tolerance and a paired test supports it: McNemar's exact test for pass/fail metrics, a seeded paired bootstrap for continuous ones, Holm-adjusted. Anything else is inconclusive.

  • A gate that cannot be fooled

    Crashed cases score 0 instead of counting as correct abstentions, a metric missing from the candidate counts as a regression, and a gate crash exits 2 instead of looking like a block.

  • Rate limits measured, not guessed

    The runner is benchmarked against a local server that enforces 3000 requests per minute, so throughput and retry behavior are measured numbers.

05/Evaluation

Setup and workloads.

  • Suite: 150 JSONL cases over a 12-document corpus: 130 answerable (16 of them need two documents) and 20 unanswerable, which expect an abstention.
  • Three deterministic RAG versions: v1 overlap retrieval, top 1, faithful quoting; v2 IDF retrieval, top 3; v3 is v2 with a fluent style that merges sentences and drops every citation, a planted regression.
  • Statistics: every mean carries a seeded 95% bootstrap interval, and comparisons pair the two runs case by case (2000 resamples, α = 0.05).
  • Runner benchmark: a local fake server at 3000 requests per minute with 0.1 s service time, 150 cases per configuration.
  • Provider runs are not quoted yet: the first Gemini run stopped early on the free-tier daily quota, and the LLM judge is still being calibrated against reviewed labels.

06/Results

Measured outcomes.

1.0→0.0
groundedness regression blocked by the gate (130 answerable cases)
0.72→0.86
Recall@3, v1 to v2, paired bootstrap p < 0.001
5.4×
runner throughput over sequential, 0 failed cases
381
tests across metrics, statistics, runner and gate
Metricnv1 baselinev2 improvedv3 fluent
Recall@11300.7154[0.64, 0.78]0.7154[0.64, 0.78]0.7154[0.64, 0.78]
Recall@31300.7154[0.64, 0.78]0.8615[0.80, 0.91]0.8615[0.80, 0.91]
MRR@31300.7769[0.70, 0.85]0.8231[0.77, 0.88]0.8231[0.77, 0.88]
Groundedness1301.01.00.0
Gold citation recall1300.7154[0.64, 0.78]0.7154[0.64, 0.78]0.0
Citation precision1301.01.0not measurable
Abstention correct200.00.10.1
Success rate1500.42670.46670.0133
Gate vs v1baselinepass, exit 0blocked on 4 metrics, exit 1

From results/*/eval_results.json and the two comparison JSONs. Means with seeded 95% bootstrap intervals; n is the number of cases each mean averages. v2 vs v1: Recall@3 and MRR@3 improve in the paired bootstrap (Recall@3 p < 0.001); success rate and abstention rise but stay inconclusive (McNemar p = 0.07 and 0.5). v3 vs v1: groundedness, gold citation recall, citation precision (nothing is cited, so it is missing) and success rate regress, with Holm-adjusted p < 0.001 wherever a test applies.

07/Findings

What the results say.

  1. 01

    Fluency destroyed grounding: v3 kept v2's retrieval (Recall@3 0.8615) while groundedness fell from 1.0 to 0.0 on all 130 answerable cases and gold citation recall from 0.7154 to 0.0, with 109 more ungrounded failures. A single composite score would have hidden it.

  2. 02

    The retrieval gain is K, not weighting: at a fixed top 3, plain overlap reaches Recall@3 0.8731 and IDF 0.8615, so v2's lift over v1 comes from retrieving three documents instead of one.

  3. 03

    Not every improvement is significant: v2 raises the success rate from 0.4267 to 0.4667, but McNemar's exact test gives p = 0.07, so the gate reports it as inconclusive instead of claiming a win.

  4. 04

    Abstention is an open gap the evaluator exposed: with IDF weighting the unanswerable questions' top retrieval scores reach 0.4596, and 84 of 130 answerable questions score no higher, so no score threshold separates them.

  5. 05

    The audit changed the baseline itself: the old groundedness baseline came from the citation-placement bug, and faithful quoting now scores 1.0 as it should.

  6. 06

    Rate limits are absorbed, not suffered: a client asking for twice the server's limit hit 18 rate-limit responses and still finished all 150 cases with 0 failures.

08/Decisions

Why it was built this way.

  • Replay economics

    Run once, store traces, evaluate forever: new metrics apply to old runs at zero API cost, and comparisons never re-invoke the system.

  • A deterministic SUT exists

    Every committed number is reproducible offline, and evaluator bugs surface as metric changes instead of LLM noise.

  • Tolerance plus significance

    A change must exceed an absolute tolerance (0.02 for scores) and pass a paired test before it is a regression, so one flipped case in 150 cannot fail a build.

  • One owner for retries

    ModelClient is the only retry layer and provider SDK retries are off, so the limiter sees every 429 instead of two layers multiplying attempts.

  • No evaluation framework

    Not building on DeepEval or Ragas keeps every metric auditable line by line: the evaluation layer is the product.

  • The gate tests itself

    CI regenerates the demo, requires v2 to pass, requires the gate to block v3 for groundedness and gold citation recall, and fails if any regenerated artifact differs from the commit.

  • Fork-safe PR comments

    Evaluation runs read-only on pull_request; a separate privileged workflow_run job posts the sticky comment only when the PR head equals the evaluated SHA.

09/Validation

How the claims are checked.

  • 381 tests pass with ruff and pyright clean; re-running the demo reproduces every committed result with zero drift, the gate passes v2 and blocks v3.
  • Audit fixes: crashed cases now score 0 and are gated, a missing metric counts as a regression, a gate crash exits 2, harness sleeps stay out of latency, and verbatim quotes score groundedness 1.0.
  • Dataset integrity: every run manifest embeds the SHA-256 of eval_set.jsonl, and the repo pins LF line endings so the hash is the same on Windows.
  • Agent trajectory metrics (tool-selection accuracy, call precision, argument schema validity, step efficiency) run on real repo-engineer traces, and a seeded agent regression is caught on 4 metrics.

10/Limitations

Stated plainly.

  • Lexical groundedness is a proxy, not entailment: paraphrases that share vocabulary can fool it, and it may undercount legitimate rewordings.
  • The gate's statistics cover case sampling, not model noise: measuring how much a nondeterministic model's answers move needs repeated runs.
  • The demo system under test is a deterministic extractive responder, not an LLM; its token counts are heuristic, and its sub-millisecond latency is reported but not gated.
  • Keyword retrieval cannot decide answerability, so abstention remains an open gap for the deterministic stack.
  • No comparable provider numbers yet: the first run stopped early on a free-tier quota, and the judge's agreement with human labels stays provisional until the labels are reviewed.
  • Retrieval ground truth is hand-declared.

11/Summary

Built
A trace-based evaluation engine for LLM/RAG and agent systems: a 150-case suite, three deterministic RAG versions, bootstrap intervals and paired tests in a CI gate, an async runner with rate limiting, and provider adapters.
Why
AI systems are easy to build and hard to trust: nondeterminism, scarce references and call cost make point-in-time testing worthless. AIRE makes evaluation replayable evidence.
How it works
Runs persist as validated traces; a deterministic engine scores them, classifies failures, and compares runs case by case with a tolerance and a paired significance test before calling anything a regression.
Key decision
Tolerance plus significance: a metric is regressed only when the change is beyond tolerance and a paired test supports it, otherwise inconclusive. That keeps a 150-case gate from flapping.
Strongest result
The gate blocks a planted citation-stripping regression (groundedness 1.0 → 0.0 on all 130 answerable cases) and passes a real retrieval improvement (Recall@3 0.72 → 0.86, p < 0.001).
Main limitation
Groundedness is a lexical proxy, the demo system under test is not an LLM, and provider numbers are not comparable yet.
Next
A full provider run once the quota allows, judge calibration on reviewed labels, and a semantic answerability check, since keyword scores cannot separate unanswerable questions.

Common questions

  1. Q01Your groundedness baseline changed. What happened?

    A citation placed after the period was attached to the next sentence, so verbatim quotes scored 0.5. I found it with a test asserting that verbatim extraction must score 1.0; with the fix, the true baseline is 1.0.

  2. Q02Why paired tests and not just compare means?

    Both versions answer the same cases, so pairing removes per-case difficulty. McNemar's exact test fits pass/fail metrics and a paired bootstrap fits continuous ones, with Holm adjustment across metrics.

  3. Q03How do you stop rate-limit failures?

    Client-side token buckets for requests and tokens with AIMD, Retry-After honoured, full jitter, fail fast on a daily quota, and an exact-request cache. Against a server enforcing the limit, an over-eager client absorbed 18 rate-limit responses with 0 failed cases.

  4. Q04Why not use the SDK retries?

    Two retry layers multiply attempts and hide 429s from the limiter. One owner, ModelClient, sees every attempt.

  5. Q05Why replay traces instead of evaluating live?

    Cost and determinism: the system runs once and the engine scores stored traces, so new metrics apply to old runs at zero API cost and comparisons never re-invoke the system.

  6. Q06Why is the PR comment fork-safe?

    Untrusted fork code never runs with a write token. The privileged job only reads an uploaded artifact, sanitizes it and checks the SHA before posting.