Rerank
Recalculate relevance scores for candidate documents and sort them according to their relevance to a query.
This endpoint is commonly used for RAG, knowledge retrieval and search result optimization.
Endpoint
http
POST https://api.nexusmodels.cn/v1/rerankHeaders
http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: application/jsonRequest parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Rerank model name |
query | string | Yes | Query used to calculate relevance |
documents | array | Yes | Candidate documents to rerank |
top_n | integer | No | Number of highest-ranked documents to return |
return_documents | boolean | No | Whether to return document content |
Example
bash
curl -sS -X POST \
'https://api.nexusmodels.cn/v1/rerank' \
-H 'Authorization: Bearer YOUR_NEXUSMODELS_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "YOUR_RERANK_MODEL",
"query": "What is a vector database?",
"documents": [
"A vector database stores and retrieves high-dimensional vectors.",
"A relational database usually stores data in tables.",
"Weather forecasts predict future weather conditions."
],
"top_n": 2,
"return_documents": true
}'Response example
json
{
"id": "rerank-request-id",
"results": [
{
"index": 0,
"relevance_score": 0.97,
"document": {
"text": "A vector database stores and retrieves high-dimensional vectors."
}
},
{
"index": 1,
"relevance_score": 0.21,
"document": {
"text": "A relational database usually stores data in tables."
}
}
]
}Response fields
| Field | Description |
|---|---|
index | Position of the document in the original documents array |
relevance_score | Relevance score between the query and document |
document | Original document content when supported and requested |