Text Ranking
sentence-transformers
Safetensors
Transformers
multilingual
t5gemma2
text2text-generation
reranker
encoder-decoder
FBNL
Retrieval
RAG
Instructions to use KaLM-Embedding/KaLM-Reranker-V1-Nano with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use KaLM-Embedding/KaLM-Reranker-V1-Nano with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("KaLM-Embedding/KaLM-Reranker-V1-Nano") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Transformers
How to use KaLM-Embedding/KaLM-Reranker-V1-Nano with Transformers:
# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("KaLM-Embedding/KaLM-Reranker-V1-Nano") model = AutoModelForMultimodalLM.from_pretrained("KaLM-Embedding/KaLM-Reranker-V1-Nano", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -244,18 +244,63 @@ with KaLMVLLMReranker(
|
|
| 244 |
print(reranker.rank(query, documents))
|
| 245 |
```
|
| 246 |
|
| 247 |
-
Offline CLI
|
| 248 |
|
| 249 |
```bash
|
| 250 |
kalm-vllm-rerank --return-margin
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
|
|
|
| 252 |
pip install "fastapi>=0.136,<0.137" "uvicorn>=0.46,<0.47"
|
| 253 |
-
|
| 254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
```
|
| 256 |
|
| 257 |
The default output is `P(yes)`. Set `return_margin=true` to also receive
|
| 258 |
-
`yes_logit - no_logit`
|
|
|
|
| 259 |
`1, 2, 4, 8, 16, 32`, with `4` as the default.
|
| 260 |
|
| 261 |
This adapter uses vLLM's plugin, scheduling and pooling interfaces while the
|
|
|
|
| 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-Nano \
|
| 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-Nano/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-Nano/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
|