Skip to content

Rerank

Reorder a set of candidate documents by relevance to a query — commonly used to refine retrieved results in RAG for better context quality.

Create a rerank

POST /v1/rerank

Parameters

ParameterTypeRequiredDescription
modelstringYesRerank model identifier
querystringYesThe query text
documentsarrayYesArray of candidate document strings
top_nintegerNoReturn the top N most relevant
return_documentsbooleanNoInclude original text in results, default false

Request

bash
curl https://ai.youqi.tech/v1/rerank \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-multilingual",
    "query": "How do I reset my password?",
    "documents": [
      "Click \"Forgot password\" on the login page and follow the steps.",
      "This platform supports many large language models.",
      "You can view your balance in the console."
    ],
    "top_n": 2,
    "return_documents": true
  }'

Response

json
{
  "object": "list",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.98,
      "document": { "text": "Click \"Forgot password\" on the login page and follow the steps." }
    },
    {
      "index": 2,
      "relevance_score": 0.12,
      "document": { "text": "You can view your balance in the console." }
    }
  ],
  "model": "rerank-multilingual",
  "usage": { "total_tokens": 64 }
}

Response fields

FieldTypeDescription
results[].indexintegerOriginal index in the input documents
results[].relevance_scorenumberRelevance score; higher is more relevant
results[].documentobjectOriginal text when return_documents=true