Introduction
Reranking
Reorder search results using AI-powered reranking.
Reranking
Reorder search results using AI-powered reranking. Improve relevance by letting a model score and sort your results.
How It Works
- Send a query and a list of documents
- The model scores each document for relevance
- Results are returned sorted by relevance score
Basic Usage
curl https://viprouter.com/v1/rerank \
-H "Content-Type: application/json" \
-d '{
"model": "cohere/rerank-v3.5",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of artificial intelligence.",
"The weather today is sunny.",
"Deep learning uses neural networks.",
"Python is a programming language."
],
"top_n": 2
}'Response:
{
"results": [
{"index": 0, "relevance_score": 0.95, "document": "Machine learning is a subset of artificial intelligence."},
{"index": 2, "relevance_score": 0.82, "document": "Deep learning uses neural networks."}
]
}Python Example
from openai import OpenAI
client = OpenAI(base_url="https://viprouter.com/v1", api_key="your-key")
response = client.post("/v1/rerank", json={
"model": "cohere/rerank-v3.5",
"query": "What is machine learning?",
"documents": [
"Machine learning is a subset of AI.",
"The weather is nice today.",
"Deep learning uses neural networks."
],
"top_n": 2
})
for result in response.json()["results"]:
print(f"Score: {result['relevance_score']:.2f} - {result['document']}")Use Cases
- RAG Enhancement: Rerank retrieval results before passing to LLM
- Search Improvement: Reorder search results by relevance
- Document Filtering: Select top-K most relevant documents
Supported Providers
| Provider | Model |
|---|---|
| Cohere | cohere/rerank-v3.5 |
| Jina | jina/reranker-v2-base-multilingual |
Next Steps
- Rerank API - Full API documentation
