hev-rerank 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.
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ dist/
4
+ *.egg-info/
5
+ .claude/
@@ -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,122 @@
1
+ Metadata-Version: 2.5
2
+ Name: hev-rerank
3
+ Version: 0.1.0
4
+ Summary: Use Jev (TypeSafe's System One model) as a calibrated reranker: one call, up to 30 documents, a probability per document.
5
+ Project-URL: Repository, https://github.com/hev/jev-rerank
6
+ Project-URL: Results, https://github.com/hev/jev-rerank/blob/main/RESULTS.md
7
+ Author: Adam Hevenor
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: jev,rag,reranker,retrieval,search,typesafe
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Text Processing :: Indexing
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: pyyaml>=6
18
+ Requires-Dist: typesafe-sdk>=0.6
19
+ Provides-Extra: examples
20
+ Requires-Dist: rank-bm25; extra == 'examples'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # hev-rerank
24
+
25
+ Use [Jev](https://docs.typesafe.ai), TypeSafe's System One decision model, as a reranker.
26
+ One call carries the query and up to 30 candidate documents; the model answers one
27
+ question per document, in parallel: *is this document relevant to the query?* The answer is
28
+ a calibrated probability, so the score is both a sort key (rerank) and an absolute
29
+ threshold (prune).
30
+
31
+ This repo is the whole recipe: the [prompt](hev_rerank/prompt.yaml), the request
32
+ [state shape](schema/state.schema.json), a 90-line Python wrapper, and the
33
+ [results](RESULTS.md) of running it against hosted and open-weight rerankers and LLM
34
+ judges on BEIR shortlists.
35
+
36
+ ## Results
37
+
38
+ nDCG@10, every system permuting the same BM25 top-30 shortlist per query. Jev uses the
39
+ domain-neutral phrasing in `prompt.yaml`, untuned per corpus.
40
+
41
+ | Reranker | SciFact (300 q) | NFCorpus (323 q) | FiQA (300 q) | p50 / p95 per query | Cost per 300 q |
42
+ |---|---|---|---|---|---|
43
+ | BM25 order, no rerank | 0.667 | 0.310 | 0.234 | | |
44
+ | MiniLM-L6 cross-encoder (local) | 0.682 | 0.336 | 0.323 | | |
45
+ | Cohere rerank-v3.5 | 0.745 | 0.340 | 0.374 | 129–277 ms / 267–698 ms | $0.60 |
46
+ | Mixedbread mxbai-rerank-large-v2 (hosted) | 0.749 | 0.324 | 0.354 | 322–380 ms / 374–460 ms | $1.05 |
47
+ | Voyage rerank-2.5 | 0.755 | 0.357 | 0.395 | 177–187 ms / 255–300 ms | ~$0.15 |
48
+ | Voyage rerank-3 | 0.755 | 0.357 | 0.402 | 173–192 ms / 285–288 ms | ~$0.15 |
49
+ | gpt-5.6-luna (reasoning off), listwise | 0.747 | 0.355 | 0.363 | 3.1–3.2 s / 3.8–5.8 s | ~$0.71 |
50
+ | Claude Haiku 4.5, listwise | 0.723 | | | 2.9 s / 11.6 s | $4.18 |
51
+ | Claude Opus 5 (low effort), listwise | 0.756 | | | 5.0 s / 7.5 s | $28.40 |
52
+ | **Jev, 30 Nouls in one state** | **0.768** | **0.358** | 0.376 | 208–238 ms / 0.8–1.8 s | $0.13–0.19 |
53
+ | Jev, one Noul per (query, doc) pair | 0.772 | 0.358 | 0.376 | 122–144 ms per call | $0.23–0.30 |
54
+
55
+ Paired-bootstrap per query, Jev's one-state shape against each reranker: at or above Cohere on
56
+ all three corpora (two wins, one tie); above Mixedbread (two wins, one interval touching zero);
57
+ trading with Voyage, the strongest purpose-built reranker here (edge on SciFact, tie on NFCorpus,
58
+ loss on FiQA by ~0.02); above every LLM used as a reranker on cost and latency, and on quality
59
+ except Opus 5, which it ties at ~1/100 the cost.
60
+
61
+ The honest one-liner: a general decision model with no reranker training lands in the same
62
+ quality and price bracket as the best purpose-built rerankers, a third of Cohere's price, and
63
+ returns a calibrated probability per document that none of them do. Voyage rerank-3 is as
64
+ good and slightly cheaper; what Jev adds over it is the probability and the fact that the same
65
+ call shape covers routing, classification and extraction gating.
66
+
67
+ Costs are the runs' actual token usage at list price (Voyage measured from its billed
68
+ `usage.total_tokens`). Full tables, confidence intervals, determinism, position-bias and
69
+ calibration checks: [RESULTS.md](RESULTS.md).
70
+
71
+ ## Install
72
+
73
+ ```sh
74
+ pip install hev-rerank # or: uv add hev-rerank
75
+ export TYPESAFE_API_KEY=... # https://console.typesafe.ai/settings/keys
76
+ ```
77
+
78
+ ## Use
79
+
80
+ ```python
81
+ from hev_rerank import rerank
82
+
83
+ hits = rerank(
84
+ "does vitamin D supplementation improve bone density in older adults",
85
+ [{"title": t, "text": x} for t, x in first_stage_results], # strings work too
86
+ top_n=10, # optional
87
+ threshold=0.1, # optional: drop candidates the model is confident are irrelevant
88
+ )
89
+ for h in hits:
90
+ print(h.score, h.index, h.document["title"])
91
+ ```
92
+
93
+ `rerank` returns `RerankResult(index, score, document)` best-first. Lists longer than
94
+ `max_docs_per_call` (30) are split into concurrent calls under Jev's ~32k-token request
95
+ budget. Scores across calls are comparable because each is an absolute probability.
96
+
97
+ ## The shape, and why
98
+
99
+ - **State**: `{"query": ..., "documents": {"D00": {...}, "D01": {...}, ...}}`
100
+ ([schema](schema/state.schema.json)).
101
+ - **Questions**: one `Noul` per document id, from [`prompt.yaml`](hev_rerank/prompt.yaml).
102
+ All questions in a request are evaluated in parallel, so 30 documents cost about the same
103
+ wall time as 5.
104
+ - **Score**: the Noul probability. Calibration on the SciFact run: documents scored ≥ 0.9
105
+ were judged relevant 76% of the time; documents scored < 0.1, 0.5% of the time.
106
+
107
+ Why not one `Choice` over the documents? It is slightly better when exactly one document is
108
+ relevant (SciFact: +0.01 nDCG@10, +3 pts P@1) and much worse when many are (NFCorpus,
109
+ median 16 relevant per query: 0.316 vs 0.358). A reranker that does not know the corpus
110
+ should ask per-document Nouls.
111
+
112
+ ## Limits
113
+
114
+ - ~32k tokens per request (state + questions): ~30–50 typical passages per call.
115
+ - Rate limits are undocumented; sustained 429s appeared at ~24 requests in flight.
116
+ - Tail latency on 30-document states (p95 0.8–1.8 s) is higher than specialized hosted
117
+ rerankers'. Fanning out per-pair calls trades 30× the calls for a p95 near 0.25 s per call.
118
+ - Hosted only; the data leaves your environment.
119
+
120
+ ## License
121
+
122
+ Apache-2.0.
@@ -0,0 +1,100 @@
1
+ # hev-rerank
2
+
3
+ Use [Jev](https://docs.typesafe.ai), TypeSafe's System One decision model, as a reranker.
4
+ One call carries the query and up to 30 candidate documents; the model answers one
5
+ question per document, in parallel: *is this document relevant to the query?* The answer is
6
+ a calibrated probability, so the score is both a sort key (rerank) and an absolute
7
+ threshold (prune).
8
+
9
+ This repo is the whole recipe: the [prompt](hev_rerank/prompt.yaml), the request
10
+ [state shape](schema/state.schema.json), a 90-line Python wrapper, and the
11
+ [results](RESULTS.md) of running it against hosted and open-weight rerankers and LLM
12
+ judges on BEIR shortlists.
13
+
14
+ ## Results
15
+
16
+ nDCG@10, every system permuting the same BM25 top-30 shortlist per query. Jev uses the
17
+ domain-neutral phrasing in `prompt.yaml`, untuned per corpus.
18
+
19
+ | Reranker | SciFact (300 q) | NFCorpus (323 q) | FiQA (300 q) | p50 / p95 per query | Cost per 300 q |
20
+ |---|---|---|---|---|---|
21
+ | BM25 order, no rerank | 0.667 | 0.310 | 0.234 | | |
22
+ | MiniLM-L6 cross-encoder (local) | 0.682 | 0.336 | 0.323 | | |
23
+ | Cohere rerank-v3.5 | 0.745 | 0.340 | 0.374 | 129–277 ms / 267–698 ms | $0.60 |
24
+ | Mixedbread mxbai-rerank-large-v2 (hosted) | 0.749 | 0.324 | 0.354 | 322–380 ms / 374–460 ms | $1.05 |
25
+ | Voyage rerank-2.5 | 0.755 | 0.357 | 0.395 | 177–187 ms / 255–300 ms | ~$0.15 |
26
+ | Voyage rerank-3 | 0.755 | 0.357 | 0.402 | 173–192 ms / 285–288 ms | ~$0.15 |
27
+ | gpt-5.6-luna (reasoning off), listwise | 0.747 | 0.355 | 0.363 | 3.1–3.2 s / 3.8–5.8 s | ~$0.71 |
28
+ | Claude Haiku 4.5, listwise | 0.723 | | | 2.9 s / 11.6 s | $4.18 |
29
+ | Claude Opus 5 (low effort), listwise | 0.756 | | | 5.0 s / 7.5 s | $28.40 |
30
+ | **Jev, 30 Nouls in one state** | **0.768** | **0.358** | 0.376 | 208–238 ms / 0.8–1.8 s | $0.13–0.19 |
31
+ | Jev, one Noul per (query, doc) pair | 0.772 | 0.358 | 0.376 | 122–144 ms per call | $0.23–0.30 |
32
+
33
+ Paired-bootstrap per query, Jev's one-state shape against each reranker: at or above Cohere on
34
+ all three corpora (two wins, one tie); above Mixedbread (two wins, one interval touching zero);
35
+ trading with Voyage, the strongest purpose-built reranker here (edge on SciFact, tie on NFCorpus,
36
+ loss on FiQA by ~0.02); above every LLM used as a reranker on cost and latency, and on quality
37
+ except Opus 5, which it ties at ~1/100 the cost.
38
+
39
+ The honest one-liner: a general decision model with no reranker training lands in the same
40
+ quality and price bracket as the best purpose-built rerankers, a third of Cohere's price, and
41
+ returns a calibrated probability per document that none of them do. Voyage rerank-3 is as
42
+ good and slightly cheaper; what Jev adds over it is the probability and the fact that the same
43
+ call shape covers routing, classification and extraction gating.
44
+
45
+ Costs are the runs' actual token usage at list price (Voyage measured from its billed
46
+ `usage.total_tokens`). Full tables, confidence intervals, determinism, position-bias and
47
+ calibration checks: [RESULTS.md](RESULTS.md).
48
+
49
+ ## Install
50
+
51
+ ```sh
52
+ pip install hev-rerank # or: uv add hev-rerank
53
+ export TYPESAFE_API_KEY=... # https://console.typesafe.ai/settings/keys
54
+ ```
55
+
56
+ ## Use
57
+
58
+ ```python
59
+ from hev_rerank import rerank
60
+
61
+ hits = rerank(
62
+ "does vitamin D supplementation improve bone density in older adults",
63
+ [{"title": t, "text": x} for t, x in first_stage_results], # strings work too
64
+ top_n=10, # optional
65
+ threshold=0.1, # optional: drop candidates the model is confident are irrelevant
66
+ )
67
+ for h in hits:
68
+ print(h.score, h.index, h.document["title"])
69
+ ```
70
+
71
+ `rerank` returns `RerankResult(index, score, document)` best-first. Lists longer than
72
+ `max_docs_per_call` (30) are split into concurrent calls under Jev's ~32k-token request
73
+ budget. Scores across calls are comparable because each is an absolute probability.
74
+
75
+ ## The shape, and why
76
+
77
+ - **State**: `{"query": ..., "documents": {"D00": {...}, "D01": {...}, ...}}`
78
+ ([schema](schema/state.schema.json)).
79
+ - **Questions**: one `Noul` per document id, from [`prompt.yaml`](hev_rerank/prompt.yaml).
80
+ All questions in a request are evaluated in parallel, so 30 documents cost about the same
81
+ wall time as 5.
82
+ - **Score**: the Noul probability. Calibration on the SciFact run: documents scored ≥ 0.9
83
+ were judged relevant 76% of the time; documents scored < 0.1, 0.5% of the time.
84
+
85
+ Why not one `Choice` over the documents? It is slightly better when exactly one document is
86
+ relevant (SciFact: +0.01 nDCG@10, +3 pts P@1) and much worse when many are (NFCorpus,
87
+ median 16 relevant per query: 0.316 vs 0.358). A reranker that does not know the corpus
88
+ should ask per-document Nouls.
89
+
90
+ ## Limits
91
+
92
+ - ~32k tokens per request (state + questions): ~30–50 typical passages per call.
93
+ - Rate limits are undocumented; sustained 429s appeared at ~24 requests in flight.
94
+ - Tail latency on 30-document states (p95 0.8–1.8 s) is higher than specialized hosted
95
+ rerankers'. Fanning out per-pair calls trades 30× the calls for a p95 near 0.25 s per call.
96
+ - Hosted only; the data leaves your environment.
97
+
98
+ ## License
99
+
100
+ Apache-2.0.
@@ -0,0 +1,78 @@
1
+ # Jev as a reranker — benchmark results
2
+
3
+ Generated 2026-09-17. Jev model jev-1.13.0.
4
+
5
+ BM25 top-K shortlist per query (rank_bm25, stopworded), every reranker permutes the same shortlist. nDCG@10 via ir_measures. Latency is per query (one API call for the single-state shapes; per pair call for the pair shape). Cost is the run's actual token usage at list price ($0.042/M input for Jev; Cohere $2/1k searches; Claude list prices).
6
+
7
+ ## scifact / test — 300 queries
8
+
9
+ | system | nDCG@10 | P@1 | MRR@10 | p50 | p95 | cost/run |
10
+ |---|---|---|---|---|---|---|
11
+ | jev_pair_generic | 0.772 | 0.710 | 0.756 | 122 ms | 236 ms | $0.28 |
12
+ | jev_batch_generic | 0.768 | 0.697 | 0.749 | 224 ms | 1758 ms | $0.18 |
13
+ | jev_choice | 0.762 | 0.710 | 0.754 | | | |
14
+ | jev_choice_generic | 0.760 | 0.693 | 0.746 | 192 ms | 1621 ms | $0.15 |
15
+ | llm_opus5_low | 0.756 | 0.683 | 0.740 | 4950 ms | 7473 ms | $28.40 |
16
+ | jev_batch | 0.756 | 0.683 | 0.739 | | | |
17
+ | jev_pair | 0.755 | 0.680 | 0.740 | | | |
18
+ | rerank_voyage | 0.755 | 0.657 | 0.734 | 187 ms | 286 ms | $0.21 |
19
+ | rerank_voyage3 | 0.755 | 0.660 | 0.734 | 192 ms | 288 ms | $0.21 |
20
+ | rerank_mixedbread | 0.749 | 0.670 | 0.731 | 379 ms | 460 ms | $1.05 |
21
+ | llm_gpt56_luna_none | 0.747 | 0.653 | 0.729 | 3223 ms | 5824 ms | $0.71 |
22
+ | rerank_cohere | 0.745 | 0.660 | 0.728 | 277 ms | 698 ms | $0.60 |
23
+ | llm_haiku45 | 0.723 | 0.633 | 0.701 | 2899 ms | 11562 ms | $4.18 |
24
+ | local_mxbai-rerank-base-v1 | 0.716 | 0.633 | 0.693 | 8148 ms | 9933 ms | |
25
+ | local_ms-marco-MiniLM-L-6-v2 | 0.682 | 0.570 | 0.653 | 211 ms | 242 ms | |
26
+ | bm25 | 0.667 | 0.540 | 0.634 | | | |
27
+
28
+ ## scifact / train — 300 queries
29
+
30
+ | system | nDCG@10 | P@1 | MRR@10 | p50 | p95 | cost/run |
31
+ |---|---|---|---|---|---|---|
32
+ | jev_choice_generic | 0.776 | 0.713 | 0.766 | 253 ms | 1157 ms | $0.26 |
33
+ | jev_batch_generic | 0.774 | 0.683 | 0.751 | 298 ms | 1721 ms | $0.30 |
34
+ | jev_pair_generic | 0.773 | 0.673 | 0.754 | 117 ms | 221 ms | $0.28 |
35
+ | jev_pair | 0.767 | 0.693 | 0.740 | 126 ms | 239 ms | $0.28 |
36
+ | jev_choice | 0.756 | 0.690 | 0.747 | 202 ms | 1657 ms | $0.16 |
37
+ | jev_batch | 0.752 | 0.667 | 0.732 | 242 ms | 1738 ms | $0.18 |
38
+ | ce_minilm | 0.708 | 0.573 | 0.671 | | | |
39
+ | bm25 | 0.670 | 0.567 | 0.640 | | | |
40
+
41
+ ## nfcorpus / test — 323 queries
42
+
43
+ | system | nDCG@10 | P@1 | MRR@10 | p50 | p95 | cost/run |
44
+ |---|---|---|---|---|---|---|
45
+ | jev_batch_generic | 0.358 | 0.511 | 0.581 | 238 ms | 1716 ms | $0.19 |
46
+ | jev_pair_generic | 0.358 | 0.523 | 0.590 | 144 ms | 295 ms | $0.30 |
47
+ | rerank_voyage3 | 0.357 | 0.514 | 0.587 | 191 ms | 285 ms | $0.23 |
48
+ | rerank_voyage | 0.357 | 0.517 | 0.584 | 183 ms | 300 ms | $0.23 |
49
+ | llm_gpt56_luna_none | 0.355 | 0.508 | 0.589 | 3062 ms | 4521 ms | $0.76 |
50
+ | rerank_cohere | 0.339 | 0.483 | 0.561 | 170 ms | 404 ms | $0.65 |
51
+ | ce_minilm | 0.336 | 0.492 | 0.567 | | | |
52
+ | rerank_mixedbread | 0.324 | 0.424 | 0.528 | 380 ms | 452 ms | $1.13 |
53
+ | jev_choice_generic | 0.315 | 0.514 | 0.580 | 212 ms | 1724 ms | $0.17 |
54
+ | bm25 | 0.310 | 0.440 | 0.521 | | | |
55
+
56
+ ## fiqa / test — 300 queries
57
+
58
+ | system | nDCG@10 | P@1 | MRR@10 | p50 | p95 | cost/run |
59
+ |---|---|---|---|---|---|---|
60
+ | rerank_voyage3 | 0.402 | 0.490 | 0.522 | 173 ms | 288 ms | $0.15 |
61
+ | rerank_voyage | 0.395 | 0.483 | 0.517 | 177 ms | 255 ms | $0.15 |
62
+ | jev_pair_generic | 0.376 | 0.440 | 0.486 | 128 ms | 238 ms | $0.23 |
63
+ | jev_batch_generic | 0.376 | 0.443 | 0.483 | 208 ms | 785 ms | $0.13 |
64
+ | rerank_cohere | 0.374 | 0.430 | 0.482 | 129 ms | 267 ms | $0.60 |
65
+ | llm_gpt56_luna_none | 0.363 | 0.393 | 0.462 | 3131 ms | 3774 ms | $0.49 |
66
+ | jev_choice_generic | 0.358 | 0.420 | 0.480 | 191 ms | 772 ms | $0.10 |
67
+ | rerank_mixedbread | 0.354 | 0.380 | 0.447 | 322 ms | 374 ms | $1.05 |
68
+ | ce_minilm | 0.323 | 0.330 | 0.407 | | | |
69
+ | bm25 | 0.234 | 0.200 | 0.279 | | | |
70
+
71
+ ## Validation (scifact/test)
72
+
73
+ - Determinism: 30 batch requests re-issued, 900 Noul pairs: mean |Δ| 0.004, max 0.14, zero top-1 changes.
74
+ - Position bias: reversed candidate order, per-doc Spearman 0.83 (30-Noul state) / 0.92 (Choice); nDCG@10 within 0.005.
75
+ - Calibration (pair Nouls): p≥0.9 → 76% judged relevant; p<0.1 → 0.5%.
76
+ - Random permutation of the shortlist: nDCG@10 0.12 (floor).
77
+ - Claude Opus 5 refused 12/300 claims (safety classifier); scored as zero in the table, 0.778 with BM25 order substituted on those queries.
78
+ - Jev rate limit: two concurrent jobs (~24 in flight) drew sustained 429s; runs were serialized at 6-wide.
@@ -0,0 +1,15 @@
1
+ """First-stage BM25 over a handful of passages, then Jev reranks the shortlist."""
2
+ from rank_bm25 import BM25Okapi
3
+ from hev_rerank import rerank
4
+
5
+ passages = [
6
+ {"title": "Vitamin D and bone density", "text": "Randomised trial: supplementation raised bone mineral density in adults over 65."},
7
+ {"title": "Vitamin D sources", "text": "Dietary sources include oily fish, egg yolk and fortified milk."},
8
+ {"title": "Calcium absorption", "text": "Vitamin D increases intestinal calcium absorption; deficiency impairs it."},
9
+ {"title": "Sunscreen use", "text": "Sunscreen reduces cutaneous vitamin D synthesis only marginally in practice."},
10
+ ]
11
+ query = "does vitamin D supplementation improve bone density in older adults"
12
+ bm25 = BM25Okapi([(p["title"] + " " + p["text"]).lower().split() for p in passages])
13
+ shortlist = [passages[i] for i in sorted(range(len(passages)), key=lambda i: -bm25.get_scores(query.lower().split())[i])]
14
+ for r in rerank(query, shortlist, top_n=3, threshold=0.1):
15
+ print(f"{r.score:.2f} {r.document['title']}")
@@ -0,0 +1,4 @@
1
+ from .rerank import RerankResult, load_prompt, rerank
2
+
3
+ __all__ = ["rerank", "RerankResult", "load_prompt"]
4
+ __version__ = "0.1.0"
@@ -0,0 +1,8 @@
1
+ # The whole "prompt" for using Jev as a reranker. One Noul question per candidate document,
2
+ # all candidates in one state, evaluated in parallel by the model. Domain-neutral phrasing:
3
+ # on SciFact / NFCorpus / FiQA it matched or beat a corpus-tailored phrasing (see RESULTS.md).
4
+ version: generic-1
5
+ question: "Document `documents.{id}` is relevant to `query`: it contains information that answers or directly addresses it."
6
+ criteria:
7
+ "true": "The document contains information that answers the query or directly addresses what it asks about."
8
+ "false": "The document is only loosely related, on a similar topic, or does not address what the query asks."
@@ -0,0 +1,104 @@
1
+ """Jev (TypeSafe's System One model) as a reranker.
2
+
3
+ Shape: the query and up to `max_docs_per_call` candidate documents go into one Jev *state*;
4
+ one Noul ("is this document relevant?") question per document; every question is evaluated
5
+ in parallel by the model, so a 30-document call costs about the same wall time as a 5-document
6
+ call. The Noul is a calibrated probability, so the score is usable as an absolute relevance
7
+ threshold (prune) as well as a sort key (rerank).
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import os
12
+ from concurrent.futures import ThreadPoolExecutor
13
+ from dataclasses import dataclass
14
+ from pathlib import Path
15
+ from typing import Any, Iterable, Mapping, Sequence
16
+
17
+ import yaml
18
+ from typesafe_sdk import Noul, RetryPolicy, TypeSafeClient
19
+
20
+ PROMPT_PATH = Path(__file__).with_name("prompt.yaml")
21
+ # TypeSafe documents a ~32k-token budget per request (state + questions), ~150k characters of
22
+ # English. Keep headroom for the questions and for non-English text.
23
+ DEFAULT_MAX_STATE_CHARS = 100_000
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class RerankResult:
28
+ index: int # position in the input `documents`
29
+ score: float # Noul probability the document is relevant, 0..1
30
+ document: Any # the input document, unchanged
31
+
32
+
33
+ def load_prompt(path: str | os.PathLike[str] | None = None) -> dict:
34
+ with open(path or PROMPT_PATH) as f:
35
+ return yaml.safe_load(f)
36
+
37
+
38
+ def _doc_state(doc: Any) -> Mapping[str, Any] | str:
39
+ if isinstance(doc, str):
40
+ return doc
41
+ if isinstance(doc, Mapping):
42
+ return {k: doc[k] for k in ("title", "text", "content", "body") if k in doc} or dict(doc)
43
+ return str(doc)
44
+
45
+
46
+ def _chunk(docs: Sequence[Any], max_docs: int, max_chars: int) -> Iterable[list[int]]:
47
+ batch: list[int] = []
48
+ chars = 0
49
+ for i, d in enumerate(docs):
50
+ n = len(str(_doc_state(d)))
51
+ if batch and (len(batch) >= max_docs or chars + n > max_chars):
52
+ yield batch
53
+ batch, chars = [], 0
54
+ batch.append(i)
55
+ chars += n
56
+ if batch:
57
+ yield batch
58
+
59
+
60
+ def rerank(
61
+ query: str,
62
+ documents: Sequence[Any],
63
+ *,
64
+ top_n: int | None = None,
65
+ threshold: float | None = None,
66
+ client: TypeSafeClient | None = None,
67
+ model: str = "jev-latest",
68
+ prompt: Mapping[str, Any] | None = None,
69
+ max_docs_per_call: int = 30,
70
+ max_state_chars: int = DEFAULT_MAX_STATE_CHARS,
71
+ concurrency: int = 4,
72
+ ) -> list[RerankResult]:
73
+ """Score every document for relevance to `query` and return them best-first.
74
+
75
+ documents: strings, or mappings with `title` / `text` (extra keys are passed through
76
+ unchanged in the result but not sent to the model unless they are title/text/content/body).
77
+ top_n: keep only the best N. threshold: drop documents scoring below it (the Noul is
78
+ calibrated: on BEIR shortlists, documents under 0.1 were judged relevant ~0.5% of the time).
79
+ Long candidate lists are split into several calls, issued concurrently.
80
+ """
81
+ if not documents:
82
+ return []
83
+ p = prompt or load_prompt()
84
+ client = client or TypeSafeClient(retry=RetryPolicy(max_retries=6, backoff_max=30.0, timeout=90.0))
85
+
86
+ def score_batch(idx: list[int]) -> list[tuple[int, float]]:
87
+ ids = {f"D{j:02d}": i for j, i in enumerate(idx)}
88
+ state = {"query": query, "documents": {k: _doc_state(documents[i]) for k, i in ids.items()}}
89
+ questions = {k: Noul(instructions=p["question"].format(id=k), criteria=p["criteria"]) for k in ids}
90
+ r = client.system_one(state=state, questions=questions, model=model)
91
+ return [(ids[k], float(r.answers[k].noul)) for k in ids]
92
+
93
+ batches = list(_chunk(documents, max_docs_per_call, max_state_chars))
94
+ if len(batches) == 1:
95
+ scored = score_batch(batches[0])
96
+ else:
97
+ with ThreadPoolExecutor(concurrency) as ex:
98
+ scored = [s for part in ex.map(score_batch, batches) for s in part]
99
+
100
+ results = [RerankResult(i, s, documents[i]) for i, s in scored]
101
+ if threshold is not None:
102
+ results = [r for r in results if r.score >= threshold]
103
+ results.sort(key=lambda r: -r.score)
104
+ return results[:top_n] if top_n else results
@@ -0,0 +1,34 @@
1
+ [project]
2
+ name = "hev-rerank"
3
+ version = "0.1.0"
4
+ description = "Use Jev (TypeSafe's System One model) as a calibrated reranker: one call, up to 30 documents, a probability per document."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.10"
8
+ authors = [{ name = "Adam Hevenor" }]
9
+ keywords = ["reranker", "search", "retrieval", "jev", "typesafe", "rag"]
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: Apache Software License",
14
+ "Programming Language :: Python :: 3",
15
+ "Topic :: Text Processing :: Indexing",
16
+ ]
17
+ dependencies = ["typesafe-sdk>=0.6", "pyyaml>=6"]
18
+
19
+ [project.urls]
20
+ Repository = "https://github.com/hev/jev-rerank"
21
+ Results = "https://github.com/hev/jev-rerank/blob/main/RESULTS.md"
22
+
23
+ [project.optional-dependencies]
24
+ examples = ["rank-bm25"]
25
+
26
+ [build-system]
27
+ requires = ["hatchling"]
28
+ build-backend = "hatchling.build"
29
+
30
+ [tool.hatch.build]
31
+ exclude = [".claude/", "dist/"]
32
+
33
+ [tool.hatch.build.targets.wheel]
34
+ packages = ["hev_rerank"]
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/hev/jev-rerank/schema/result.schema.json",
4
+ "title": "Jev rerank result",
5
+ "type": "array",
6
+ "description": "Documents best-first. `score` is the Noul probability the document is relevant (calibrated, 0..1).",
7
+ "items": {
8
+ "type": "object",
9
+ "required": ["index", "score"],
10
+ "properties": {
11
+ "index": {"type": "integer", "minimum": 0, "description": "Position in the input document list."},
12
+ "score": {"type": "number", "minimum": 0, "maximum": 1}
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://github.com/hev/jev-rerank/schema/state.schema.json",
4
+ "title": "Jev rerank request state",
5
+ "description": "The `state` object sent to POST https://api.typesafe.ai/v1/systemone. One Noul question per key of `documents` (see prompt.yaml); question ids match the document keys.",
6
+ "type": "object",
7
+ "required": ["query", "documents"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "query": {"type": "string", "description": "The search query or claim."},
11
+ "documents": {
12
+ "type": "object",
13
+ "description": "Candidate documents keyed D00, D01, ... in shortlist order.",
14
+ "propertyNames": {"pattern": "^D[0-9]{2,}$"},
15
+ "additionalProperties": {
16
+ "oneOf": [
17
+ {"type": "string"},
18
+ {"type": "object", "properties": {"title": {"type": "string"}, "text": {"type": "string"}}, "additionalProperties": true}
19
+ ]
20
+ }
21
+ }
22
+ }
23
+ }