Skip to main content
POST
/
v1
/
rerank
curl -X POST "https://api.lemondata.cc/v1/rerank" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-v3",
    "query": "What is machine learning?",
    "documents": [
      "Machine learning is a subset of AI",
      "The weather is nice today",
      "Deep learning uses neural networks"
    ],
    "top_n": 2,
    "return_documents": true
  }'
{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.95,
      "document": "Machine learning is a subset of AI"
    },
    {
      "index": 2,
      "relevance_score": 0.82,
      "document": "Deep learning uses neural networks"
    }
  ],
  "model": "rerank-v3",
  "usage": {
    "prompt_tokens": 45,
    "total_tokens": 45
  }
}
Rerank documents using semantic similarity models. Useful for improving search results and RAG applications.

Request Body

model
string
required
ID of the reranker model to use (e.g., rerank-v3, bge-reranker-v2).
query
string
required
The query to rank documents against.
documents
array
required
List of documents (strings) to rerank.
top_n
integer
Number of top results to return. Defaults to all documents.
return_documents
boolean
default:"false"
Whether to include original document text in response.

Response

results
array
Ranked list of documents with scores.Each result contains:
  • index (integer): Original document index
  • relevance_score (number): Relevance score (0-1)
  • document (string): Original text (if return_documents=true)
model
string
The model used for reranking.
usage
object
Token usage statistics.
curl -X POST "https://api.lemondata.cc/v1/rerank" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-v3",
    "query": "What is machine learning?",
    "documents": [
      "Machine learning is a subset of AI",
      "The weather is nice today",
      "Deep learning uses neural networks"
    ],
    "top_n": 2,
    "return_documents": true
  }'
{
  "results": [
    {
      "index": 0,
      "relevance_score": 0.95,
      "document": "Machine learning is a subset of AI"
    },
    {
      "index": 2,
      "relevance_score": 0.82,
      "document": "Deep learning uses neural networks"
    }
  ],
  "model": "rerank-v3",
  "usage": {
    "prompt_tokens": 45,
    "total_tokens": 45
  }
}