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/rerankParameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Rerank model identifier |
query | string | Yes | The query text |
documents | array | Yes | Array of candidate document strings |
top_n | integer | No | Return the top N most relevant |
return_documents | boolean | No | Include 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
| Field | Type | Description |
|---|---|---|
results[].index | integer | Original index in the input documents |
results[].relevance_score | number | Relevance score; higher is more relevant |
results[].document | object | Original text when return_documents=true |