Skip to main content
A reranker is a model that reorders retrieved documents by relevance to a given query. It takes a query and a set of text inputs (called documents) and returns a relevancy score for each document. Use reranking to filter and prioritize the most relevant results. In retrieval-augmented generation (RAG) pipelines, the reranking step sits between initial retrieval and final generation. It acts as a quality filter, refining the documents passed to the language model so the answer is grounded in the most relevant context.

How the rerank API works

Together’s rerank API takes a query and a list of documents, and returns a relevancy score and ordering index for each document. It can also filter the response to the top n most relevant documents. Key features:
  • Long 8K context per document.
  • Low latency for fast search queries.

Get started

Rerank models like mxbai-rerank-large-v2 are only available for dedicated model inference. Bring up a dedicated endpoint to use reranking in your applications.

Example with text

The example below uses the rerank API endpoint to reorder a list of documents from most to least relevant to the query What animals can I find near Peru?.

Example with JSON data (dedicated model inference only)

The following JSON data format with rank_fields is only supported on dedicated model inference running the Salesforce/Llama-Rank-V1 model. All other rerank endpoints accept documents only as a list of strings.
When using Salesforce/Llama-Rank-V1, pass a JSON object and specify the fields to rank over and the order to consider them in. If you don’t pass rank_fields, the model defaults to the text key. The example below shows passing in some emails, with the query Which pricing did we get from Oracle?.
The documents parameter is a list of objects with the keys from, to, date, subject, and text. The rank_fields parameter names which keys to rank over and the order to consider them in. Because return_documents is set to true, the response also includes each email alongside the rankings.
JSON