Rerank results
curl --request POST \
--url https://api.pinecone.io/rerank \
--header 'Api-Key: <api-key>' \
--header 'Content-Type: application/json' \
--header 'X-Pinecone-Api-Version: <x-pinecone-api-version>' \
--data '
{
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
{
"id": "1",
"text": "Paris is the capital of France.",
"title": "France",
"url": "https://example.com"
}
],
"top_n": 5,
"return_documents": true,
"rank_fields": [
"text"
],
"parameters": {
"truncate": "END"
}
}
'import requests
url = "https://api.pinecone.io/rerank"
payload = {
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
{
"id": "1",
"text": "Paris is the capital of France.",
"title": "France",
"url": "https://example.com"
}
],
"top_n": 5,
"return_documents": True,
"rank_fields": ["text"],
"parameters": { "truncate": "END" }
}
headers = {
"X-Pinecone-Api-Version": "<x-pinecone-api-version>",
"Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Pinecone-Api-Version': '<x-pinecone-api-version>',
'Api-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'bge-reranker-v2-m3',
query: 'What is the capital of France?',
documents: [
{
id: '1',
text: 'Paris is the capital of France.',
title: 'France',
url: 'https://example.com'
}
],
top_n: 5,
return_documents: true,
rank_fields: ['text'],
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
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pinecone.io/rerank",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'bge-reranker-v2-m3',
'query' => 'What is the capital of France?',
'documents' => [
[
'id' => '1',
'text' => 'Paris is the capital of France.',
'title' => 'France',
'url' => 'https://example.com'
]
],
'top_n' => 5,
'return_documents' => true,
'rank_fields' => [
'text'
],
'parameters' => [
'truncate' => 'END'
]
]),
CURLOPT_HTTPHEADER => [
"Api-Key: <api-key>",
"Content-Type: application/json",
"X-Pinecone-Api-Version: <x-pinecone-api-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pinecone.io/rerank"
payload := strings.NewReader("{\n \"model\": \"bge-reranker-v2-m3\",\n \"query\": \"What is the capital of France?\",\n \"documents\": [\n {\n \"id\": \"1\",\n \"text\": \"Paris is the capital of France.\",\n \"title\": \"France\",\n \"url\": \"https://example.com\"\n }\n ],\n \"top_n\": 5,\n \"return_documents\": true,\n \"rank_fields\": [\n \"text\"\n ],\n \"parameters\": {\n \"truncate\": \"END\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Pinecone-Api-Version", "<x-pinecone-api-version>")
req.Header.Add("Api-Key", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.pinecone.io/rerank")
.header("X-Pinecone-Api-Version", "<x-pinecone-api-version>")
.header("Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"bge-reranker-v2-m3\",\n \"query\": \"What is the capital of France?\",\n \"documents\": [\n {\n \"id\": \"1\",\n \"text\": \"Paris is the capital of France.\",\n \"title\": \"France\",\n \"url\": \"https://example.com\"\n }\n ],\n \"top_n\": 5,\n \"return_documents\": true,\n \"rank_fields\": [\n \"text\"\n ],\n \"parameters\": {\n \"truncate\": \"END\"\n }\n}")
.asString();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["X-Pinecone-Api-Version"] = '<x-pinecone-api-version>'
request["Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"bge-reranker-v2-m3\",\n \"query\": \"What is the capital of France?\",\n \"documents\": [\n {\n \"id\": \"1\",\n \"text\": \"Paris is the capital of France.\",\n \"title\": \"France\",\n \"url\": \"https://example.com\"\n }\n ],\n \"top_n\": 5,\n \"return_documents\": true,\n \"rank_fields\": [\n \"text\"\n ],\n \"parameters\": {\n \"truncate\": \"END\"\n }\n}"
response = http.request(request)
puts response.read_body{
"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
}
}{
"error": {
"code": "INVALID_ARGUMENT",
"message": "Bad request. The request body included invalid request parameters."
},
"status": 400
}{
"error": {
"code": "UNAUTHENTICATED",
"message": "Invalid API key."
},
"status": 401
}{
"error": {
"code": "UNKNOWN",
"message": "Internal server error"
},
"status": 500
}Inference
Rerank results
Rerank results according to their relevance to a query.
For guidance and examples, see Rerank results.
POST
/
rerank
Rerank results
curl --request POST \
--url https://api.pinecone.io/rerank \
--header 'Api-Key: <api-key>' \
--header 'Content-Type: application/json' \
--header 'X-Pinecone-Api-Version: <x-pinecone-api-version>' \
--data '
{
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
{
"id": "1",
"text": "Paris is the capital of France.",
"title": "France",
"url": "https://example.com"
}
],
"top_n": 5,
"return_documents": true,
"rank_fields": [
"text"
],
"parameters": {
"truncate": "END"
}
}
'import requests
url = "https://api.pinecone.io/rerank"
payload = {
"model": "bge-reranker-v2-m3",
"query": "What is the capital of France?",
"documents": [
{
"id": "1",
"text": "Paris is the capital of France.",
"title": "France",
"url": "https://example.com"
}
],
"top_n": 5,
"return_documents": True,
"rank_fields": ["text"],
"parameters": { "truncate": "END" }
}
headers = {
"X-Pinecone-Api-Version": "<x-pinecone-api-version>",
"Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'X-Pinecone-Api-Version': '<x-pinecone-api-version>',
'Api-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'bge-reranker-v2-m3',
query: 'What is the capital of France?',
documents: [
{
id: '1',
text: 'Paris is the capital of France.',
title: 'France',
url: 'https://example.com'
}
],
top_n: 5,
return_documents: true,
rank_fields: ['text'],
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
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pinecone.io/rerank",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'bge-reranker-v2-m3',
'query' => 'What is the capital of France?',
'documents' => [
[
'id' => '1',
'text' => 'Paris is the capital of France.',
'title' => 'France',
'url' => 'https://example.com'
]
],
'top_n' => 5,
'return_documents' => true,
'rank_fields' => [
'text'
],
'parameters' => [
'truncate' => 'END'
]
]),
CURLOPT_HTTPHEADER => [
"Api-Key: <api-key>",
"Content-Type: application/json",
"X-Pinecone-Api-Version: <x-pinecone-api-version>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pinecone.io/rerank"
payload := strings.NewReader("{\n \"model\": \"bge-reranker-v2-m3\",\n \"query\": \"What is the capital of France?\",\n \"documents\": [\n {\n \"id\": \"1\",\n \"text\": \"Paris is the capital of France.\",\n \"title\": \"France\",\n \"url\": \"https://example.com\"\n }\n ],\n \"top_n\": 5,\n \"return_documents\": true,\n \"rank_fields\": [\n \"text\"\n ],\n \"parameters\": {\n \"truncate\": \"END\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Pinecone-Api-Version", "<x-pinecone-api-version>")
req.Header.Add("Api-Key", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://api.pinecone.io/rerank")
.header("X-Pinecone-Api-Version", "<x-pinecone-api-version>")
.header("Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"bge-reranker-v2-m3\",\n \"query\": \"What is the capital of France?\",\n \"documents\": [\n {\n \"id\": \"1\",\n \"text\": \"Paris is the capital of France.\",\n \"title\": \"France\",\n \"url\": \"https://example.com\"\n }\n ],\n \"top_n\": 5,\n \"return_documents\": true,\n \"rank_fields\": [\n \"text\"\n ],\n \"parameters\": {\n \"truncate\": \"END\"\n }\n}")
.asString();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["X-Pinecone-Api-Version"] = '<x-pinecone-api-version>'
request["Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"bge-reranker-v2-m3\",\n \"query\": \"What is the capital of France?\",\n \"documents\": [\n {\n \"id\": \"1\",\n \"text\": \"Paris is the capital of France.\",\n \"title\": \"France\",\n \"url\": \"https://example.com\"\n }\n ],\n \"top_n\": 5,\n \"return_documents\": true,\n \"rank_fields\": [\n \"text\"\n ],\n \"parameters\": {\n \"truncate\": \"END\"\n }\n}"
response = http.request(request)
puts response.read_body{
"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
}
}{
"error": {
"code": "INVALID_ARGUMENT",
"message": "Bad request. The request body included invalid request parameters."
},
"status": 400
}{
"error": {
"code": "UNAUTHENTICATED",
"message": "Invalid API key."
},
"status": 401
}{
"error": {
"code": "UNKNOWN",
"message": "Internal server error"
},
"status": 500
}Authorizations
Headers
Required date-based version header
Body
application/json
Rerank documents for the given query
The query to rerank documents against.
Example:
"What is the capital of France?"
The documents to rerank.
The number of results to return sorted by relevance. Defaults to the number of inputs.
Example:
5
Whether to return the documents in the response.
Example:
true
The field(s) to consider for reranking. If not provided, the default is ["text"].
The number of fields supported is model-specific.
Additional model-specific parameters. Refer to the model guide for available model parameters.
Example:
{ "truncate": "END" }
Was this page helpful?