Text Ranking
Transformers
Safetensors
multilingual
t5gemma2
text2text-generation
reranker
encoder-decoder
FBNL
Retrieval
RAG
cosyy commited on
Commit
bc5cb8f
·
verified ·
1 Parent(s): 6f7a484

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +108 -3
README.md CHANGED
@@ -92,6 +92,7 @@ On LMEB, reranking models demonstrate a clear advantage, with even the 0.27B Nan
92
  ![lmeb_emb](./assets/lmeb_emb.jpg)
93
 
94
  # Usage
 
95
  ```python
96
  import argparse
97
  from typing import Optional
@@ -192,17 +193,121 @@ def main() -> None:
192
  pairs = [(query, document) for document in documents]
193
  print("scores:", reranker.predict(pairs, instruction=instruction))
194
  print("rankings:", reranker.rank(query, documents, instruction=instruction))
195
-
196
 
197
  if __name__ == "__main__":
198
  main()
199
 
200
  '''
201
- scores: [0.9998464584350586, 6.893610020597407e-07]
202
- rankings: [{'corpus_id': 0, 'score': 0.9998464584350586}, {'corpus_id': 1, 'score': 6.893610020597407e-07}]
203
  '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  ```
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  # Acknowledgements
207
  We sincerely thank `jina-reranker-v3` and `Qwen3-Reranker` for their valuable inspiration and contributions to the reranking community, from which we have learned a lot.
208
 
 
92
  ![lmeb_emb](./assets/lmeb_emb.jpg)
93
 
94
  # Usage
95
+ ## Using transformers
96
  ```python
97
  import argparse
98
  from typing import Optional
 
193
  pairs = [(query, document) for document in documents]
194
  print("scores:", reranker.predict(pairs, instruction=instruction))
195
  print("rankings:", reranker.rank(query, documents, instruction=instruction))
196
+
197
 
198
  if __name__ == "__main__":
199
  main()
200
 
201
  '''
202
+ scores: [0.9998205304145813, 4.7850949158601e-06]
203
+ rankings: [{'corpus_id': 0, 'score': 0.9998205304145813}, {'corpus_id': 1, 'score': 4.7850949158601e-06}]
204
  '''
205
+
206
+ ```
207
+
208
+ ## Using vLLM
209
+ An experimental single-GPU adapter is available for offline
210
+ `LLM.classify()` reranking and optional FastAPI serving. It reuses the original
211
+ checkpoint without adding or modifying model weights.
212
+
213
+ The adapter has been validated with Python 3.12, vLLM 0.19.1, Transformers
214
+ 5.6.2 and CUDA BF16:
215
+
216
+ ```bash
217
+ conda create -n kalm-vllm python=3.12 -y
218
+ conda activate kalm-vllm
219
+ pip install "vllm==0.19.1" "transformers==5.6.2"
220
+
221
+ hf download KaLM-Embedding/KaLM-Reranker-V1-Large \
222
+ --local-dir ./KaLM-Reranker-V1-Large
223
+ pip install ./KaLM-Reranker-V1-Large/vllm_support --no-deps
224
+ export VLLM_PLUGINS=kalm_t5gemma2
225
+ ```
226
+
227
+ Offline Python:
228
+
229
+ ```python
230
+ from kalm_t5gemma2_vllm_plugin import KaLMVLLMReranker
231
+
232
+ query = "What is the capital of China?"
233
+ documents = [
234
+ "The capital of China is Beijing.",
235
+ "Gravity attracts bodies toward one another.",
236
+ ]
237
+
238
+ with KaLMVLLMReranker(
239
+ "KaLM-Embedding/KaLM-Reranker-V1-Large",
240
+ query_max_length=512,
241
+ document_max_length=1024,
242
+ encoder_chunk_size=4,
243
+ ) as reranker:
244
+ print(reranker.rank(query, documents))
245
+ ```
246
+
247
+ Offline CLI:
248
+
249
+ ```bash
250
+ kalm-vllm-rerank --return-margin
251
  ```
252
 
253
+ To deploy the online service, install the HTTP dependencies and keep the
254
+ server running in the first terminal:
255
+
256
+ ```bash
257
+ pip install "fastapi>=0.136,<0.137" "uvicorn>=0.46,<0.47"
258
+ export CUDA_VISIBLE_DEVICES=0
259
+ export VLLM_PLUGINS=kalm_t5gemma2
260
+
261
+ kalm-vllm-serve \
262
+ --host 0.0.0.0 \
263
+ --port 8000 \
264
+ --model KaLM-Embedding/KaLM-Reranker-V1-Large \
265
+ --query-max-length 512 \
266
+ --document-max-length 1024 \
267
+ --encoder-chunk-size 4 \
268
+ --max-model-len 2048
269
+ ```
270
+
271
+ In a second terminal, check the server:
272
+
273
+ ```bash
274
+ conda activate kalm-vllm
275
+ kalm-vllm-client --base-url http://127.0.0.1:8000 --health
276
+ ```
277
+
278
+ Use `/rerank` for one query and a list of documents. Results are sorted by
279
+ score:
280
+
281
+ ```bash
282
+ kalm-vllm-client \
283
+ --base-url http://127.0.0.1:8000 \
284
+ --endpoint rerank \
285
+ --json-file ./KaLM-Reranker-V1-Large/vllm_support/examples/rerank_request.json \
286
+ --return-margin \
287
+ --top-k 10
288
+ ```
289
+
290
+ Use `/score` to score a batch of independent query-document pairs. Results
291
+ preserve the input order and optional IDs:
292
+
293
+ ```bash
294
+ kalm-vllm-client \
295
+ --base-url http://127.0.0.1:8000 \
296
+ --endpoint score \
297
+ --json-file ./KaLM-Reranker-V1-Large/vllm_support/examples/score_request.json \
298
+ --return-margin
299
+ ```
300
+
301
+ The default output is `P(yes)`. Set `return_margin=true` to also receive
302
+ `yes_logit - no_logit`; the client flag `--return-margin` applies the same
303
+ setting to a JSON file request. The supported encoder chunk sizes are
304
+ `1, 2, 4, 8, 16, 32`, with `4` as the default.
305
+
306
+ This adapter uses vLLM's plugin, scheduling and pooling interfaces while the
307
+ T5Gemma2 semantic forward still runs through Transformers. It is not vLLM's
308
+ native HTTP `/score` implementation or a complete vLLM-native kernel port.
309
+ See [the complete installation, API and troubleshooting guide](./vllm_support/README.md).
310
+
311
  # Acknowledgements
312
  We sincerely thank `jina-reranker-v3` and `Qwen3-Reranker` for their valuable inspiration and contributions to the reranking community, from which we have learned a lot.
313