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.Documentation Index
Fetch the complete documentation index at: https://docs.together.ai/llms.txt
Use this file to discover all available pages before exploring further.
How the rerank API works
Together’s rerank API takes aquery 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
Example with text
The example below uses the rerank API endpoint to reorder a list ofdocuments from most to least relevant to the query What animals can I find near Peru?.
Example with JSON data (dedicated endpoints only)
The following JSON data format with
rank_fields is only supported on dedicated endpoints running the Salesforce/Llama-Rank-V1 model. All other rerank endpoints accept documents only as a list of strings.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?.
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