inference.eu

POST /v1/rerank

Rerank API: sort search results by relevance, processed in the EU

The rerank endpoint takes a query and a list of candidate documents and returns them sorted by how well each one answers the query. It sits between vector search and the language model in a RAG pipeline, and is often the cheapest way to make answers noticeably more accurate. Queries and documents are processed in European data centres.

  1. 01API format: OpenAI
  2. 02EU data centres
  3. 03Covered by one DPA
POST /v1/rerank
curl https://api.inference.eu/v1/rerank \
  -H "Authorization: Bearer $INFERENCE_EU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "bge-reranker-v2-m3",
    "query": "Can an employee carry unused holiday into next year?",
    "documents": [
      "Unused annual leave may be carried over until 31 March of the following year.",
      "The office is closed between Christmas and New Year.",
      "Urlaubsansprüche verfallen nicht, wenn der Arbeitgeber nicht auf den Verfall hingewiesen hat.",
      "Expense claims must be submitted within 30 days."
    ],
    "top_n": 2
  }'

# {"results": [{"index": 0, "relevance_score": 0.94}, {"index": 2, "relevance_score": 0.81}], ...}

What the endpoint does

POST /v1/rerank takes a model, a query and an array of documents as strings. A reranker such as bge-reranker-v2-m3 reads the query and each document together, which lets it judge relevance far more precisely than comparing two separately computed embeddings. The cost is speed, which is why you rerank a short list of candidates rather than a whole collection.

The response contains a results array sorted from most to least relevant. Each result has the index of the document in your original array and a relevance_score. Use the index to look up the document and its metadata on your side.

Key request fields

top_n limits how many results come back; leave it out to receive a score for every document. Set return_documents to true if you want each result to include the document text, which saves a lookup but makes the response larger.

The request shape follows the rerank format used by most search libraries and RAG frameworks, so integrations that support a custom rerank endpoint can usually be pointed at inference.eu by changing the URL, key and model. bge-reranker-v2-m3 is multilingual, so a query in English can rank German or French passages correctly.

Embeddings plus rerank, the standard RAG pattern

First, embed the user's question and fetch around 30 to 50 nearest chunks from your vector database. This step is fast and has high recall but imprecise ordering. Second, send the question and those chunks to the rerank endpoint and keep the top three to eight results. Third, put those chunks into the prompt of a chat model and ask it to answer with references to them.

You can also use the score as a threshold. If even the best result scores low, tell the user that the knowledge base has no good answer instead of letting the model guess. Tune that threshold on a set of real questions.

Errors and edge cases

Each query and document pair must fit the reranker's input length. Long documents are truncated to that length on the model's side, so rerank chunks of similar size to the ones you embedded, not whole files. An empty documents array or an empty query returns a 400 error.

Scores are only comparable within one model; do not mix thresholds across rerankers. Very large candidate lists slow the request down without improving results much, because a good first-stage search already puts the answer in the top 50. The number of documents per request depends on your plan, and we confirm it with you.

Rerank: common questions

The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.

Ask a question

Move your AI workloads to EU infrastructure

Tell us which models you use and roughly how much traffic you have. We reply within one working day with pricing and next steps.

  • Reply within one working day
  • Pricing for your volume
  • DPA ready to sign