Skip to main content
Pinecone Docs
current

Search documentation

Type to search this documentation.

Rerank results

Rerank results according to their relevance to a query.

For guidance and examples, see Rerank results.

POST /rerank

cURL
curl --request POST \
  --url https://api.pinecone.io/rerank \
  --header 'Api-Key: <api-key>' \
  --header 'X-Pinecone-Api-Version: <x-pinecone-api-version>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "bge-reranker-v2-m3",
  "query": "What is the capital of France?",
  "top_n": 5,
  "return_documents": true,
  "rank_fields": [
    "<string>"
  ],
  "documents": [
    {
      "id": "1",
      "text": "Paris is the capital of France.",
      "title": "France",
      "url": "https://example.com"
    }
  ],
  "parameters": {
    "truncate": "END"
  }
}'
Python
import requests

url = "https://api.pinecone.io/rerank"

payload = {
  "model": "bge-reranker-v2-m3",
  "query": "What is the capital of France?",
  "top_n": 5,
  "return_documents": True,
  "rank_fields": [
    "<string>"
  ],
  "documents": [
    {
      "id": "1",
      "text": "Paris is the capital of France.",
      "title": "France",
      "url": "https://example.com"
    }
  ],
  "parameters": {
    "truncate": "END"
  }
}
headers = {
    "Api-Key": "<api-key>",
    "X-Pinecone-Api-Version": "<x-pinecone-api-version>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
JavaScript
const options = {method: "POST", headers: {"Api-Key": "<api-key>", "X-Pinecone-Api-Version": "<x-pinecone-api-version>", "Content-Type": "application/json"}, body: JSON.stringify({
  "model": "bge-reranker-v2-m3",
  "query": "What is the capital of France?",
  "top_n": 5,
  "return_documents": true,
  "rank_fields": [
    "<string>"
  ],
  "documents": [
    {
      "id": "1",
      "text": "Paris is the capital of France.",
      "title": "France",
      "url": "https://example.com"
    }
  ],
  "parameters": {
    "truncate": "END"
  }
})};

fetch("https://api.pinecone.io/rerank", options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
PHP
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.pinecone.io/rerank",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\"model\":\"bge-reranker-v2-m3\",\"query\":\"What is the capital of France?\",\"top_n\":5,\"return_documents\":true,\"rank_fields\":[\"<string>\"],\"documents\":[{\"id\":\"1\",\"text\":\"Paris is the capital of France.\",\"title\":\"France\",\"url\":\"https://example.com\"}],\"parameters\":{\"truncate\":\"END\"}}",
  CURLOPT_HTTPHEADER => [
    "Api-Key: <api-key>",
    "X-Pinecone-Api-Version: <x-pinecone-api-version>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.pinecone.io/rerank"

	payload := strings.NewReader("{\"model\":\"bge-reranker-v2-m3\",\"query\":\"What is the capital of France?\",\"top_n\":5,\"return_documents\":true,\"rank_fields\":[\"<string>\"],\"documents\":[{\"id\":\"1\",\"text\":\"Paris is the capital of France.\",\"title\":\"France\",\"url\":\"https://example.com\"}],\"parameters\":{\"truncate\":\"END\"}}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Api-Key", "<api-key>")
	req.Header.Add("X-Pinecone-Api-Version", "<x-pinecone-api-version>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
Java
HttpResponse<String> response = Unirest.post("https://api.pinecone.io/rerank")
  .header("Api-Key", "<api-key>")
  .header("X-Pinecone-Api-Version", "<x-pinecone-api-version>")
  .header("Content-Type", "application/json")
  .body("{\"model\":\"bge-reranker-v2-m3\",\"query\":\"What is the capital of France?\",\"top_n\":5,\"return_documents\":true,\"rank_fields\":[\"<string>\"],\"documents\":[{\"id\":\"1\",\"text\":\"Paris is the capital of France.\",\"title\":\"France\",\"url\":\"https://example.com\"}],\"parameters\":{\"truncate\":\"END\"}}")
  .asString();
Ruby
require 'uri'
require 'net/http'

url = URI("https://api.pinecone.io/rerank")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Api-Key"] = '<api-key>'
request["X-Pinecone-Api-Version"] = '<x-pinecone-api-version>'
request["Content-Type"] = 'application/json'
request.body = "{\"model\":\"bge-reranker-v2-m3\",\"query\":\"What is the capital of France?\",\"top_n\":5,\"return_documents\":true,\"rank_fields\":[\"<string>\"],\"documents\":[{\"id\":\"1\",\"text\":\"Paris is the capital of France.\",\"title\":\"France\",\"url\":\"https://example.com\"}],\"parameters\":{\"truncate\":\"END\"}}"

response = http.request(request)
puts response.read_body
200
{
  "model": "bge-reranker-v2-m3",
  "data": [
    {
      "index": 123,
      "score": 0.5,
      "document": {
        "id": "1",
        "text": "Paris is the capital of France.",
        "title": "France",
        "url": "https://example.com"
      }
    }
  ],
  "usage": {
    "rerank_units": 1
  }
}
400
{
  "error": {
    "code": "INVALID_ARGUMENT",
    "message": "Bad request. The request body included invalid request parameters."
  },
  "status": 400
}
401
{
  "error": {
    "code": "UNAUTHENTICATED",
    "message": "Invalid API key."
  },
  "status": 401
}
500
{
  "error": {
    "code": "UNKNOWN",
    "message": "Internal server error"
  },
  "status": 500
}
Api-Keystringrequired

An API Key is required to call Pinecone APIs. Get yours from the console.

X-Pinecone-Api-Versionstringrequired

Required date-based version header

Typestring
Default2026-07

Rerank documents for the given query

modelstringrequired

Example: bge-reranker-v2-m3

Typestring

The model to use for reranking.

querystringrequired

The query to rerank documents against.

Example: What is the capital of France?

Typestring
top_n?integer

The number of results to return sorted by relevance. Defaults to the number of inputs.

Example: 5

Typeinteger
return_documents?boolean

Whether to return the documents in the response.

Example: true

Typeboolean
Defaulttrue
rank_fields?string[]
Typestring[]
Default['text']

The field(s) to consider for reranking. If not provided, the default is ["text"]. The number of fields supported is model-specific.

documentsobject[]required

The documents to rerank.

Typeobject[]
parameters?object

Additional model-specific parameters. Refer to the model guide for available model parameters.

200 — OK

The result of a reranking request.

modelstringrequired

The model used to rerank documents.

Example: bge-reranker-v2-m3

Typestring
dataobject[]required

The reranked documents.

Typeobject[]
Show child attributes
indexintegerrequired

The index position of the document from the original request.

Typeinteger
scorenumberrequired

The relevance of the document to the query, normalized between 0 and 1, with scores closer to 1 indicating higher relevance.

Example: 0.5

Typenumber
document?object

Document for reranking

Typeobject
usageobjectrequired

Usage statistics for the model inference.

Typeobject
Show child attributes
rerank_units?integer

The number of rerank units consumed by this operation.

Required range: 0 <= x. Example: 1

Typeinteger
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu