# Evaluation Lab

Measure a workflow against a versioned dataset with 18 evaluators for retrieval, generation, safety, agents and operations, and compare two versions case by case.

Source: https://glamorous-boar.cloudvent.net/evaluation/

---

<Figure source="/src/assets/images/screens/evaluate.jpg" alt="Comparing two evaluations in the Evaluation Lab" caption="Compare two experiments metric by metric and case by case."/>

The **Evaluation Lab** answers the question every AI engineer faces: *did my change make it better?* Run a dataset of test cases against a revision of your graph, change the graph, run again, and compare.

## Walkthrough

1. Create a project from *Advanced RAG*, upload `examples/data/employee-handbook.md`, and **Run → Index report**.
2. Click **Evaluate** in the toolbar.
3. **Datasets** tab → **Import** `examples/datasets/employee-handbook-qa.json` (8 cases).
4. **Run** tab: pick the dataset version, the graph revision, a label (*baseline*), the answer output (`answer`), K (5), evaluators by area, and optionally a **judge** model and its secret. Start.
5. **Results**: a summary per metric (with the aggregation method and *n/of* applicable cases) and a per-case table: answer, retrieved passages, metric details. Mark it as the **baseline**.
6. Change the graph (e.g. switch the Reranker to `overlap`), save, run the same dataset again with a new label.
7. **Compare** the two runs: per-metric deltas, per-case regressions and improvements, and cases missing on either side.

Each case is a **real, traced run**, so you can open any case's run and see exactly what produced its score.

## Test cases

<CodeBlock language="json" filename="A test case" showCopy={true}>

```
{
  "id": "hotel_limit",
  "inputs": {"question": "What is the hotel limit per night?"},
  "reference": "Up to 180 EUR per night in major cities, 120 EUR elsewhere.",
  "expected_sources": [{"filename": "employee-handbook.md", "section": "Travel"}],
  "must_include": ["180"],
  "must_not_include": [],
  "expected_tools": []
}
```

</CodeBlock>

Only `id` and `inputs` are required. `expected_sources` entries can also be `"file.md#Section"` or a chunk ID (`art_…#c3`). A metric that needs a missing field is *not applicable* for that case (shown as `null` and excluded from the mean).

Datasets are **immutable per version**: saving appends a version unless nothing changed. Edit cases in the form editor, or import and export JSON.

## Evaluators

| Area | Evaluator | Measures | Needs |
|---|---|---|---|
| Retrieval | `recall_at_k` | Share of expected sources found in the top K | expected_sources + a retrieval node |
| Retrieval | `precision_at_k` | Share of returned results (≤ K) that are expected | same |
| Retrieval | `mrr` | 1 / rank of the first relevant result | same |
| Retrieval | `ndcg_at_k` | Rank-weighted relevance (binary) | same |
| Retrieval | `hit_rate` | Any relevant result in the top K | same |
| Generation | `contains_required` | All `must_include` phrases present | must_include |
| Generation | `reference_f1` | Token-overlap F1 with the reference | reference |
| Generation | `citation_validity` | Cited sources exist | an answer object with citations |
| Generation | `citation_source_recall` | Expected sources were cited | citations + expected_sources |
| Generation | `correctness_judge` | LLM judge: answer vs reference (estimate) | reference + judge |
| Generation | `groundedness_judge` | LLM judge: answer supported by retrieved passages (estimate) | passages + judge |
| Safety | `forbidden_content` | No `must_not_include` phrase present | must_not_include |
| Agent | `tool_use` | Expected tools were used (including inside sub-agents) | expected_tools |
| Operations | `success` | The run succeeded | — |
| Operations | `latency_ms` | Mean, p50, p95 | — |
| Operations | `tokens` | Token usage | — |
| Operations | `cost_usd` | Reported cost | — |
| Operations | `retries` | Retries during the run | — |

**What gets scored:** the answer comes from the chosen Output (a string, or an answer object with citations and steps). Retrieval metrics score the documents of the last retrieval node the answer depends on (Retriever, Keyword/Hybrid Search, Reranker, Context Compressor), or one you name.

## LLM judges are estimates

A judge makes a forced `submit_grade` call, scoring 1–5 against a stated rubric, scaled to 0–1. Every grade stores the judge model, prompt version (`correctness-v1`, `groundedness-v1`), rubric and reasoning; the run stores the judge's usage and cost. A judge failure is *not applicable* with the error, never a silent 0. The UI labels judge metrics **estimate**. Judges are opt-in because they cost model calls.

## Comparisons you can trust

- Every evaluation records the dataset ID, version and content hash, the project revision and IR hash, and the full config.
- `compare` flags runs as **not comparable** when the dataset version or hash, K or the judge differ.
- One run per project and dataset can be the **baseline**.
- Small datasets show direction, not proof: statistical significance is not computed.

## Cost

About $0.002 per case for a typical RAG pipeline with Gemini Flash, plus the judge. Case runs appear in the project's run history.

## API

`GET|POST /api/projects/{id}/datasets`, `GET|PUT|DELETE /api/datasets/{id}`, `POST /api/projects/{id}/evaluations`, `GET /api/evaluations/{id}`, `…/cases`, `POST …/cancel`, `PUT …/baseline`, `GET /api/evaluations/compare?a=…&b=…`, `GET /api/evaluators`. See [REST API](/api/#evaluation).

## Theory

What each metric means, how to build a good test set and how to use LLM-as-judge responsibly: [Evaluating AI systems](/learn/evaluation/).
