retrieval-eval 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +342 -0
  3. package/dist/cli.js +1344 -0
  4. package/dist/index.d.ts +376 -0
  5. package/dist/index.js +971 -0
  6. package/package.json +74 -0
  7. package/spec/README.md +31 -0
  8. package/spec/chunk-id.md +51 -0
  9. package/spec/drift.md +49 -0
  10. package/spec/fixtures/README.md +48 -0
  11. package/spec/fixtures/basic/expected.json +43 -0
  12. package/spec/fixtures/basic/judgments.jsonl +4 -0
  13. package/spec/fixtures/basic/run.jsonl +2 -0
  14. package/spec/fixtures/chunk-id/expected.json +32 -0
  15. package/spec/fixtures/drift/corpus.json +38 -0
  16. package/spec/fixtures/drift/expected.json +22 -0
  17. package/spec/fixtures/drift/judgments.jsonl +4 -0
  18. package/spec/fixtures/duplicate-ranking/expected.json +56 -0
  19. package/spec/fixtures/duplicate-ranking/judgments.jsonl +3 -0
  20. package/spec/fixtures/duplicate-ranking/run-duplicate-query.jsonl +2 -0
  21. package/spec/fixtures/duplicate-ranking/run-non-string-key.jsonl +1 -0
  22. package/spec/fixtures/duplicate-ranking/run.jsonl +2 -0
  23. package/spec/fixtures/merge/corpus.json +22 -0
  24. package/spec/fixtures/merge/expected.json +21 -0
  25. package/spec/fixtures/merge/judgments.jsonl +3 -0
  26. package/spec/fixtures/no-positives/expected.json +17 -0
  27. package/spec/fixtures/no-positives/judgments.jsonl +4 -0
  28. package/spec/fixtures/no-positives/run.jsonl +2 -0
  29. package/spec/fixtures/nothing-scored/expected.json +9 -0
  30. package/spec/fixtures/nothing-scored/judgments.jsonl +1 -0
  31. package/spec/fixtures/nothing-scored/run.jsonl +1 -0
  32. package/spec/fixtures/qrels/beir.tsv +4 -0
  33. package/spec/fixtures/qrels/expected.json +14 -0
  34. package/spec/fixtures/qrels/trec.qrels +4 -0
  35. package/spec/fixtures/strata/expected.json +40 -0
  36. package/spec/fixtures/strata/judgments.jsonl +5 -0
  37. package/spec/fixtures/strata/run.jsonl +5 -0
  38. package/spec/fixtures/stratum-order/expected.json +30 -0
  39. package/spec/fixtures/stratum-order/judgments.jsonl +5 -0
  40. package/spec/fixtures/stratum-order/run.jsonl +5 -0
  41. package/spec/fixtures/summarize/expected.json +53 -0
  42. package/spec/fixtures/unsorted-queries/expected.json +23 -0
  43. package/spec/fixtures/unsorted-queries/judgments.jsonl +3 -0
  44. package/spec/fixtures/unsound-judgments/expected.json +19 -0
  45. package/spec/fixtures/unsound-judgments/judgments.jsonl +3 -0
  46. package/spec/fixtures/unsound-judgments/run.jsonl +1 -0
  47. package/spec/judgments.schema.json +54 -0
  48. package/spec/report.schema.json +227 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,342 @@
1
+ <div align="center">
2
+
3
+ # retrieval-eval
4
+
5
+ **Every re-chunk quietly invalidates part of your RAG test suite.<br>
6
+ `retrieval-eval` tells you which labels are still true, and repairs the ones it can.**
7
+
8
+ Label drift detection · deterministic retrieval metrics · a portable, qrels-compatible judgment format<br>
9
+ Zero dependencies · no API key · TypeScript and Python
10
+
11
+ [![CI](https://github.com/aton-of-data/retrieval-eval/actions/workflows/ci.yml/badge.svg)](https://github.com/aton-of-data/retrieval-eval/actions/workflows/ci.yml)
12
+ [![npm version](https://img.shields.io/npm/v/retrieval-eval?logo=npm&label=npm&color=cb3837)](https://www.npmjs.com/package/retrieval-eval)
13
+ [![PyPI version](https://img.shields.io/pypi/v/retrieval-eval?logo=pypi&logoColor=white&label=pypi&color=3775a9)](https://pypi.org/project/retrieval-eval/)
14
+ [![node](https://img.shields.io/node/v/retrieval-eval?logo=nodedotjs&logoColor=white&color=5fa04e)](https://www.npmjs.com/package/retrieval-eval)
15
+ [![python](https://img.shields.io/pypi/pyversions/retrieval-eval?logo=python&logoColor=white&color=3775a9)](https://pypi.org/project/retrieval-eval/)
16
+ [![zero dependencies](https://img.shields.io/badge/runtime%20deps-0-brightgreen)](#why-zero-dependencies)
17
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/aton-of-data/retrieval-eval/blob/main/LICENSE)
18
+ [![docs](https://img.shields.io/badge/docs-aton--of--data.github.io-0d1117?logo=github)](https://aton-of-data.github.io/retrieval-eval/)
19
+
20
+ </div>
21
+
22
+ ---
23
+
24
+ A retrieval test suite rests on one assumption nobody writes down: that every label still points
25
+ at the passage a human actually read. Labels are stored as chunk IDs, and chunk IDs are an
26
+ artifact of your chunker. Change the chunk size, the splitter or the overlap, and the IDs move
27
+ while the labels stay where they were. Nothing errors. The metrics keep computing, against ground
28
+ truth that is partly no longer there.
29
+
30
+ One command shows you how much:
31
+
32
+ ```bash
33
+ npx retrieval-eval drift --judgments judgments.jsonl --corpus corpus.json
34
+ ```
35
+
36
+ ```
37
+ 312 judgments · labeled @ fingerprint recursive/512
38
+ live corpus @ fingerprint recursive/384
39
+
40
+ ok 188 VALID chunk_id still present
41
+ ! 47 RE-ANCHORABLE text moved to a new chunk_id
42
+ ! 24 MERGED text absorbed into a coarser chunk
43
+ ! 34 SPLIT labeled text now spans 2+ chunks
44
+ x 19 ORPHANED source text or document is gone
45
+
46
+ 40% of your judgment set no longer matches the live corpus.
47
+ Any metric computed against it is measuring two changes at once.
48
+ 71 recoverable automatically · 53 need a human
49
+
50
+ next retrieval-eval drift --fix, to re-anchor the recoverable labels
51
+ ```
52
+
53
+ You changed your chunker. Your `recall@5` moved 0.06. You credited the change.
54
+
55
+ But 40% of your labels no longer point at the text a human actually read. Part of that movement
56
+ was your test suite decaying, not your retriever improving, and no other evaluation tool will
57
+ tell you which part.
58
+
59
+ `retrieval-eval` separates them, then recovers the labels it can:
60
+
61
+ ```bash
62
+ npx retrieval-eval drift --judgments judgments.jsonl --corpus corpus.json --fix
63
+ # fixed re-anchored 71 label(s) in judgments.jsonl
64
+ # review 53 label(s) still need a human
65
+ ```
66
+
67
+ `RE_ANCHORABLE` and `MERGED` are recoverable: the text a human judged is still there, either as
68
+ its own chunk or inside a bigger one. `SPLIT` and `ORPHANED` are left alone on purpose, because
69
+ guessing at them would fabricate ground truth, which is the exact failure this tool exists to
70
+ expose.
71
+
72
+ > **See it happen in 30 seconds.** [`examples/quickstart`](https://github.com/aton-of-data/retrieval-eval/tree/main/examples/quickstart) runs a corpus
73
+ > whose text never changes, re-chunks it, and watches `recall@3` fall from 1.00 to 0.00 while
74
+ > retrieval stays perfect, then brings it back with `--fix`. Six more runnable scenarios, the
75
+ > integration for eight stacks, and complete CI jobs are in [`examples/`](https://github.com/aton-of-data/retrieval-eval/tree/main/examples).
76
+
77
+ ## Why this matters
78
+
79
+ A golden set is the most expensive thing in a RAG project. Every label is a person reading a
80
+ passage and deciding whether it answers a question. Yet it is the one artifact nothing checks.
81
+ Retrievers get versioned, prompts get diffed, embedding models get benchmarked, and the labels
82
+ underneath all of them are treated as permanent. They are coordinates into one particular
83
+ chunking, and every chunking change moves the map.
84
+
85
+ The damage is quiet, and it points the wrong way. A chunker that genuinely retrieves better can
86
+ score worse, because its correct answers now live under IDs the labels have never seen. A real
87
+ improvement and the decay it caused can cancel out and read as no change at all. Either way, the
88
+ number you gate releases on is measuring two things at once, and nothing tells you how much of
89
+ each.
90
+
91
+ Teams that notice end up with three bad options: relabel from scratch, stop trusting the suite,
92
+ or stop changing the chunker. `drift` is a fourth. It names exactly which labels moved, recovers
93
+ every one whose text is provably still there, and sends only the rest to a human. After that,
94
+ your metrics are measuring your retriever again.
95
+
96
+ ## Install
97
+
98
+ ```bash
99
+ npm install retrieval-eval # or: npx retrieval-eval --help
100
+ ```
101
+
102
+ Same name, same commands, same flags, same rendered output, same exit codes in both, so one CI
103
+ step works for a polyglot team. Node 20.11 or newer, Python 3.10 or newer.
104
+
105
+ ## What it does
106
+
107
+ **1. Keeps your labels true when the corpus changes.** Every chunk gets an identity derived from
108
+ its content, not its position ([the one idea](#the-one-idea)), so a label remembers what a human
109
+ read rather than where it used to sit. `drift` classifies every label as `VALID`,
110
+ `RE_ANCHORABLE`, `MERGED`, `SPLIT` or `ORPHANED`, `--fix` repairs the two recoverable classes in
111
+ place, and the command exits non-zero on decay, so a re-chunk cannot ship with a stale suite
112
+ behind it. Run it before `score`, in CI, on every chunking change.
113
+
114
+ **2. Measures retrieval, deterministically.** `precision@k`, `recall@k`, `ndcg@k`, `mrr@k`, `map@k`,
115
+ `hit_rate@k`. Every metric carries its cutoff in its name, because a number that means
116
+ something other than its name is how a report stops being trustworthy. No model call, no API key, no per-run cost, milliseconds per run.
117
+
118
+ These are the metrics that localize a failure. High `recall@20` with low `recall@5` means
119
+ retrieval found the answer and ranking buried it, so the reranker is the problem rather than the
120
+ chunker. A single end-to-end score cannot make that distinction.
121
+
122
+ ```bash
123
+ retrieval-eval score --judgments judgments.jsonl --run hits.jsonl -k 5 \
124
+ --baseline .retrieval-eval/baseline.json \
125
+ --gate recall@5:-0.02 \
126
+ --gate worst-stratum:recall@5:0.7
127
+ ```
128
+
129
+ **3. Refuses to let an average hide a broken query class.**
130
+
131
+ ```
132
+ recall@3 by stratum
133
+ · legal 0.0000 ░░░░░░░░ n=2 worst
134
+ · billing 1.0000 ████████ n=3
135
+
136
+ gates
137
+ ok recall@3:0.5
138
+ x worst-stratum:recall@3:0.7
139
+ ```
140
+
141
+ Overall recall is 0.60 and passes an average gate. Legal queries retrieve nothing. That is why
142
+ `stratum` is a field in the format, `per_stratum` is mandatory in the report, and worst-stratum
143
+ gating is a first-class gate.
144
+
145
+ **4. Speaks TREC qrels, so thirty years of tooling just works.**
146
+
147
+ ```bash
148
+ retrieval-eval convert --judgments judgments.jsonl --to qrels | trec_eval -m all_trec - run.txt
149
+ retrieval-eval convert --qrels beir/scifact/qrels/test.tsv --to judgments > judgments.jsonl
150
+ ```
151
+
152
+ A judgments file is a strict superset of qrels, so `trec_eval`, `ir_measures`, `pytrec_eval`,
153
+ BEIR and `ir_datasets` are all one conversion away in either direction.
154
+
155
+ **5. Tells you when a judgment set is unsound**, not merely malformed:
156
+
157
+ ```
158
+ warning [no-human-labels] every label is synthetic. Without human labels you cannot measure
159
+ judge calibration, and synthetic labels quietly become ground truth
160
+ warning [mixed-fingerprints] judgments span 2 corpus fingerprints; run 'drift' first
161
+ warning [thin-stratum] stratum 'legal' has only 2 labels, too few to gate on
162
+ error [no-positives] no judgment has relevance >= 1, so recall is undefined
163
+ ```
164
+
165
+ ## The one idea
166
+
167
+ Give every chunk an identity derived from its **content**, not its position:
168
+
169
+ ```
170
+ chunk_id = "c1:" + sha256(doc_uri ␟ doc_revision ␟ ordinal ␟ normalize(text) ␟ chunker_fingerprint)[0..16]
171
+ # 128 bits, written as 32 lowercase hex characters
172
+ ```
173
+
174
+ A label then points at text a human read, so after a re-chunk the tool can say exactly which
175
+ labels survived.
176
+
177
+ The [spec](https://github.com/aton-of-data/retrieval-eval/tree/main/spec/) is two JSON Schemas and one hash definition, small enough to implement in an
178
+ afternoon in any language. If it ever needs a framework, it has failed. It ships inside both
179
+ packages, so a port never has to start from the GitHub UI.
180
+
181
+ ## What this removes
182
+
183
+ Each row is a situation teams are already in.
184
+
185
+ | Situation | What breaks today | What changes |
186
+ |---|---|---|
187
+ | Chunker changed and a metric moved | the whole movement is credited to the retriever | drift separates label decay from retrieval change |
188
+ | Chunk size tuned, labels now point at stale IDs | the golden set is relabeled by hand, or quietly trusted anyway | `--fix` re-anchors every label whose text survived; only the rest need a human |
189
+ | Golden set built in one evaluation tool, team adopts another | labels are rebuilt by hand or abandoned | one conversion, labels outlive the tool |
190
+ | Public collection in TREC qrels, product written in TypeScript | no path into the ecosystem | one conversion, then scored locally |
191
+ | Gate on an aggregate metric | a whole query class can fail silently | worst-stratum gate fails the build |
192
+ | Judged metric gated on a single sample | a non-deterministic instrument reported as a point estimate | confidence interval, plus an `INDETERMINATE` verdict |
193
+ | Synthetic labels accumulating over time | they become ground truth without anyone deciding that | `labeled_by` is required, and `validate` warns |
194
+ | Evaluation platform priced per run | build gates get rationed to stay inside a tier | no model call, no API key, no per-run cost |
195
+ | Evaluation tooling added to a CI image | a dependency tree makes the step slow or fragile | standard library only, in both languages |
196
+
197
+ ## Use it as a library
198
+
199
+ ```ts
200
+ import { drift, score, chunkId, toQrels } from "retrieval-eval";
201
+
202
+ const result = drift(judgments, corpus);
203
+ if (result.summary.invalid_ratio > 0.1) throw new Error("golden set has decayed");
204
+
205
+ const { metrics } = score(judgments, run, { k: 5 });
206
+ metrics["recall@5"].value;
207
+ ```
208
+
209
+ ```python
210
+ from retrieval_eval import drift, score, chunk_id, to_qrels
211
+
212
+ result = drift(judgments, corpus)
213
+ if result.summary.invalid_ratio > 0.1:
214
+ raise RuntimeError("golden set has decayed")
215
+
216
+ scored = score(judgments, run, k=5)
217
+ scored.metrics["recall@5"].value
218
+ ```
219
+
220
+ ## In CI
221
+
222
+ ```yaml
223
+ - run: npx retrieval-eval drift --judgments eval/judgments.jsonl --corpus eval/corpus.json
224
+ - run: |
225
+ npx retrieval-eval score \
226
+ --judgments eval/judgments.jsonl --run eval/hits.jsonl -k 5 \
227
+ --baseline eval/baseline.json \
228
+ --gate recall@5:-0.02 --gate worst-stratum:recall@5:0.7 \
229
+ --out report.json
230
+ ```
231
+
232
+ Exit `0` passed, exit `1` a gate failed or labels decayed, exit `2` bad invocation or unreadable
233
+ input. `drift` exits non-zero on its own, so it works as a standalone check.
234
+
235
+ GitLab, CircleCI, Jenkins, Azure Pipelines and pre-commit recipes are in [docs/ci.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/ci.md).
236
+
237
+ ## Why this does not already exist
238
+
239
+ Every evaluation tool scores against a golden set. None of them checks whether the golden set
240
+ still describes the corpus. RAGAS, DeepEval, promptfoo and the IR toolkits all store a label as
241
+ a pointer and trust it forever, because no shared format records which corpus revision or which
242
+ chunker a label was made against. Without that, drift is not merely unreported, it is
243
+ unmeasurable. The judgment format here adds exactly the fields that make it measurable, and
244
+ `drift` is the algorithm that uses them.
245
+
246
+ The metrics had a smaller gap of their own. Python has `pytrec_eval`, `ir_measures` and BEIR. On npm the package names you would reach for
247
+ first, `ndcg`, `ir-measures`, `trec-eval` and `qrels`, are unpublished, and what does exist is
248
+ thin: [`node-dcg`](https://www.npmjs.com/package/node-dcg) computes DCG alone and was last
249
+ published in 2023, [`trec-eval-wrapper`](https://www.npmjs.com/package/trec-eval-wrapper) shells
250
+ out to the `trec_eval` C binary rather than implementing anything and was last published in 2022,
251
+ and the recent entries are coupled to something else, an MCP server or a recommender engine's own
252
+ core package.
253
+
254
+ So there are two gaps, in order of importance: **nothing in either ecosystem treats judgment
255
+ drift as a measurable condition**, and **no maintained, standalone, dependency-free IR
256
+ evaluation library exists for JavaScript**. The evidence, including the
257
+ two claims this research falsified against its own earlier draft, is in
258
+ [research/](https://github.com/aton-of-data/retrieval-eval/tree/main/research/).
259
+
260
+ *(Registry state checked 2026-09-22. If this has changed, the claim is wrong and belongs in an
261
+ issue. Accuracy about our own positioning is part of the point.)*
262
+
263
+ ## It is not a replacement for judged evaluation
264
+
265
+ Retrieval quality is a large share of end-to-end RAG quality, not all of it. The rest is how well
266
+ the model uses what it retrieved. This covers the retrieval half rigorously and deliberately does
267
+ not claim to certify a RAG system.
268
+
269
+ Use it alongside RAGAS, DeepEval, promptfoo, Phoenix or Braintrust rather than instead of them. It
270
+ makes their golden sets portable and durable, which is why interoperability is the strategy rather
271
+ than a feature.
272
+
273
+ For the judged half, the report format carries the honesty those metrics need, and `summarize()`
274
+ computes it: `n`, `stdev` and a confidence interval from repeated samples of the same judge, plus
275
+ a third verdict, `INDETERMINATE`. LLM judges are non-deterministic even at temperature 0, so a
276
+ `ci-lower` gate on a single sample says "I do not know" rather than guessing.
277
+
278
+ ```python
279
+ report.metrics["faithfulness"] = summarize([0.8, 1.0, 0.6, 0.9, 0.7])
280
+ # value 0.8000, stdev 0.1581, 95% interval [0.6037, 0.9963]
281
+ # the mean clears a 0.8 floor; the interval says you cannot tell yet
282
+ ```
283
+
284
+ [`examples/judged-metrics`](https://github.com/aton-of-data/retrieval-eval/tree/main/examples/judged-metrics) runs that end to end in both languages.
285
+
286
+ ## Why zero dependencies
287
+
288
+ Both packages use only their standard library: `sha256` and JSON. A measurement tool that drags in
289
+ a dependency tree becomes a thing you skip installing in CI. It also keeps the spec implementable
290
+ anywhere, which is the point of a spec.
291
+
292
+ ## Status
293
+
294
+ **0.1.0, alpha.** The formats and the metric mathematics are what we intend to keep. The CLI
295
+ surface may still move. The `c1:` and `t1:` hash prefixes exist so identity can be versioned
296
+ without breaking existing judgment files.
297
+
298
+ What is already load-bearing, and enforced on every commit:
299
+
300
+ - **Parity.** Both implementations run the same `spec/fixtures` through both CLIs and must agree
301
+ on the numbers, the rendered output, the help text and the exit codes. Not two test suites that
302
+ each pass, one job that runs both and diffs the result.
303
+ - **Determinism.** Same inputs, same output, every run. No network, no model, no clock in the
304
+ numbers. Across the two implementations: rendered output and judgments files are byte-identical,
305
+ and `--json` agrees as data rather than as bytes, because JSON writes a whole number as `1` in
306
+ JavaScript and `1.0` in Python. Compare reports by parsing them, not by checksum.
307
+ - **A quickstart that is executed, not described.** CI runs the README's own first-run path on a
308
+ clean checkout on Linux and macOS, and asserts the demo still demonstrates its claim.
309
+
310
+ ## Repo layout
311
+
312
+ ```
313
+ spec/ the contract: 2 schemas, 1 hash definition, shared fixtures
314
+ fixtures/ conformance cases BOTH implementations must pass
315
+ packages/retrieval-eval/ TypeScript (tsup · vitest · biome)
316
+ python/retrieval-eval/ Python (hatchling · pytest · ruff · mypy --strict)
317
+ docs/ CLI reference, CI recipes, interop, troubleshooting
318
+ examples/ runnable scenarios, stack integrations, pipeline jobs
319
+ frameworks/ LangChain, LlamaIndex, Haystack, Chroma, Qdrant, pgvector, RAGAS, DeepEval
320
+ pipelines/ Jenkins, GitHub Actions, GitLab, Azure, CircleCI, pre-commit
321
+ research/ the evidence behind the design
322
+ ```
323
+
324
+ Python and TypeScript are peers, not ports. Both read the same `spec/fixtures` and must agree to
325
+ the twelfth decimal, which is what makes "parity by spec" a claim rather than a slogan.
326
+
327
+ ## Docs
328
+
329
+ | | |
330
+ |---|---|
331
+ | [docs/cli.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/cli.md) | every command, flag, exit code and output mode |
332
+ | [docs/ci.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/ci.md) | pipeline recipes and how to keep a baseline |
333
+ | [docs/interop.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/interop.md) | qrels, BEIR, `ir_datasets`, and the tools you already run |
334
+ | [docs/troubleshooting.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/troubleshooting.md) | every error and warning, and what to do about it |
335
+ | [spec/](https://github.com/aton-of-data/retrieval-eval/tree/main/spec/) | the formats, the hash, the fixtures |
336
+ | [examples/](https://github.com/aton-of-data/retrieval-eval/tree/main/examples) | seven runnable scenarios, eight stack integrations, seven pipeline jobs |
337
+ | [research/](https://github.com/aton-of-data/retrieval-eval/tree/main/research/) | the problem, the market gap, and the impact argument |
338
+ | [CONTRIBUTING.md](https://github.com/aton-of-data/retrieval-eval/blob/main/CONTRIBUTING.md) | add a metric, add an adapter, port the spec |
339
+
340
+ ## License
341
+
342
+ Apache-2.0