GreenPT Docs

Reranker

Rerank search results to improve relevance and accuracy.

POST

Rerank search results to improve relevance and accuracy.

What is a reranker?

The goal of a search system is to find the most relevant results quickly and efficiently. Traditionally, methods like BM25 or tf-idf have been used to rank search results based on keyword matching. Recent methods, such as embedding-based cosine similarity, have been implemented in many vector databases. These methods are straightforward but can sometimes miss the subtleties of language, and most importantly, the interaction between documents and a query's intent.

This is where the reranker shines. A reranker is an advanced AI model that takes the initial set of results from a search, often provided by an embeddings/token-based search, and reevaluates them to ensure they align more closely with the user's intent. It looks beyond the surface-level matching of terms to consider the deeper interaction between the search query and the content of the documents.

API endpoint

Rerank search results to improve relevance and accuracy using GreenPT models.

POST /v1/rerank

Takes a query and a list of documents and returns a reranked list based on relevance.

Example request

curl --location 'https://api.greenpt.ai/v1/rerank' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk-your_api_key' \
  --data '{
    "model": "green-rerank",
    "query": "What are the benefits of renewable energy?",
    "documents": [
      "Solar panels convert sunlight into electricity using photovoltaic cells.",
      "Renewable energy sources like wind and solar reduce greenhouse gas emissions and help combat climate change.",
      "The installation cost of solar panels has decreased significantly over the past decade.",
      "Fossil fuels are finite resources that will eventually be depleted.",
      "Wind turbines can generate electricity even at night, unlike solar panels."
    ],
    "top_n": 3,
    "return_documents": true
  }'
const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
myHeaders.append('Authorization', 'Bearer sk-your_api_key');

const raw = JSON.stringify({
  model: 'green-rerank',
  query: 'What are the benefits of renewable energy?',
  documents: [
    'Solar panels convert sunlight into electricity using photovoltaic cells.',
    'Renewable energy sources like wind and solar reduce greenhouse gas emissions and help combat climate change.',
    'The installation cost of solar panels has decreased significantly over the past decade.',
    'Fossil fuels are finite resources that will eventually be depleted.',
    'Wind turbines can generate electricity even at night, unlike solar panels.',
  ],
  top_n: 3,
  return_documents: true,
});

const requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow',
};

fetch('https://api.greenpt.ai/v1/rerank', requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
import requests
import json

url = "https://api.greenpt.ai/v1/rerank"

payload = json.dumps({
  "model": "green-rerank",
  "query": "What are the benefits of renewable energy?",
  "documents": [
    "Solar panels convert sunlight into electricity using photovoltaic cells.",
    "Renewable energy sources like wind and solar reduce greenhouse gas emissions and help combat climate change.",
    "The installation cost of solar panels has decreased significantly over the past decade.",
    "Fossil fuels are finite resources that will eventually be depleted.",
    "Wind turbines can generate electricity even at night, unlike solar panels."
  ],
  "top_n": 3,
  "return_documents": True
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer sk-your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Parameters

ParameterTypeRequiredDescription
modelstringYesID of the model to use. Currently supports "green-rerank".
querystringYesThe search query to use for reranking the documents.
documentsarrayYesList of documents to be reranked. Can be strings or objects with text content.
top_nintegerNoNumber of most relevant documents to return. Defaults to returning all documents.
return_documentsbooleanNoWhether to return the document text alongside the relevance scores. Defaults to false.

Response format

{
  "id": "rerank-26b2353f140341579c5ee22871c24ee5",
  "model": "green-rerank",
  "usage": {
    "total_tokens": 157,
    "inferenceTiming": {
      "inferenceTimeMs": 30.504435000009835
    }
  },
  "results": [
    {
      "index": 1,
      "document": {
        "text": "Renewable energy sources like wind and solar reduce greenhouse gas emissions and help combat climate change."
      },
      "relevance_score": 0.94677734375
    },
    {
      "index": 2,
      "document": {
        "text": "The installation cost of solar panels has decreased significantly over the past decade."
      },
      "relevance_score": 0.0005955696105957031
    },
    {
      "index": 4,
      "document": {
        "text": "Wind turbines can generate electricity even at night, unlike solar panels."
      },
      "relevance_score": 0.00040459632873535156
    }
  ]
}

Use cases

  • Search enhancement: improve the relevance of search results from vector databases.
  • Information retrieval: fine-tune document ranking based on user intent.
  • Question answering: rank documents by their likelihood to contain relevant answers.
  • Content discovery: surface the most relevant content from large document collections.
  • Hybrid search: combine traditional keyword search with AI-powered reranking.

Models

green-rerank is backed by Qwen3-Reranker-4B: a multilingual (100+ languages) cross-encoder reranker with a 32k token context that outputs a per-document relevance score.

See the full list of available models on the Models page.

On this page