Rerank
Takes a search query and a list of candidate documents, returns a stronger ranking of which document best answers the query. The second pass after embedding-based top-K retrieval.
Available models
| Model | Type |
|---|---|
verirerag (recommended) | TEI (Text Embeddings Inference) cross-encoder, multilingual |
Cohere rerank-multilingual-v3.0 | If a Cohere-keyed channel exists |
Why rerank?
Embedding similarity is fast (vector dot product) but "closest neighbour" isn't always "correct answer". A cross-encoder examines each (query, document) pair and scores actual relevance. It's slower — so we first cut down to 50–100 with embedding, then verirerag picks the real top 3.
[5000 docs via embedding → top 50] → [verirerag → top 5]curl
bash
curl https://app.qevron.ai/v1/rerank \
-H "Authorization: Bearer sk-..." \
-H "Content-Type: application/json" \
-d '{
"model": "verirerag",
"query": "what is qevron",
"documents": [
"The weather is nice today.",
"Qevron is an AI gateway application.",
"Channels follow the OpenAI schema.",
"Turkish and English are supported."
]
}'Response
json
{
"results": [
{"index": 1, "relevance_score": 0.96, "document": {"text": "Qevron is an AI gateway application."}},
{"index": 2, "relevance_score": 0.62, "document": {"text": "Channels follow the OpenAI schema."}},
{"index": 3, "relevance_score": 0.18, "document": {"text": "Turkish and English are supported."}},
{"index": 0, "relevance_score": 0.02, "document": {"text": "The weather is nice today."}}
]
}index is the position in the original documents array — use it to look up your own metadata.
Python (raw requests — OpenAI SDK doesn't expose rerank)
python
import requests
resp = requests.post(
"https://app.qevron.ai/v1/rerank",
headers={"Authorization": "Bearer sk-..."},
json={
"model": "verirerag",
"query": "what is qevron",
"documents": ["d1", "d2", "d3"],
},
)
results = resp.json()["results"]
# already sorted by relevance_score descIn a RAG pipeline
python
# 1) Embedding picks candidates
candidates = vector_db.search(embed(user_query), top_k=50)
# 2) Rerank computes real relevance
reranked = rerank("verirerag", user_query, [c.text for c in candidates])
# 3) Top 3 go into the LLM as context
top_3 = [candidates[r["index"]] for r in reranked[:3]]Troubleshooting
- All scores very low (< 0.05) → query likely doesn't overlap with documents. Audit embedding-side candidate selection first.
- Slow → 100+ documents are heavy. Trim with embedding to ~50 before rerank.
- OpenAI SDK doesn't work → correct, rerank isn't in OpenAI's standard; use raw
requests/httpx.
Next: Embedding · RAG walkthrough