Rerank

Score a set of documents against a query and order them by relevance.

POSThttps://your-instance.com/v1/rerank

The usual second stage of a retrieval pipeline: fetch candidates cheaply with embeddings, then rerank the shortlist with a model that reads query and document together. Slower per document, and much more accurate.

  • modelstringrequired

    Rerank model to use.

  • querystringrequired

    The query to score documents against.

  • documentsstring[]required

    Candidate documents to order.

  • top_ninteger

    Return only the best N. Defaults to all of them.

curl
curl https://your-instance.com/v1/rerank \
  -H "Authorization: Bearer $CLAWROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "rerank-multilingual-v3",
    "query": "How do I rotate an API key?",
    "documents": [
      "Keys can be revoked from the console.",
      "Billing runs on the first of the month.",
      "Create a replacement key, deploy it, then delete the old one."
    ],
    "top_n": 2
  }'
200 OK
{
  "results": [
    { "index": 2, "relevance_score": 0.94 },
    { "index": 0, "relevance_score": 0.71 }
  ]
}

index refers back to the position in the documents array you sent, so you can map scores onto your own records without echoing the text back.