Skip to content

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/rerank

Headers

http
Authorization: Bearer YOUR_NEXUSMODELS_API_KEY
Content-Type: application/json

Request parameters

ParameterTypeRequiredDescription
modelstringYesRerank model name
querystringYesQuery used to calculate relevance
documentsarrayYesCandidate documents to rerank
top_nintegerNoNumber of highest-ranked documents to return
return_documentsbooleanNoWhether 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

FieldDescription
indexPosition of the document in the original documents array
relevance_scoreRelevance score between the query and document
documentOriginal document content when supported and requested