﻿---
title: In CI
description: judy is built to fail a build for the right reason. A gate names a number that must hold. --max-regression names a drop you will not accept. Exit codes...
url: https://docs-v3-preview.elastic.dev/workflow/ci
---

# In CI
judy is built to fail a build for the right reason. A gate names a number that must hold. `--max-regression` names a drop you will not accept. Exit codes say which kind of
failure happened.

## Exit codes


| Code | Meaning                                                                         |
|------|---------------------------------------------------------------------------------|
| 0    | ok                                                                              |
| 1    | a gate was breached, or the candidate regressed by more than `--max-regression` |
| 2    | usage error or an invalid file (for example an unknown target)                  |
| 3    | an IO error or failed searches                                                  |

A failed search is its own exit code, not a bad score: a cluster that is down never looks like a relevance regression.
```text
$ judy run fruit.judgements.yaml --target nope
error: No target 'nope'. Defined: baseline, candidate.
$ echo $?
2
```


## Gates

Put the numbers a target must hold in the judgement set, per target:
```yaml
gates:
  candidate: {ndcg@5: 0.9, success@1: 0.5}
```

```text
gates
  FAIL ndcg@5 0.638 < 0.800
  FAIL success@1 0.333 < 0.500
```

`judy run` exits 1 when any gate fails. Set gates a little under what you measure today. A gate at the current score fails on noise. A gate far below it never fires.

## Regressions

A gate protects an absolute level. `--max-regression` protects against going backwards, whatever the level:
```sh
judy compare main.results.yaml pr.results.yaml --max-regression 0.01
```

It exits 1 when the candidate's mean is lower than the baseline's by more than 0.01.

## A GitHub Actions job

```yaml
- name: Score the pull request
  run: judy run search.judgements.yaml --target candidate --format md
  env:
    ES_URL: ${{ secrets.ES_URL }}
    ES_API_KEY: ${{ secrets.ES_API_KEY }}

- name: Compare with main
  run: judy compare search.main.results.yaml search.candidate.results.yaml --max-regression 0.01
```

`judy run` appends its markdown to `$GITHUB_STEP_SUMMARY` when that variable is set. The scorecard then shows on the run page
without a step of its own. `--format md` prints the same table for a pull request comment:
```text
### fruit on baseline

3 queries, 3 scorable, labels: human

| metric | all | `words:2` | `words:1` |
|---|---|---|---|
| success@1 | 0.333 | 0.000 | 1.000 |
| success@3 | 1.000 | 1.000 | 1.000 |
| mrr@5 | 0.667 | 0.500 | 1.000 |
| ndcg@5 | 0.638 | 0.650 | 0.613 |
```

`--format json` gives the same data for your own tooling.

## Keeping a baseline

`judy compare` needs no cluster when both sides are results files. Store the main branch's results as a CI artifact (or commit
them) and compare each pull request with them. Results files hold each query's metrics and ranked ids, so they are small and
diff well.

## Tips

- **Run the same judgement set everywhere.** A set is a file: commit it next to the code that changes the search.
- **Mind `judged@k`.** A new query that returns many unjudged documents can lower a score without being worse. Look at the
  `judged@k` line, and fill the gaps with [`judy judge`](https://docs-v3-preview.elastic.dev/llm/judging) when it drops.
- **Cap spend in CI.** `judy judge` has `--max-calls`; leave the LLM commands out of the pull request job and run them on a
  schedule.