Seed-aware, clustered confidence intervals for retrieval results. It tells you whether a gain holds up, how big a gap your comparison could detect, and how many seeds your next experiment needs. It reads standard run and qrels files or similarity matrices.
Retrieval benchmarks give each item several queries: five captions per image on COCO and Flickr30k, about 40 per video on MSVD, many paraphrases per scenario on templated benchmarks. They are then scored as if every query were independent. They aren't: a model that misses a hard video misses most of its captions. On MSVD the usual per-caption error bars are about 3x too small. And a single training run can't say whether a small gain came from the method or the seed.
retriewell:
- groups queries by the item they describe;
- when you give it several runs per system, counts training-seed noise as noise;
- reports the interval, a p-value, the gap the comparison could detect, and a verdict.
The statistics are standard (cluster-robust CR2 errors with Bell-McCaffrey degrees of freedom, as in Miller 2024 and errorbars). What retriewell adds is the retrieval side and the seeds: see How it compares.
pip install retriewell
import retriewell as rw
d = rw.example_data() # per-caption hit@1 on Flickr30k (5,000 captions of 1,000 images); 10 seeds of two recipes
r = rw.compare(d["r0"], d["r2"], groups=d["image"], names=("5 epochs", "10 epochs"),
unit="image", metric="R@1", scale=100)
print(r)5 epochs vs 10 epochs (R@1) (5,000 queries in 1,000 images)
scores 74.76 vs 75.04 gap -0.28 (10 epochs higher)
question is one training setup better than the other, allowing for training luck (seeds) and the test set?
95% interval [-0.66, +0.10], p = 0.139 (if queries were independent: [-0.65, +0.09])
grouping widens the test-set error bars 1.17x; ~3,625 effective independent queries (design effect 1.38)
seed noise SE 0.16 from seeds vs 0.09 from the test set (10 and 10 seeds)
detectable gap for this pair on this test set, a true gap of ~0.53 would be detected 80% of the time
verdict INCONCLUSIVE: the data are consistent with gaps from -0.66 to +0.10.
One run of each (d["r0"][3] vs d["r2"][3]) shows the 5-epoch recipe ahead by 0.24, also inconclusive. Single
runs point the wrong way surprisingly often. r.sentence() gives one line for a paper; r.to_dict() gives every
number as valid JSON.
More examples (an OpenCLIP cross-modal table, Flickr30k end to end): examples/.
With several seeds, there are two different questions, and tools that don't say which one they answer can mislead:
estimand= |
Question | Noise counted |
|---|---|---|
'recipe' (default with seeds) |
Is one training setup better than the other? | Test set and training seeds |
'checkpoints' (only option for single runs) |
Do these particular trained models differ? | Test set only (seeds averaged) |
Method papers usually make recipe claims. Averaging seeds and running a test-set-only test (what most tools do)
answers the checkpoint question; in our simulations that gives 10-40% false detections for recipe claims when seed
noise shifts whole runs. A system with no training randomness (BM25, a frozen model) should be marked
deterministic; otherwise a single-run system borrows the other system's seed variance, with a warning.
# Two systems: per-query scores (one row per seed if you have several) and one group label per query
r = rw.compare(ours, base, groups=image_ids, names=("ours", "base"), unit="image", metric="R@1", scale=100,
deterministic=(False, True)) # e.g. base is BM25
# Several systems, Holm-corrected; print(t), t.to_markdown() or t.to_latex(); row warnings appear as footnotes
t = rw.compare_many({"ours": ours, "base": base, "abl": abl}, groups=image_ids, baseline="base", scale=100)
# The standard cross-modal table from similarity matrices (one matrix, or a list with one per seed).
# unit="video" labels rows T2V/V2T. RSUM is the sum of the six row means, also with unequal captions per item.
t = rw.compare_crossmodal({"ours": [sim_s0, sim_s1, sim_s2], "baseline": sim_base}, item_of_query=caption_to_video,
unit="video")Two groupings that cut across each other (each query has an item and a wording template; a clip and its source
video): rw.compare(..., groups=item_ids, crossed=template_ids, crossed_unit="template").
- The interval uses two-way clustering and is never narrower than either one-way interval.
- In simulations it stays at or below about 8% false detections, where one-way grouping misses template effects entirely.
- With fewer than about 10 crossed groups it is valid but conservative: also report the one-way result.
IR topics with different numbers of query variants: weight="group" weights every topic equally (the mean of topic
means, as IR papers report). That is a different quantity from the query-weighted mean when the gain depends on topic
size; the output says which one you got. It can't be combined with crossed.
Does the retrieval pool matter? rw.gallery_bootstrap(sim_ours, sim_base, item_of_query) resamples images or
videos as both queries and distractors. It takes one matrix per system, query-to-item only. Its SE runs about 5-15%
high even when the pool doesn't matter, so read a ratio up to about 1.1-1.2 as "no pool effect". On COCO and Flickr30k
we measured 1.06 and 1.01.
Helpers:
rw.ranks_from_similarity(sim, gold)gives 0-based ranks, with several gold items per query allowed.rw.hits_from_ranks(ranks, k)gives hit@k.rw.read_run,rw.read_qrels,rw.per_queryandrw.groups_from_qrelswork with files.
Verdicts:
| Verdict | Meaning |
|---|---|
a-better / b-better |
The interval excludes zero. In a table, this is after Holm's correction. |
inconclusive |
The data are consistent with the interval shown. Not evidence that the systems are equal. |
not-established |
Would pass a test that treats queries as independent, but not a grouped one: the over-claim this tool catches. |
equivalent |
Only with sesoi= (the smallest gap that matters, in reported units): the interval lies inside ±sesoi. |
Lead with the interval, not the label.
print(rw.plan(0.5, comparison=r)) # r: a compare() result, ideally with 3+ seeds per systemtarget gap 0.5; test-set SE 0.0898; seed SD 0.357
seeds per system -> smallest gap detected 80% of the time
1 -> 1.44
2 -> 1.03
3 -> 0.855
5 -> 0.681
10 -> 0.513
20 -> 0.404
Detectable with 11 seed(s) per system.
How it plans:
- Plan from a pilot pair similar to the one you'll test: the detectable gap depends on how often the two systems disagree.
- A pilot that can't separate seed noise from test noise (single runs, or under 3 seeds) overstates the test-set noise, and the planner says so.
- It refuses a target in points when the pilot is on a 0-1 scale, and notes the reverse.
retriewell check -a ours.run -b base.run --qrels qrels.txt --metric R@1 --unit image
retriewell check -a ours_s0.run -a ours_s1.run -a ours_s2.run -b bm25.run --deterministic bm25 --qrels q.txt
retriewell table -s ours=s0.run,s1.run,s2.run -s bm25=bm25.run --deterministic bm25 --qrels q.txt \
--metric ndcg@10,ap --group-by none --baseline bm25 --format latex
retriewell plan --target 0.5 --se-test 0.09 --seed-sd 0.36
retriewell floors
Options:
--estimand recipe|checkpoints--crossed FILE(two-way grouping;query_id grouplines)--weight group--paired-seeds--sesoi X(in reported units: points for R@k)--exit-code(fails CI unless A is detected better)--json
System names default to the run file names, with seed tags such as _s0 removed.
Grouping (--group-by):
| Option | Groups | Use for |
|---|---|---|
qrels (default) |
Queries with identical relevant sets | Captions of an image, paraphrases of a scenario |
none |
Every query alone | Ordinary IR test collections |
FILE |
query_id group lines |
Query variants of a topic |
Metrics:
hit@k/success@k: any relevant document in the top k, the image and video retrieval "R@k".R@k: the same, accepted only when every query has a single relevant document, because in IR R@k means recall.recall@k,P@k,ndcg@k,ndcg,rr,rprec,ap.- Several at once:
--metric ndcg@10,ap.
Conventions: these follow trec_eval, and per-query scores match pytrec_eval exactly.
- Ties are broken by doc id, descending.
- nDCG gain is linear (
--gain expfor 2^rel - 1). --min-relsets the relevance threshold.- Queries with no relevant document are not scored. trec_eval counts them as 0, so means can differ slightly.
Formats:
- qrels: TREC or 3-column BEIR.
- runs: TREC, or 3 columns, where the third column is read as ranks if it is exactly 1..n per query and as scores
otherwise (
--third-column). - A run that misses judged queries is an error (
--allow-missingto score them 0).
| Term | Meaning |
|---|---|
| Interval | 95% CI of the gap, queries grouped by item: CR2 standard error, Bell-McCaffrey degrees of freedom. With seeds: seed and test-set noise combined (Satterthwaite). With crossed=: two-way clustering (Cameron, Gelbach and Miller). |
| If queries were independent | The interval most papers implicitly use. |
| Design effect | How much grouping inflates the test-set variance; the test-set error bars widen by its square root. |
| Detectable gap | For this pair on this test set: the true gap found 80% of the time at the 5% level. Smaller for pairs that disagree less. |
| Effective groups | n² / Σ size². Below about 50, intervals are approximate; below 2, unreliable. |
| Scenario | Status |
|---|---|
| Captions per image or video; paraphrases sharing a relevant set | Supported (grouping from qrels) |
| Cross-modal tables (T2I/I2T or T2V/V2T R@k, RSUM) from similarity matrices | Supported |
| Several systems, several metrics | Supported (Holm) |
| Seeds, independent or paired; deterministic baselines | Supported. Use 3+ seeds per system, ideally 5+ |
| IR, one query per topic / query variants | --group-by none / a topic file; weight="group" for topic means |
| Nested designs (passage > question > paraphrase) | Pass the top level |
| Crossed designs (item x template, clip x source video) | crossed= / --crossed FILE |
| Uncertainty from the retrieval pool itself | gallery_bootstrap (a check; conservative) |
| Private data | Fully offline; outputs contain only names and numbers |
Limitations:
- With very uneven group sizes and gains that depend on group size, query-weighted intervals can be optimistic;
compare with
weight="group". consistency(worst and best of k random wordings per item) is experimental.
| retriewell | errorbars | evalci | ranx | |
|---|---|---|---|---|
| Clustered SE, single run | CR2 + Bell-McCaffrey (matches errorbars to 1e-13) | CR2 + Bell-McCaffrey | cluster bootstrap (opt-in) | no |
| Training seeds as noise (recipe claims) | yes | no | no | no |
| Detectable gap / power | yes, plus seed planning | yes | yes | no |
| Several systems, multiple-comparison correction | Holm | Holm | Holm / BH | Tukey HSD (per query) |
| Equivalence (smallest gap that matters) | yes | no | no | no |
| Run/qrels input, grouping from qrels, IR metrics | yes | no | no | yes (no grouping) |
| LLM-eval logs, HTML reports | no | yes | some | no |
For LLM evaluations, use errorbars. For retrieval results, especially with seeds or several captions per item, use retriewell.
- Paper reproduction: the tests reproduce the paper's numbers from the same per-query ranks (Flickr30k, public data).
- Simulations with a known answer: false-detection rates stay near 5% for:
- single runs;
- very unbalanced groups;
- 2, 3 and 5 seeds;
- deterministic baselines;
- crossed designs.
- Cross-checks against other tools:
- statsmodels and errorbars for standard errors and degrees of freedom;
- pytrec_eval for metrics;
- brute-force code for the seed estimator.
- Python: tested on 3.9-3.14, with NumPy 1.22 to current.
Paper: How Much of a Retrieval Gain Is Noise? (Kachroo, 2026; preprint forthcoming). MIT licence.