retrieval-eval 0.1.0__tar.gz

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 (62) hide show
  1. retrieval_eval-0.1.0/.gitignore +20 -0
  2. retrieval_eval-0.1.0/LICENSE +202 -0
  3. retrieval_eval-0.1.0/PKG-INFO +372 -0
  4. retrieval_eval-0.1.0/README.md +340 -0
  5. retrieval_eval-0.1.0/pyproject.toml +100 -0
  6. retrieval_eval-0.1.0/spec/README.md +31 -0
  7. retrieval_eval-0.1.0/spec/chunk-id.md +51 -0
  8. retrieval_eval-0.1.0/spec/drift.md +49 -0
  9. retrieval_eval-0.1.0/spec/fixtures/README.md +48 -0
  10. retrieval_eval-0.1.0/spec/fixtures/basic/expected.json +43 -0
  11. retrieval_eval-0.1.0/spec/fixtures/basic/judgments.jsonl +4 -0
  12. retrieval_eval-0.1.0/spec/fixtures/basic/run.jsonl +2 -0
  13. retrieval_eval-0.1.0/spec/fixtures/chunk-id/expected.json +32 -0
  14. retrieval_eval-0.1.0/spec/fixtures/drift/corpus.json +38 -0
  15. retrieval_eval-0.1.0/spec/fixtures/drift/expected.json +22 -0
  16. retrieval_eval-0.1.0/spec/fixtures/drift/judgments.jsonl +4 -0
  17. retrieval_eval-0.1.0/spec/fixtures/duplicate-ranking/expected.json +56 -0
  18. retrieval_eval-0.1.0/spec/fixtures/duplicate-ranking/judgments.jsonl +3 -0
  19. retrieval_eval-0.1.0/spec/fixtures/duplicate-ranking/run-duplicate-query.jsonl +2 -0
  20. retrieval_eval-0.1.0/spec/fixtures/duplicate-ranking/run-non-string-key.jsonl +1 -0
  21. retrieval_eval-0.1.0/spec/fixtures/duplicate-ranking/run.jsonl +2 -0
  22. retrieval_eval-0.1.0/spec/fixtures/merge/corpus.json +22 -0
  23. retrieval_eval-0.1.0/spec/fixtures/merge/expected.json +21 -0
  24. retrieval_eval-0.1.0/spec/fixtures/merge/judgments.jsonl +3 -0
  25. retrieval_eval-0.1.0/spec/fixtures/no-positives/expected.json +17 -0
  26. retrieval_eval-0.1.0/spec/fixtures/no-positives/judgments.jsonl +4 -0
  27. retrieval_eval-0.1.0/spec/fixtures/no-positives/run.jsonl +2 -0
  28. retrieval_eval-0.1.0/spec/fixtures/nothing-scored/expected.json +9 -0
  29. retrieval_eval-0.1.0/spec/fixtures/nothing-scored/judgments.jsonl +1 -0
  30. retrieval_eval-0.1.0/spec/fixtures/nothing-scored/run.jsonl +1 -0
  31. retrieval_eval-0.1.0/spec/fixtures/qrels/beir.tsv +4 -0
  32. retrieval_eval-0.1.0/spec/fixtures/qrels/expected.json +14 -0
  33. retrieval_eval-0.1.0/spec/fixtures/qrels/trec.qrels +4 -0
  34. retrieval_eval-0.1.0/spec/fixtures/strata/expected.json +40 -0
  35. retrieval_eval-0.1.0/spec/fixtures/strata/judgments.jsonl +5 -0
  36. retrieval_eval-0.1.0/spec/fixtures/strata/run.jsonl +5 -0
  37. retrieval_eval-0.1.0/spec/fixtures/stratum-order/expected.json +30 -0
  38. retrieval_eval-0.1.0/spec/fixtures/stratum-order/judgments.jsonl +5 -0
  39. retrieval_eval-0.1.0/spec/fixtures/stratum-order/run.jsonl +5 -0
  40. retrieval_eval-0.1.0/spec/fixtures/summarize/expected.json +53 -0
  41. retrieval_eval-0.1.0/spec/fixtures/unsorted-queries/expected.json +23 -0
  42. retrieval_eval-0.1.0/spec/fixtures/unsorted-queries/judgments.jsonl +3 -0
  43. retrieval_eval-0.1.0/spec/fixtures/unsound-judgments/expected.json +19 -0
  44. retrieval_eval-0.1.0/spec/fixtures/unsound-judgments/judgments.jsonl +3 -0
  45. retrieval_eval-0.1.0/spec/fixtures/unsound-judgments/run.jsonl +1 -0
  46. retrieval_eval-0.1.0/spec/judgments.schema.json +54 -0
  47. retrieval_eval-0.1.0/spec/report.schema.json +227 -0
  48. retrieval_eval-0.1.0/src/retrieval_eval/__init__.py +114 -0
  49. retrieval_eval-0.1.0/src/retrieval_eval/cli.py +430 -0
  50. retrieval_eval-0.1.0/src/retrieval_eval/drift.py +265 -0
  51. retrieval_eval-0.1.0/src/retrieval_eval/gate.py +213 -0
  52. retrieval_eval-0.1.0/src/retrieval_eval/help_text.py +168 -0
  53. retrieval_eval-0.1.0/src/retrieval_eval/identity.py +57 -0
  54. retrieval_eval-0.1.0/src/retrieval_eval/judgments.py +300 -0
  55. retrieval_eval-0.1.0/src/retrieval_eval/metrics.py +426 -0
  56. retrieval_eval-0.1.0/src/retrieval_eval/models.py +219 -0
  57. retrieval_eval-0.1.0/src/retrieval_eval/py.typed +0 -0
  58. retrieval_eval-0.1.0/src/retrieval_eval/qrels.py +106 -0
  59. retrieval_eval-0.1.0/src/retrieval_eval/report.py +211 -0
  60. retrieval_eval-0.1.0/src/retrieval_eval/ui.py +71 -0
  61. retrieval_eval-0.1.0/tests/test_cli.py +231 -0
  62. retrieval_eval-0.1.0/tests/test_conformance.py +738 -0
@@ -0,0 +1,20 @@
1
+ node_modules/
2
+ dist/
3
+ coverage/
4
+ .coverage
5
+ *.tsbuildinfo
6
+ __pycache__/
7
+ *.py[cod]
8
+ .venv/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .mypy_cache/
12
+ build/
13
+ *.egg-info/
14
+ .turbo/
15
+ .DS_Store
16
+ .claude/
17
+
18
+ # generated by scripts/sync-spec.mjs -- the canonical copy is /spec
19
+ packages/retrieval-eval/spec/
20
+ python/retrieval-eval/spec/
@@ -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.
@@ -0,0 +1,372 @@
1
+ Metadata-Version: 2.5
2
+ Name: retrieval-eval
3
+ Version: 0.1.0
4
+ Summary: Your RAG test suite decays every time you re-chunk. Drift detection that tells you which relevance labels are still true after a chunker or corpus change and re-anchors the ones it can, plus deterministic retrieval metrics and a portable, TREC qrels-compatible judgment format.
5
+ Project-URL: Homepage, https://github.com/aton-of-data/retrieval-eval
6
+ Project-URL: Repository, https://github.com/aton-of-data/retrieval-eval
7
+ Project-URL: Issues, https://github.com/aton-of-data/retrieval-eval/issues
8
+ Project-URL: Changelog, https://github.com/aton-of-data/retrieval-eval/blob/main/CHANGELOG.md
9
+ Author: retrieval-eval contributors
10
+ License: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: chunking,drift,embeddings,evaluation,golden-dataset,information-retrieval,label-drift,llm,map,mrr,ndcg,precision,qrels,rag,rag-evaluation,recall,regression-testing,reranking,retrieval,trec,vector-search
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Text Processing :: Indexing
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Provides-Extra: dev
27
+ Requires-Dist: mypy>=1.13; extra == 'dev'
28
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
29
+ Requires-Dist: pytest>=8.3; extra == 'dev'
30
+ Requires-Dist: ruff>=0.7; extra == 'dev'
31
+ Description-Content-Type: text/markdown
32
+
33
+ <div align="center">
34
+
35
+ # retrieval-eval
36
+
37
+ **Every re-chunk quietly invalidates part of your RAG test suite.<br>
38
+ `retrieval-eval` tells you which labels are still true, and repairs the ones it can.**
39
+
40
+ Label drift detection · deterministic retrieval metrics · a portable, qrels-compatible judgment format<br>
41
+ Zero dependencies · no API key · TypeScript and Python
42
+
43
+ [![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)
44
+ [![npm](https://img.shields.io/npm/v/retrieval-eval?logo=npm&color=cb3837)](https://www.npmjs.com/package/retrieval-eval)
45
+ [![PyPI](https://img.shields.io/pypi/v/retrieval-eval?logo=pypi&logoColor=white&color=3775a9)](https://pypi.org/project/retrieval-eval/)
46
+ [![zero dependencies](https://img.shields.io/badge/runtime%20deps-0-brightgreen)](#why-zero-dependencies)
47
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/aton-of-data/retrieval-eval/blob/main/LICENSE)
48
+
49
+ </div>
50
+
51
+ ---
52
+
53
+ A retrieval test suite rests on one assumption nobody writes down: that every label still points
54
+ at the passage a human actually read. Labels are stored as chunk IDs, and chunk IDs are an
55
+ artifact of your chunker. Change the chunk size, the splitter or the overlap, and the IDs move
56
+ while the labels stay where they were. Nothing errors. The metrics keep computing, against ground
57
+ truth that is partly no longer there.
58
+
59
+ One command shows you how much:
60
+
61
+ ```bash
62
+ retrieval-eval drift --judgments judgments.jsonl --corpus corpus.json
63
+ ```
64
+
65
+ ```
66
+ 312 judgments · labeled @ fingerprint recursive/512
67
+ live corpus @ fingerprint recursive/384
68
+
69
+ ok 188 VALID chunk_id still present
70
+ ! 47 RE-ANCHORABLE text moved to a new chunk_id
71
+ ! 24 MERGED text absorbed into a coarser chunk
72
+ ! 34 SPLIT labeled text now spans 2+ chunks
73
+ x 19 ORPHANED source text or document is gone
74
+
75
+ 40% of your judgment set no longer matches the live corpus.
76
+ Any metric computed against it is measuring two changes at once.
77
+ 71 recoverable automatically · 53 need a human
78
+
79
+ next retrieval-eval drift --fix, to re-anchor the recoverable labels
80
+ ```
81
+
82
+ You changed your chunker. Your `recall@5` moved 0.06. You credited the change.
83
+
84
+ But 40% of your labels no longer point at the text a human actually read. Part of that movement
85
+ was your test suite decaying, not your retriever improving, and no other evaluation tool will
86
+ tell you which part.
87
+
88
+ `retrieval-eval` separates them, then recovers the labels it can:
89
+
90
+ ```bash
91
+ retrieval-eval drift --judgments judgments.jsonl --corpus corpus.json --fix
92
+ # fixed re-anchored 71 label(s) in judgments.jsonl
93
+ # review 53 label(s) still need a human
94
+ ```
95
+
96
+ `RE_ANCHORABLE` and `MERGED` are recoverable: the text a human judged is still there, either as
97
+ its own chunk or inside a bigger one. `SPLIT` and `ORPHANED` are left alone on purpose, because
98
+ guessing at them would fabricate ground truth, which is the exact failure this tool exists to
99
+ expose.
100
+
101
+ > **See it happen in 30 seconds.** [`examples/quickstart`](https://github.com/aton-of-data/retrieval-eval/tree/main/examples/quickstart) runs a corpus
102
+ > whose text never changes, re-chunks it, and watches `recall@3` fall from 1.00 to 0.00 while
103
+ > retrieval stays perfect, then brings it back with `--fix`. Six more runnable scenarios, the
104
+ > integration for eight stacks, and complete CI jobs are in [`examples/`](https://github.com/aton-of-data/retrieval-eval/tree/main/examples).
105
+
106
+ ## Why this matters
107
+
108
+ A golden set is the most expensive thing in a RAG project. Every label is a person reading a
109
+ passage and deciding whether it answers a question. Yet it is the one artifact nothing checks.
110
+ Retrievers get versioned, prompts get diffed, embedding models get benchmarked, and the labels
111
+ underneath all of them are treated as permanent. They are coordinates into one particular
112
+ chunking, and every chunking change moves the map.
113
+
114
+ The damage is quiet, and it points the wrong way. A chunker that genuinely retrieves better can
115
+ score worse, because its correct answers now live under IDs the labels have never seen. A real
116
+ improvement and the decay it caused can cancel out and read as no change at all. Either way, the
117
+ number you gate releases on is measuring two things at once, and nothing tells you how much of
118
+ each.
119
+
120
+ Teams that notice end up with three bad options: relabel from scratch, stop trusting the suite,
121
+ or stop changing the chunker. `drift` is a fourth. It names exactly which labels moved, recovers
122
+ every one whose text is provably still there, and sends only the rest to a human. After that,
123
+ your metrics are measuring your retriever again.
124
+
125
+ ## Install
126
+
127
+ ```bash
128
+ pip install retrieval-eval # or: uvx retrieval-eval --help
129
+ ```
130
+
131
+ Same name, same commands, same flags, same rendered output, same exit codes in both, so one CI
132
+ step works for a polyglot team. Node 20.11 or newer, Python 3.10 or newer.
133
+
134
+ ## What it does
135
+
136
+ **1. Keeps your labels true when the corpus changes.** Every chunk gets an identity derived from
137
+ its content, not its position ([the one idea](#the-one-idea)), so a label remembers what a human
138
+ read rather than where it used to sit. `drift` classifies every label as `VALID`,
139
+ `RE_ANCHORABLE`, `MERGED`, `SPLIT` or `ORPHANED`, `--fix` repairs the two recoverable classes in
140
+ place, and the command exits non-zero on decay, so a re-chunk cannot ship with a stale suite
141
+ behind it. Run it before `score`, in CI, on every chunking change.
142
+
143
+ **2. Measures retrieval, deterministically.** `precision@k`, `recall@k`, `ndcg@k`, `mrr@k`, `map@k`,
144
+ `hit_rate@k`. Every metric carries its cutoff in its name, because a number that means
145
+ 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.
146
+
147
+ These are the metrics that localize a failure. High `recall@20` with low `recall@5` means
148
+ retrieval found the answer and ranking buried it, so the reranker is the problem rather than the
149
+ chunker. A single end-to-end score cannot make that distinction.
150
+
151
+ ```bash
152
+ retrieval-eval score --judgments judgments.jsonl --run hits.jsonl -k 5 \
153
+ --baseline .retrieval-eval/baseline.json \
154
+ --gate recall@5:-0.02 \
155
+ --gate worst-stratum:recall@5:0.7
156
+ ```
157
+
158
+ **3. Refuses to let an average hide a broken query class.**
159
+
160
+ ```
161
+ recall@3 by stratum
162
+ · legal 0.0000 ░░░░░░░░ n=2 worst
163
+ · billing 1.0000 ████████ n=3
164
+
165
+ gates
166
+ ok recall@3:0.5
167
+ x worst-stratum:recall@3:0.7
168
+ ```
169
+
170
+ Overall recall is 0.60 and passes an average gate. Legal queries retrieve nothing. That is why
171
+ `stratum` is a field in the format, `per_stratum` is mandatory in the report, and worst-stratum
172
+ gating is a first-class gate.
173
+
174
+ **4. Speaks TREC qrels, so thirty years of tooling just works.**
175
+
176
+ ```bash
177
+ retrieval-eval convert --judgments judgments.jsonl --to qrels | trec_eval -m all_trec - run.txt
178
+ retrieval-eval convert --qrels beir/scifact/qrels/test.tsv --to judgments > judgments.jsonl
179
+ ```
180
+
181
+ A judgments file is a strict superset of qrels, so `trec_eval`, `ir_measures`, `pytrec_eval`,
182
+ BEIR and `ir_datasets` are all one conversion away in either direction.
183
+
184
+ **5. Tells you when a judgment set is unsound**, not merely malformed:
185
+
186
+ ```
187
+ warning [no-human-labels] every label is synthetic. Without human labels you cannot measure
188
+ judge calibration, and synthetic labels quietly become ground truth
189
+ warning [mixed-fingerprints] judgments span 2 corpus fingerprints; run 'drift' first
190
+ warning [thin-stratum] stratum 'legal' has only 2 labels, too few to gate on
191
+ error [no-positives] no judgment has relevance >= 1, so recall is undefined
192
+ ```
193
+
194
+ ## The one idea
195
+
196
+ Give every chunk an identity derived from its **content**, not its position:
197
+
198
+ ```
199
+ chunk_id = "c1:" + sha256(doc_uri ␟ doc_revision ␟ ordinal ␟ normalize(text) ␟ chunker_fingerprint)[0..16]
200
+ # 128 bits, written as 32 lowercase hex characters
201
+ ```
202
+
203
+ A label then points at text a human read, so after a re-chunk the tool can say exactly which
204
+ labels survived.
205
+
206
+ 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
207
+ afternoon in any language. If it ever needs a framework, it has failed. It ships inside both
208
+ packages, so a port never has to start from the GitHub UI.
209
+
210
+ ## What this removes
211
+
212
+ Each row is a situation teams are already in.
213
+
214
+ | Situation | What breaks today | What changes |
215
+ |---|---|---|
216
+ | Chunker changed and a metric moved | the whole movement is credited to the retriever | drift separates label decay from retrieval change |
217
+ | 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 |
218
+ | Golden set built in one evaluation tool, team adopts another | labels are rebuilt by hand or abandoned | one conversion, labels outlive the tool |
219
+ | Public collection in TREC qrels, product written in TypeScript | no path into the ecosystem | one conversion, then scored locally |
220
+ | Gate on an aggregate metric | a whole query class can fail silently | worst-stratum gate fails the build |
221
+ | Judged metric gated on a single sample | a non-deterministic instrument reported as a point estimate | confidence interval, plus an `INDETERMINATE` verdict |
222
+ | Synthetic labels accumulating over time | they become ground truth without anyone deciding that | `labeled_by` is required, and `validate` warns |
223
+ | Evaluation platform priced per run | build gates get rationed to stay inside a tier | no model call, no API key, no per-run cost |
224
+ | Evaluation tooling added to a CI image | a dependency tree makes the step slow or fragile | standard library only, in both languages |
225
+
226
+ ## Use it as a library
227
+
228
+ ```ts
229
+ import { drift, score, chunkId, toQrels } from "retrieval-eval";
230
+
231
+ const result = drift(judgments, corpus);
232
+ if (result.summary.invalid_ratio > 0.1) throw new Error("golden set has decayed");
233
+
234
+ const { metrics } = score(judgments, run, { k: 5 });
235
+ metrics["recall@5"].value;
236
+ ```
237
+
238
+ ```python
239
+ from retrieval_eval import drift, score, chunk_id, to_qrels
240
+
241
+ result = drift(judgments, corpus)
242
+ if result.summary.invalid_ratio > 0.1:
243
+ raise RuntimeError("golden set has decayed")
244
+
245
+ scored = score(judgments, run, k=5)
246
+ scored.metrics["recall@5"].value
247
+ ```
248
+
249
+ ## In CI
250
+
251
+ ```yaml
252
+ - run: pip install retrieval-eval
253
+ - run: retrieval-eval drift --judgments eval/judgments.jsonl --corpus eval/corpus.json
254
+ - run: |
255
+ retrieval-eval score \
256
+ --judgments eval/judgments.jsonl --run eval/hits.jsonl -k 5 \
257
+ --baseline eval/baseline.json \
258
+ --gate recall@5:-0.02 --gate worst-stratum:recall@5:0.7 \
259
+ --out report.json
260
+ ```
261
+
262
+ Exit `0` passed, exit `1` a gate failed or labels decayed, exit `2` bad invocation or unreadable
263
+ input. `drift` exits non-zero on its own, so it works as a standalone check.
264
+
265
+ 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).
266
+
267
+ ## Why this does not already exist
268
+
269
+ Every evaluation tool scores against a golden set. None of them checks whether the golden set
270
+ still describes the corpus. RAGAS, DeepEval, promptfoo and the IR toolkits all store a label as
271
+ a pointer and trust it forever, because no shared format records which corpus revision or which
272
+ chunker a label was made against. Without that, drift is not merely unreported, it is
273
+ unmeasurable. The judgment format here adds exactly the fields that make it measurable, and
274
+ `drift` is the algorithm that uses them.
275
+
276
+ 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
277
+ first, `ndcg`, `ir-measures`, `trec-eval` and `qrels`, are unpublished, and what does exist is
278
+ thin: [`node-dcg`](https://www.npmjs.com/package/node-dcg) computes DCG alone and was last
279
+ published in 2023, [`trec-eval-wrapper`](https://www.npmjs.com/package/trec-eval-wrapper) shells
280
+ out to the `trec_eval` C binary rather than implementing anything and was last published in 2022,
281
+ and the recent entries are coupled to something else, an MCP server or a recommender engine's own
282
+ core package.
283
+
284
+ So there are two gaps, in order of importance: **nothing in either ecosystem treats judgment
285
+ drift as a measurable condition**, and **no maintained, standalone, dependency-free IR
286
+ evaluation library exists for JavaScript**. The evidence, including the
287
+ two claims this research falsified against its own earlier draft, is in
288
+ [research/](https://github.com/aton-of-data/retrieval-eval/tree/main/research/).
289
+
290
+ *(Registry state checked 2026-09-22. If this has changed, the claim is wrong and belongs in an
291
+ issue. Accuracy about our own positioning is part of the point.)*
292
+
293
+ ## It is not a replacement for judged evaluation
294
+
295
+ Retrieval quality is a large share of end-to-end RAG quality, not all of it. The rest is how well
296
+ the model uses what it retrieved. This covers the retrieval half rigorously and deliberately does
297
+ not claim to certify a RAG system.
298
+
299
+ Use it alongside RAGAS, DeepEval, promptfoo, Phoenix or Braintrust rather than instead of them. It
300
+ makes their golden sets portable and durable, which is why interoperability is the strategy rather
301
+ than a feature.
302
+
303
+ For the judged half, the report format carries the honesty those metrics need, and `summarize()`
304
+ computes it: `n`, `stdev` and a confidence interval from repeated samples of the same judge, plus
305
+ a third verdict, `INDETERMINATE`. LLM judges are non-deterministic even at temperature 0, so a
306
+ `ci-lower` gate on a single sample says "I do not know" rather than guessing.
307
+
308
+ ```python
309
+ report.metrics["faithfulness"] = summarize([0.8, 1.0, 0.6, 0.9, 0.7])
310
+ # value 0.8000, stdev 0.1581, 95% interval [0.6037, 0.9963]
311
+ # the mean clears a 0.8 floor; the interval says you cannot tell yet
312
+ ```
313
+
314
+ [`examples/judged-metrics`](https://github.com/aton-of-data/retrieval-eval/tree/main/examples/judged-metrics) runs that end to end in both languages.
315
+
316
+ ## Why zero dependencies
317
+
318
+ Both packages use only their standard library: `sha256` and JSON. A measurement tool that drags in
319
+ a dependency tree becomes a thing you skip installing in CI. It also keeps the spec implementable
320
+ anywhere, which is the point of a spec.
321
+
322
+ ## Status
323
+
324
+ **0.1.0, alpha.** The formats and the metric mathematics are what we intend to keep. The CLI
325
+ surface may still move. The `c1:` and `t1:` hash prefixes exist so identity can be versioned
326
+ without breaking existing judgment files.
327
+
328
+ What is already load-bearing, and enforced on every commit:
329
+
330
+ - **Parity.** Both implementations run the same `spec/fixtures` through both CLIs and must agree
331
+ on the numbers, the rendered output, the help text and the exit codes. Not two test suites that
332
+ each pass, one job that runs both and diffs the result.
333
+ - **Determinism.** Same inputs, same output, every run. No network, no model, no clock in the
334
+ numbers. Across the two implementations: rendered output and judgments files are byte-identical,
335
+ and `--json` agrees as data rather than as bytes, because JSON writes a whole number as `1` in
336
+ JavaScript and `1.0` in Python. Compare reports by parsing them, not by checksum.
337
+ - **A quickstart that is executed, not described.** CI runs the README's own first-run path on a
338
+ clean checkout on Linux and macOS, and asserts the demo still demonstrates its claim.
339
+
340
+ ## Repo layout
341
+
342
+ ```
343
+ spec/ the contract: 2 schemas, 1 hash definition, shared fixtures
344
+ fixtures/ conformance cases BOTH implementations must pass
345
+ packages/retrieval-eval/ TypeScript (tsup · vitest · biome)
346
+ python/retrieval-eval/ Python (hatchling · pytest · ruff · mypy --strict)
347
+ docs/ CLI reference, CI recipes, interop, troubleshooting
348
+ examples/ runnable scenarios, stack integrations, pipeline jobs
349
+ frameworks/ LangChain, LlamaIndex, Haystack, Chroma, Qdrant, pgvector, RAGAS, DeepEval
350
+ pipelines/ Jenkins, GitHub Actions, GitLab, Azure, CircleCI, pre-commit
351
+ research/ the evidence behind the design
352
+ ```
353
+
354
+ Python and TypeScript are peers, not ports. Both read the same `spec/fixtures` and must agree to
355
+ the twelfth decimal, which is what makes "parity by spec" a claim rather than a slogan.
356
+
357
+ ## Docs
358
+
359
+ | | |
360
+ |---|---|
361
+ | [docs/cli.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/cli.md) | every command, flag, exit code and output mode |
362
+ | [docs/ci.md](https://github.com/aton-of-data/retrieval-eval/blob/main/docs/ci.md) | pipeline recipes and how to keep a baseline |
363
+ | [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 |
364
+ | [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 |
365
+ | [spec/](https://github.com/aton-of-data/retrieval-eval/tree/main/spec/) | the formats, the hash, the fixtures |
366
+ | [examples/](https://github.com/aton-of-data/retrieval-eval/tree/main/examples) | seven runnable scenarios, eight stack integrations, seven pipeline jobs |
367
+ | [research/](https://github.com/aton-of-data/retrieval-eval/tree/main/research/) | the problem, the market gap, and the impact argument |
368
+ | [CONTRIBUTING.md](https://github.com/aton-of-data/retrieval-eval/blob/main/CONTRIBUTING.md) | add a metric, add an adapter, port the spec |
369
+
370
+ ## License
371
+
372
+ Apache-2.0