Skip to main content
POST
https://llm.ai-nebula.com
/
v1
/
rerank
Rerank
curl --request POST \
  --url https://llm.ai-nebula.com/v1/rerank \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "query": "<string>",
  "documents": [
    {}
  ],
  "top_n": 123,
  "return_documents": true
}
'
{
  "model": "rerank-v1",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.95,
      "document": "AI is a branch of computer science dedicated to creating intelligent systems."
    },
    {
      "index": 1,
      "relevance_score": 0.82,
      "document": "Machine learning is a subfield of AI focused on learning from data."
    },
    {
      "index": 2,
      "relevance_score": 0.65,
      "document": "Deep learning uses neural networks for pattern recognition."
    }
  ],
  "usage": {
    "total_tokens": 128
  }
}

Introduction

Rerank documents by relevance to a query, commonly used in RAG to optimize retrieval results.

Authentication

Authorization
string
required
Bearer Token, e.g. Bearer sk-xxxxxxxxxx

Request Parameters

model
string
required
Model name, e.g. rerank-v1
query
string
required
Query text
documents
array
required
List of documents to rank
top_n
integer
Return top N results (default: all)
return_documents
boolean
default:"false"
Return document content

cURL Example

curl https://llm.ai-nebula.com/v1/rerank \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-XyLy**************************mIqSt" \
  -d '{
    "model": "rerank-v1",
    "query": "What is artificial intelligence?",
    "documents": [
      "AI is a branch of computer science dedicated to creating intelligent systems.",
      "Machine learning is a subfield of AI focused on learning from data.",
      "Deep learning uses neural networks for pattern recognition."
    ],
    "top_n": 3,
    "return_documents": true
  }'

Python Example

import requests

url = "https://llm.ai-nebula.com/v1/rerank"
headers = {
    "Authorization": "Bearer sk-XyLy**************************mIqSt",
    "Content-Type": "application/json"
}

data = {
    "model": "rerank-v1",
    "query": "What is artificial intelligence?",
    "documents": [
        "AI is a branch of computer science dedicated to creating intelligent systems.",
        "Machine learning is a subfield of AI focused on learning from data.",
        "Deep learning uses neural networks for pattern recognition."
    ],
    "top_n": 3,
    "return_documents": True
}

response = requests.post(url, headers=headers, json=data)
print(response.json())
{
  "model": "rerank-v1",
  "results": [
    {
      "index": 0,
      "relevance_score": 0.95,
      "document": "AI is a branch of computer science dedicated to creating intelligent systems."
    },
    {
      "index": 1,
      "relevance_score": 0.82,
      "document": "Machine learning is a subfield of AI focused on learning from data."
    },
    {
      "index": 2,
      "relevance_score": 0.65,
      "document": "Deep learning uses neural networks for pattern recognition."
    }
  ],
  "usage": {
    "total_tokens": 128
  }
}

Response Fields

FieldTypeDescription
results[].indexintegerOriginal document index
results[].relevance_scorefloatRelevance score (0-1)
results[].documentstringDocument content (when return_documents=true)

Notes

  • Common in RAG: first vector search for candidates, then rerank to optimize
  • Higher relevance_score means more relevant to query
  • Requires requests library: pip install requests