agentforge-reranker-sentence-transformers 0.2.3__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.
- agentforge_reranker_sentence_transformers-0.2.3/.gitignore +49 -0
- agentforge_reranker_sentence_transformers-0.2.3/LICENSE +202 -0
- agentforge_reranker_sentence_transformers-0.2.3/PKG-INFO +74 -0
- agentforge_reranker_sentence_transformers-0.2.3/README.md +49 -0
- agentforge_reranker_sentence_transformers-0.2.3/pyproject.toml +60 -0
- agentforge_reranker_sentence_transformers-0.2.3/src/agentforge_reranker_sentence_transformers/__init__.py +10 -0
- agentforge_reranker_sentence_transformers-0.2.3/src/agentforge_reranker_sentence_transformers/_inmem_runner.py +40 -0
- agentforge_reranker_sentence_transformers-0.2.3/src/agentforge_reranker_sentence_transformers/_runner.py +44 -0
- agentforge_reranker_sentence_transformers-0.2.3/src/agentforge_reranker_sentence_transformers/py.typed +0 -0
- agentforge_reranker_sentence_transformers-0.2.3/src/agentforge_reranker_sentence_transformers/reranker.py +126 -0
- agentforge_reranker_sentence_transformers-0.2.3/tests/integration/test_reranker_live.py +62 -0
- agentforge_reranker_sentence_transformers-0.2.3/tests/unit/test_reranker.py +125 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
|
|
7
|
+
# Distribution / packaging
|
|
8
|
+
.Python
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
*.egg-info/
|
|
12
|
+
*.egg
|
|
13
|
+
wheels/
|
|
14
|
+
sdist/
|
|
15
|
+
share/python-wheels/
|
|
16
|
+
|
|
17
|
+
# uv
|
|
18
|
+
.venv/
|
|
19
|
+
uv-cache/
|
|
20
|
+
|
|
21
|
+
# Testing
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.coverage
|
|
24
|
+
.coverage.*
|
|
25
|
+
htmlcov/
|
|
26
|
+
coverage.xml
|
|
27
|
+
.tox/
|
|
28
|
+
.mypy_cache/
|
|
29
|
+
.ruff_cache/
|
|
30
|
+
.hypothesis/
|
|
31
|
+
|
|
32
|
+
# Environment
|
|
33
|
+
.env
|
|
34
|
+
.envrc
|
|
35
|
+
|
|
36
|
+
# Editors
|
|
37
|
+
.vscode/
|
|
38
|
+
.idea/
|
|
39
|
+
*.swp
|
|
40
|
+
*.swo
|
|
41
|
+
*~
|
|
42
|
+
|
|
43
|
+
# OS
|
|
44
|
+
.DS_Store
|
|
45
|
+
Thumbs.db
|
|
46
|
+
|
|
47
|
+
# Project-local
|
|
48
|
+
*.local
|
|
49
|
+
.agentforge-state/.session-cache
|
|
@@ -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,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentforge-reranker-sentence-transformers
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: SentenceTransformers cross-encoder reranker for AgentForge
|
|
5
|
+
Project-URL: Homepage, https://github.com/Scaffoldic/agentforge-py
|
|
6
|
+
Project-URL: Repository, https://github.com/Scaffoldic/agentforge-py
|
|
7
|
+
Project-URL: Changelog, https://github.com/Scaffoldic/agentforge-py/blob/main/CHANGELOG.md
|
|
8
|
+
Project-URL: Issues, https://github.com/Scaffoldic/agentforge-py/issues
|
|
9
|
+
Author: The AgentForge Authors
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent,ai,cross-encoder,rag,rerank,sentence-transformers
|
|
13
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.13
|
|
21
|
+
Requires-Dist: agentforge-core~=0.2.3
|
|
22
|
+
Provides-Extra: sentence-transformers
|
|
23
|
+
Requires-Dist: sentence-transformers>=3.0; extra == 'sentence-transformers'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# agentforge-reranker-sentence-transformers
|
|
27
|
+
|
|
28
|
+
SentenceTransformers cross-encoder reranker for the AgentForge
|
|
29
|
+
framework (feat-021 default concrete impl).
|
|
30
|
+
|
|
31
|
+
Registers as `agentforge.rerankers:sentence-transformers` and
|
|
32
|
+
implements the `Reranker` ABC from `agentforge-core`.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install agentforge-reranker-sentence-transformers[sentence-transformers]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The `[sentence-transformers]` extra pulls in
|
|
41
|
+
`sentence-transformers>=3.0` (~500MB for base + one model).
|
|
42
|
+
Without it, the production factory raises `ModuleError` with
|
|
43
|
+
pip remediation.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from agentforge import Retriever
|
|
49
|
+
from agentforge_reranker_sentence_transformers import (
|
|
50
|
+
SentenceTransformersReranker,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
reranker = SentenceTransformersReranker.from_config(
|
|
54
|
+
model="cross-encoder/ms-marco-MiniLM-L-6-v2",
|
|
55
|
+
)
|
|
56
|
+
retriever = Retriever(
|
|
57
|
+
store=vector_store,
|
|
58
|
+
embedder=embedding_client,
|
|
59
|
+
reranker=reranker,
|
|
60
|
+
over_fetch_factor=3,
|
|
61
|
+
)
|
|
62
|
+
results = await retriever.retrieve("how do I deploy?", top_k=5)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Score normalisation
|
|
66
|
+
|
|
67
|
+
The cross-encoder returns raw logits (typically `-10..+10`).
|
|
68
|
+
The reranker applies a sigmoid (`1 / (1 + exp(-x))`) so
|
|
69
|
+
returned scores are normalised to `(0, 1)` — fitting the
|
|
70
|
+
`VectorMatch.score` contract from `agentforge-core`.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
Apache-2.0.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# agentforge-reranker-sentence-transformers
|
|
2
|
+
|
|
3
|
+
SentenceTransformers cross-encoder reranker for the AgentForge
|
|
4
|
+
framework (feat-021 default concrete impl).
|
|
5
|
+
|
|
6
|
+
Registers as `agentforge.rerankers:sentence-transformers` and
|
|
7
|
+
implements the `Reranker` ABC from `agentforge-core`.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install agentforge-reranker-sentence-transformers[sentence-transformers]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The `[sentence-transformers]` extra pulls in
|
|
16
|
+
`sentence-transformers>=3.0` (~500MB for base + one model).
|
|
17
|
+
Without it, the production factory raises `ModuleError` with
|
|
18
|
+
pip remediation.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from agentforge import Retriever
|
|
24
|
+
from agentforge_reranker_sentence_transformers import (
|
|
25
|
+
SentenceTransformersReranker,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
reranker = SentenceTransformersReranker.from_config(
|
|
29
|
+
model="cross-encoder/ms-marco-MiniLM-L-6-v2",
|
|
30
|
+
)
|
|
31
|
+
retriever = Retriever(
|
|
32
|
+
store=vector_store,
|
|
33
|
+
embedder=embedding_client,
|
|
34
|
+
reranker=reranker,
|
|
35
|
+
over_fetch_factor=3,
|
|
36
|
+
)
|
|
37
|
+
results = await retriever.retrieve("how do I deploy?", top_k=5)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Score normalisation
|
|
41
|
+
|
|
42
|
+
The cross-encoder returns raw logits (typically `-10..+10`).
|
|
43
|
+
The reranker applies a sigmoid (`1 / (1 + exp(-x))`) so
|
|
44
|
+
returned scores are normalised to `(0, 1)` — fitting the
|
|
45
|
+
`VectorMatch.score` contract from `agentforge-core`.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
Apache-2.0.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# agentforge-reranker-sentence-transformers — feat-021 default Reranker.
|
|
2
|
+
#
|
|
3
|
+
# Tier-3 module per ADR-0003. Wraps sentence_transformers.CrossEncoder
|
|
4
|
+
# for cross-encoder reranking. Registers as
|
|
5
|
+
# `agentforge.rerankers:sentence-transformers`. SDK is the optional
|
|
6
|
+
# [sentence-transformers] extra; bare install keeps the package
|
|
7
|
+
# importable for tests with the fake runner.
|
|
8
|
+
|
|
9
|
+
[project]
|
|
10
|
+
name = "agentforge-reranker-sentence-transformers"
|
|
11
|
+
version = "0.2.3"
|
|
12
|
+
description = "SentenceTransformers cross-encoder reranker for AgentForge"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.13"
|
|
15
|
+
license = "Apache-2.0"
|
|
16
|
+
license-files = ["LICENSE"]
|
|
17
|
+
authors = [
|
|
18
|
+
{name = "The AgentForge Authors"},
|
|
19
|
+
]
|
|
20
|
+
keywords = ["ai", "agent", "rag", "rerank", "cross-encoder", "sentence-transformers"]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 2 - Pre-Alpha",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: Apache Software License",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
dependencies = [
|
|
32
|
+
"agentforge-core ~= 0.2.3",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
sentence-transformers = ["sentence-transformers>=3.0"]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/Scaffoldic/agentforge-py"
|
|
40
|
+
Repository = "https://github.com/Scaffoldic/agentforge-py"
|
|
41
|
+
Changelog = "https://github.com/Scaffoldic/agentforge-py/blob/main/CHANGELOG.md"
|
|
42
|
+
Issues = "https://github.com/Scaffoldic/agentforge-py/issues"
|
|
43
|
+
|
|
44
|
+
[project.entry-points."agentforge.rerankers"]
|
|
45
|
+
sentence-transformers = "agentforge_reranker_sentence_transformers:SentenceTransformersReranker"
|
|
46
|
+
|
|
47
|
+
[build-system]
|
|
48
|
+
requires = ["hatchling>=1.27"]
|
|
49
|
+
build-backend = "hatchling.build"
|
|
50
|
+
|
|
51
|
+
[tool.hatch.build.targets.wheel]
|
|
52
|
+
packages = ["src/agentforge_reranker_sentence_transformers"]
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.sdist]
|
|
55
|
+
include = [
|
|
56
|
+
"src/agentforge_reranker_sentence_transformers",
|
|
57
|
+
"tests",
|
|
58
|
+
"README.md",
|
|
59
|
+
"LICENSE",
|
|
60
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""`agentforge-reranker-sentence-transformers` — cross-encoder reranker."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from agentforge_reranker_sentence_transformers._runner import CrossEncoderRunner
|
|
6
|
+
from agentforge_reranker_sentence_transformers.reranker import (
|
|
7
|
+
SentenceTransformersReranker,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = ["CrossEncoderRunner", "SentenceTransformersReranker"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""In-memory `CrossEncoderRunner` for unit tests + downstream integration.
|
|
2
|
+
|
|
3
|
+
Records every ``predict`` call's pair list and returns scripted
|
|
4
|
+
raw-logit scores. Tests use ``set_scores`` to control what the
|
|
5
|
+
reranker sees.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FakeCrossEncoderRunner:
|
|
12
|
+
"""In-memory recorder of every predict call + scripted scoring."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, scores: list[float] | None = None) -> None:
|
|
15
|
+
self._scores = list(scores or [])
|
|
16
|
+
self.predict_calls: list[list[tuple[str, str]]] = []
|
|
17
|
+
self.closed = False
|
|
18
|
+
|
|
19
|
+
def set_scores(self, scores: list[float]) -> None:
|
|
20
|
+
"""Replace the scripted score list. Returned in order on
|
|
21
|
+
subsequent ``predict`` calls."""
|
|
22
|
+
self._scores = list(scores)
|
|
23
|
+
|
|
24
|
+
def predict(self, pairs: list[tuple[str, str]]) -> list[float]:
|
|
25
|
+
self.predict_calls.append(list(pairs))
|
|
26
|
+
if not pairs:
|
|
27
|
+
return []
|
|
28
|
+
if len(self._scores) < len(pairs):
|
|
29
|
+
msg = (
|
|
30
|
+
f"FakeCrossEncoderRunner: scripted {len(self._scores)} scores "
|
|
31
|
+
f"but called with {len(pairs)} pairs"
|
|
32
|
+
)
|
|
33
|
+
raise ValueError(msg)
|
|
34
|
+
return self._scores[: len(pairs)]
|
|
35
|
+
|
|
36
|
+
def close(self) -> None:
|
|
37
|
+
self.closed = True
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = ["FakeCrossEncoderRunner"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""CrossEncoder runner Protocol + production SDK wrapper."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Protocol
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CrossEncoderRunner(Protocol):
|
|
9
|
+
"""Lifecycle Protocol for the single SDK call we make.
|
|
10
|
+
|
|
11
|
+
Mirrors `sentence_transformers.CrossEncoder.predict` exactly,
|
|
12
|
+
enough for tests to inject a fake that returns scripted scores.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def predict(self, pairs: list[tuple[str, str]]) -> list[float]: # pragma: no cover
|
|
16
|
+
"""Return one raw relevance score per ``(query, candidate_text)`` pair."""
|
|
17
|
+
...
|
|
18
|
+
|
|
19
|
+
def close(self) -> None: # pragma: no cover
|
|
20
|
+
"""Release model handles (no-op for SDK; tests may use this)."""
|
|
21
|
+
...
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class _SentenceTransformersRunner: # pragma: no cover — exercised only with `-m live`.
|
|
25
|
+
"""Production runner wrapping ``sentence_transformers.CrossEncoder``."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, model: Any) -> None:
|
|
28
|
+
self._model = model
|
|
29
|
+
|
|
30
|
+
def predict(self, pairs: list[tuple[str, str]]) -> list[float]:
|
|
31
|
+
if not pairs:
|
|
32
|
+
return []
|
|
33
|
+
# CrossEncoder.predict returns numpy.ndarray; convert to plain
|
|
34
|
+
# python floats for downstream serialisation.
|
|
35
|
+
raw = self._model.predict(pairs)
|
|
36
|
+
return [float(x) for x in raw]
|
|
37
|
+
|
|
38
|
+
def close(self) -> None:
|
|
39
|
+
# sentence_transformers has no explicit close; the model is
|
|
40
|
+
# garbage-collected when the reference drops.
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
__all__ = ["CrossEncoderRunner"]
|
|
File without changes
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""`SentenceTransformersReranker` — cross-encoder reranker.
|
|
2
|
+
|
|
3
|
+
Implements the locked `Reranker` ABC from feat-021 against
|
|
4
|
+
``sentence_transformers.CrossEncoder.predict``. Applies a sigmoid
|
|
5
|
+
to the raw logits so returned scores satisfy the
|
|
6
|
+
``VectorMatch.score ∈ [0, 1]`` contract.
|
|
7
|
+
|
|
8
|
+
Construction is two paths:
|
|
9
|
+
|
|
10
|
+
- ``SentenceTransformersReranker(runner=<CrossEncoderRunner>)`` —
|
|
11
|
+
direct injection (tests).
|
|
12
|
+
- ``SentenceTransformersReranker.from_config(model=...)`` — builds
|
|
13
|
+
the production runner by lazy-importing ``sentence_transformers``.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import math
|
|
19
|
+
from typing import TYPE_CHECKING
|
|
20
|
+
|
|
21
|
+
from agentforge_core.contracts.reranker import Reranker
|
|
22
|
+
from agentforge_core.production.exceptions import ModuleError
|
|
23
|
+
from agentforge_core.values.vector import VectorMatch
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from agentforge_reranker_sentence_transformers._runner import CrossEncoderRunner
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
_DEFAULT_MODEL = "cross-encoder/ms-marco-MiniLM-L-6-v2"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _sigmoid(x: float) -> float:
|
|
33
|
+
"""Logistic sigmoid mapping (-∞, +∞) → (0, 1).
|
|
34
|
+
|
|
35
|
+
Numerically-stable variant: routes through the larger branch
|
|
36
|
+
so very negative logits don't blow up ``math.exp``.
|
|
37
|
+
"""
|
|
38
|
+
if x >= 0:
|
|
39
|
+
z = math.exp(-x)
|
|
40
|
+
return 1.0 / (1.0 + z)
|
|
41
|
+
z = math.exp(x)
|
|
42
|
+
return z / (1.0 + z)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class SentenceTransformersReranker(Reranker):
|
|
46
|
+
"""Cross-encoder reranker backed by ``sentence-transformers``.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
runner: A `CrossEncoderRunner` (test fake or production
|
|
50
|
+
SDK wrapper). The reranker is the only place we touch
|
|
51
|
+
the runner.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, *, runner: CrossEncoderRunner) -> None:
|
|
55
|
+
self._runner = runner
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_config(
|
|
59
|
+
cls,
|
|
60
|
+
*,
|
|
61
|
+
model: str = _DEFAULT_MODEL,
|
|
62
|
+
) -> SentenceTransformersReranker: # pragma: no cover — `-m live` only.
|
|
63
|
+
"""Build a reranker backed by a real `CrossEncoder` model."""
|
|
64
|
+
runner = _build_cross_encoder_runner(model=model)
|
|
65
|
+
return cls(runner=runner)
|
|
66
|
+
|
|
67
|
+
async def rerank(
|
|
68
|
+
self,
|
|
69
|
+
query: str,
|
|
70
|
+
candidates: list[VectorMatch],
|
|
71
|
+
*,
|
|
72
|
+
top_k: int | None = None,
|
|
73
|
+
) -> list[VectorMatch]:
|
|
74
|
+
if top_k is not None and top_k < 1:
|
|
75
|
+
msg = f"top_k must be >= 1, got {top_k}"
|
|
76
|
+
raise ValueError(msg)
|
|
77
|
+
if not candidates:
|
|
78
|
+
return []
|
|
79
|
+
|
|
80
|
+
pairs = [(query, c.text) for c in candidates]
|
|
81
|
+
raw_scores = self._runner.predict(pairs)
|
|
82
|
+
if len(raw_scores) != len(candidates):
|
|
83
|
+
msg = f"CrossEncoder returned {len(raw_scores)} scores for {len(candidates)} pairs"
|
|
84
|
+
raise RuntimeError(msg)
|
|
85
|
+
|
|
86
|
+
rescored = [
|
|
87
|
+
VectorMatch(
|
|
88
|
+
id=c.id,
|
|
89
|
+
text=c.text,
|
|
90
|
+
metadata=c.metadata,
|
|
91
|
+
score=_sigmoid(float(s)),
|
|
92
|
+
)
|
|
93
|
+
for c, s in zip(candidates, raw_scores, strict=True)
|
|
94
|
+
]
|
|
95
|
+
rescored.sort(key=lambda m: m.score, reverse=True)
|
|
96
|
+
if top_k is not None:
|
|
97
|
+
return rescored[:top_k]
|
|
98
|
+
return rescored
|
|
99
|
+
|
|
100
|
+
async def close(self) -> None:
|
|
101
|
+
self._runner.close()
|
|
102
|
+
|
|
103
|
+
def capabilities(self) -> set[str]:
|
|
104
|
+
return {"local", "batched"}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _build_cross_encoder_runner(*, model: str) -> CrossEncoderRunner: # pragma: no cover
|
|
108
|
+
"""Lazy-import `sentence_transformers` and build the production runner."""
|
|
109
|
+
try:
|
|
110
|
+
from sentence_transformers import CrossEncoder # noqa: PLC0415
|
|
111
|
+
except ImportError as exc:
|
|
112
|
+
msg = (
|
|
113
|
+
"sentence-transformers is not installed. Install via "
|
|
114
|
+
"`pip install agentforge-reranker-sentence-transformers"
|
|
115
|
+
"[sentence-transformers]` to use the production runner."
|
|
116
|
+
)
|
|
117
|
+
raise ModuleError(msg) from exc
|
|
118
|
+
|
|
119
|
+
from agentforge_reranker_sentence_transformers._runner import ( # noqa: PLC0415
|
|
120
|
+
_SentenceTransformersRunner,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
return _SentenceTransformersRunner(CrossEncoder(model))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
__all__ = ["SentenceTransformersReranker"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Live `SentenceTransformersReranker` integration test (feat-021).
|
|
2
|
+
|
|
3
|
+
Downloads ``cross-encoder/ms-marco-MiniLM-L-6-v2`` (~80MB) on
|
|
4
|
+
first run. Gated on `RUN_LIVE_RERANKER=1`. Run with:
|
|
5
|
+
|
|
6
|
+
RUN_LIVE_RERANKER=1 \\
|
|
7
|
+
uv run pytest -m live \\
|
|
8
|
+
packages/agentforge-reranker-sentence-transformers/
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
|
|
15
|
+
import pytest
|
|
16
|
+
from agentforge_core.values.vector import VectorMatch
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@pytest.mark.live
|
|
20
|
+
@pytest.mark.asyncio
|
|
21
|
+
async def test_reranker_live_reorders_known_candidates() -> None:
|
|
22
|
+
if os.environ.get("RUN_LIVE_RERANKER") != "1":
|
|
23
|
+
pytest.skip("RUN_LIVE_RERANKER != 1")
|
|
24
|
+
|
|
25
|
+
from agentforge_reranker_sentence_transformers import ( # noqa: PLC0415
|
|
26
|
+
SentenceTransformersReranker,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
candidates = [
|
|
30
|
+
VectorMatch(
|
|
31
|
+
id="weather",
|
|
32
|
+
text="The weather today is sunny and warm.",
|
|
33
|
+
score=0.5,
|
|
34
|
+
metadata={},
|
|
35
|
+
),
|
|
36
|
+
VectorMatch(
|
|
37
|
+
id="deploy",
|
|
38
|
+
text="To deploy an agent, run `agentforge run` from your project root.",
|
|
39
|
+
score=0.5,
|
|
40
|
+
metadata={},
|
|
41
|
+
),
|
|
42
|
+
VectorMatch(
|
|
43
|
+
id="recipe",
|
|
44
|
+
text="A classic pasta carbonara needs eggs, pancetta, and pepper.",
|
|
45
|
+
score=0.5,
|
|
46
|
+
metadata={},
|
|
47
|
+
),
|
|
48
|
+
]
|
|
49
|
+
reranker = SentenceTransformersReranker.from_config()
|
|
50
|
+
try:
|
|
51
|
+
results = await reranker.rerank(
|
|
52
|
+
"how do I deploy an agentforge agent?",
|
|
53
|
+
candidates,
|
|
54
|
+
top_k=3,
|
|
55
|
+
)
|
|
56
|
+
finally:
|
|
57
|
+
await reranker.close()
|
|
58
|
+
|
|
59
|
+
# The deploy candidate is the only relevant one for this query.
|
|
60
|
+
assert results[0].id == "deploy"
|
|
61
|
+
# All scores normalised into [0, 1] per the ABC contract.
|
|
62
|
+
assert all(0.0 <= r.score <= 1.0 for r in results)
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Unit tests for `SentenceTransformersReranker` (feat-021)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
from agentforge_core.testing import run_reranker_conformance
|
|
7
|
+
from agentforge_core.values.vector import VectorMatch
|
|
8
|
+
from agentforge_reranker_sentence_transformers import SentenceTransformersReranker
|
|
9
|
+
from agentforge_reranker_sentence_transformers._inmem_runner import (
|
|
10
|
+
FakeCrossEncoderRunner,
|
|
11
|
+
)
|
|
12
|
+
from agentforge_reranker_sentence_transformers.reranker import _sigmoid
|
|
13
|
+
|
|
14
|
+
SIGMOID_TOLERANCE = 1e-3
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _candidates() -> list[VectorMatch]:
|
|
18
|
+
"""Three deterministic candidates for the unit tests."""
|
|
19
|
+
return [
|
|
20
|
+
VectorMatch(id="a", text="alpha", score=0.7, metadata={"i": 0}),
|
|
21
|
+
VectorMatch(id="b", text="beta", score=0.6, metadata={"i": 1}),
|
|
22
|
+
VectorMatch(id="c", text="gamma", score=0.5, metadata={"i": 2}),
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_sigmoid_anchors_match_intuition() -> None:
|
|
27
|
+
"""Raw -10 → ~0, raw 0 → 0.5, raw +10 → ~1."""
|
|
28
|
+
assert abs(_sigmoid(-10.0) - 0.0) < SIGMOID_TOLERANCE
|
|
29
|
+
assert abs(_sigmoid(0.0) - 0.5) < SIGMOID_TOLERANCE
|
|
30
|
+
assert abs(_sigmoid(10.0) - 1.0) < SIGMOID_TOLERANCE
|
|
31
|
+
# Monotonic
|
|
32
|
+
assert _sigmoid(-1.0) < _sigmoid(0.0) < _sigmoid(1.0)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.asyncio
|
|
36
|
+
async def test_rerank_sorts_descending_by_normalised_score() -> None:
|
|
37
|
+
# Raw scores: a -> low, b -> medium, c -> high. Expected order
|
|
38
|
+
# after rerank: c, b, a.
|
|
39
|
+
runner = FakeCrossEncoderRunner(scores=[-5.0, 0.0, 5.0])
|
|
40
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
41
|
+
|
|
42
|
+
results = await reranker.rerank("q", _candidates())
|
|
43
|
+
|
|
44
|
+
assert [r.id for r in results] == ["c", "b", "a"]
|
|
45
|
+
# Each score normalised into [0, 1] and matches sigmoid of raw.
|
|
46
|
+
assert abs(results[0].score - _sigmoid(5.0)) < SIGMOID_TOLERANCE
|
|
47
|
+
assert abs(results[1].score - _sigmoid(0.0)) < SIGMOID_TOLERANCE
|
|
48
|
+
assert abs(results[2].score - _sigmoid(-5.0)) < SIGMOID_TOLERANCE
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.mark.asyncio
|
|
52
|
+
async def test_rerank_preserves_other_fields() -> None:
|
|
53
|
+
runner = FakeCrossEncoderRunner(scores=[0.0, 0.0, 0.0])
|
|
54
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
55
|
+
results = await reranker.rerank("q", _candidates())
|
|
56
|
+
by_id = {r.id: r for r in results}
|
|
57
|
+
assert by_id["a"].text == "alpha"
|
|
58
|
+
assert by_id["b"].metadata == {"i": 1}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@pytest.mark.asyncio
|
|
62
|
+
async def test_rerank_top_k_truncates() -> None:
|
|
63
|
+
runner = FakeCrossEncoderRunner(scores=[1.0, 2.0, 3.0])
|
|
64
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
65
|
+
results = await reranker.rerank("q", _candidates(), top_k=2)
|
|
66
|
+
assert len(results) == 2
|
|
67
|
+
# Best two are c (raw 3.0) and b (raw 2.0).
|
|
68
|
+
assert [r.id for r in results] == ["c", "b"]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@pytest.mark.asyncio
|
|
72
|
+
async def test_rerank_empty_candidates_short_circuits() -> None:
|
|
73
|
+
runner = FakeCrossEncoderRunner(scores=[])
|
|
74
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
75
|
+
assert await reranker.rerank("q", []) == []
|
|
76
|
+
# No predict call when there's nothing to score.
|
|
77
|
+
assert runner.predict_calls == []
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@pytest.mark.asyncio
|
|
81
|
+
async def test_rerank_rejects_zero_top_k() -> None:
|
|
82
|
+
reranker = SentenceTransformersReranker(runner=FakeCrossEncoderRunner())
|
|
83
|
+
with pytest.raises(ValueError, match="top_k"):
|
|
84
|
+
await reranker.rerank("q", _candidates(), top_k=0)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.asyncio
|
|
88
|
+
async def test_capabilities_advertised() -> None:
|
|
89
|
+
reranker = SentenceTransformersReranker(runner=FakeCrossEncoderRunner())
|
|
90
|
+
assert reranker.capabilities() == {"local", "batched"}
|
|
91
|
+
assert reranker.supports("local") is True
|
|
92
|
+
assert reranker.supports("managed") is False
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@pytest.mark.asyncio
|
|
96
|
+
async def test_runner_score_count_mismatch_raises() -> None:
|
|
97
|
+
"""Defensive: if the runner returns the wrong number of scores
|
|
98
|
+
we surface a clear error rather than silently mis-zipping."""
|
|
99
|
+
runner = FakeCrossEncoderRunner()
|
|
100
|
+
# set_scores intentionally too short to force the mismatch.
|
|
101
|
+
runner.set_scores([1.0, 2.0])
|
|
102
|
+
|
|
103
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
104
|
+
# FakeCrossEncoderRunner itself raises before we get to the
|
|
105
|
+
# length check in the reranker, which is also acceptable.
|
|
106
|
+
with pytest.raises((RuntimeError, ValueError)):
|
|
107
|
+
await reranker.rerank("q", _candidates())
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@pytest.mark.asyncio
|
|
111
|
+
async def test_close_propagates_to_runner() -> None:
|
|
112
|
+
runner = FakeCrossEncoderRunner()
|
|
113
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
114
|
+
await reranker.close()
|
|
115
|
+
assert runner.closed
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.asyncio
|
|
119
|
+
async def test_conformance_suite() -> None:
|
|
120
|
+
# Conformance probes call predict() under several different
|
|
121
|
+
# candidate-list sizes; supply enough scores up-front and rely on
|
|
122
|
+
# FakeCrossEncoderRunner's prefix-slicing.
|
|
123
|
+
runner = FakeCrossEncoderRunner(scores=[3.0, 2.0, 1.0])
|
|
124
|
+
reranker = SentenceTransformersReranker(runner=runner)
|
|
125
|
+
await run_reranker_conformance(reranker)
|