Reranking¶
A reranker (cross-encoder) reads the query together with each candidate and scores how well the candidate answers it. That is slower than comparing embeddings but more accurate, so it is used on a short list: retrieval finds the candidates, and the reranker puts them in order.
curl -X POST localhost:8000/api/v1/projects/1/retrieve -H 'Content-Type: application/json' \
-d '{"query": "What is the refund policy?", "mode": "hybrid", "rerank": true}'
Set up a reranker¶
Set RERANKER_PROVIDER (and usually RERANKER_MODEL), install its extra,
then restart.
RERANKER_PROVIDER |
Extra | Default model | Notes |
|---|---|---|---|
SENTENCE_TRANSFORMERS |
sentence-transformers |
cross-encoder/ms-marco-MiniLM-L6-v2 |
Any CrossEncoder (bge-reranker, mxbai-rerank, ...), run locally. RERANKER_DEVICE, RERANKER_MAX_LENGTH, RERANKER_TRUST_REMOTE_CODE |
FASTEMBED |
fastembed |
Xenova/ms-marco-MiniLM-L-6-v2 |
ONNX cross-encoders, no PyTorch |
COHERE |
cohere |
rerank-v3.5 |
RERANKER_URL for Cohere on Azure AI Foundry |
VOYAGE |
voyage |
rerank-2.5 |
|
JINA |
jina |
jina-reranker-v2-base-multilingual |
|
BEDROCK |
bedrock |
amazon.rerank-v1:0 |
AWS credentials and AWS_REGION; also cohere.rerank-v3-5:0 or a model ARN |
GEMINI |
gemini |
semantic-ranker-default@latest |
The Vertex AI Ranking API, with Application Default Credentials and GOOGLE_CLOUD_PROJECT |
OPENROUTER |
rerank-http |
cohere/rerank-v3.5 |
Needs RERANKER_API_KEY |
HUGGINGFACE |
rerank-http |
A Text Embeddings Inference server or Inference Endpoint at RERANKER_URL |
|
OPENAI_COMPATIBLE |
rerank-http |
Any server with a Cohere / Jina-style POST /rerank: vLLM, llama.cpp (--reranking), Infinity, Together, ... RERANKER_URL is required |
|
LOCALAI, LEMONADE, LITELLM |
rerank-http |
Their rerank endpoints, at their default local URLs unless RERANKER_URL is set |
OpenAI, Azure OpenAI, Mistral, Ollama and LM Studio have no rerank API, so
those values are refused at startup, with the alternatives listed. For a
reranker on your own machine, use SENTENCE_TRANSFORMERS or FASTEMBED,
or serve one with llama.cpp or LocalAI.
Local rerankers load their model at startup (and download it the first time). Hosted rerankers are not called at startup, so a wrong key shows up on the first rerank (502).
GET /api/v1/rerank/model shows the configured reranker.
Options¶
| Option | Default | |
|---|---|---|
rerank |
RERANK_BY_DEFAULT (off) |
true reranks this request, false skips it |
rerank_candidates |
4 x top_k, at least 20, at most 100 |
How many of the best candidates (after filters and de-duplication) the reranker scores, from top_k to 200. Candidates outside the pool are dropped |
rerank_threshold |
none | Drop results the reranker scores below this. The scale is the model's: 0-1 for the hosted APIs, raw logits for some local cross-encoders |
- Asking for
rerankwith no reranker configured returns 409, and a reranker that fails returns 502. - Reranked results carry the reranker's
score, plus theretrieval_scoreandretrieval_rankthey had before. - The response names the
reranker, andstatsreportsrerankedandrerank_ms. diversitystill works: MMR then uses the reranker's scores for relevance.- With parents, the reranker scores the parent text.
- A request with only a
vectorhas no text to rerank against. That is an error ifrerankwastrue, and a warning if reranking came fromRERANK_BY_DEFAULT.
Rerank any texts¶
POST /api/v1/rerank reranks a list of texts without a project:
curl -X POST localhost:8000/api/v1/rerank -H 'Content-Type: application/json' \
-d '{"query": "refund policy", "documents": ["...", "..."], "top_n": 3}'
It returns [{index, score}], best first (return_documents: true adds the
text), for up to 1000 documents per request.
Settings¶
| Setting | |
|---|---|
RERANKER_PROVIDER |
Empty: no reranker |
RERANKER_MODEL |
Default: the provider's default model |
RERANKER_API_KEY |
For hosted providers |
RERANKER_URL |
Custom endpoint |
RERANKER_DEVICE, RERANKER_MAX_LENGTH, RERANKER_TRUST_REMOTE_CODE |
Local models |
RERANK_BY_DEFAULT |
Rerank requests that don't set rerank |