What is a reranker?
A reranker is a specialized model that improves search relevancy by reassessing and reordering a set of retrieved documents based on their 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 relative to the given query. This process helps filter and prioritize the most pertinent information, enhancing the quality of search results. In Retrieval Augmented Generation (RAG) pipelines, the reranking step sits between the initial retrieval step and the final generation phase. It acts as a quality filter, refining the selection of documents that will be used as context for language models. By ensuring that only the most relevant information is passed to the generation phase, rerankers play a crucial role in improving the accuracy of generated responses while potentially reducing processing costs.How does Together’s Rerank API work?
Together’s serverless Rerank API allows you to seamlessly integrate supported rerank models into your enterprise applications. It takes in aquery
and a number of documents
, and outputs a relevancy score and ordering index for each document. It can also filter its response to the n most relevant documents.
Together’s Rerank API is also compatible with Cohere Rerank, making it easy to try out our reranker models on your existing applications.
Key features of Together’s Rerank API include:
- Flagship support for LlamaRank, Salesforce’s reranker model
- Support for JSON and tabular data
- Long 8K context per document
- Low latency for fast search queries
- Full compatibility with Cohere’s Rerank API
Cohere Rerank compatibility
The Together Rerank endpoint is compatible with Cohere Rerank, making it easy to test out models like LlamaRank for your existing applications. Simply switch it out by updating theURL
, API key
and model
.
Python
Get Started
Example with text
In the example below, we use the Rerank API endpoint to index the list ofdocuments
from most to least relevant to the query What animals can I find near Peru?
.
Request
In this example, the documents being passed in are a list of strings:
Python
Example with JSON Data
Alternatively, you can pass in a JSON object and specify the fields you’d like to rank over, and the order they should be considered in. If you do not pass in anyrank_fields
, it will default to the text key.
The example below shows passing in some emails, with the query Which pricing did we get from Oracle?
.
Request
Python
documents
parameter, we are passing in a list of objects which have the key values: ['from', 'to', 'date', 'subject', 'text']
. As part of the Rerank call, under rank_fields
we are specifying which keys to rank over, as well as the order in which the key value pairs should be considered. Finally, we’re also setting return_documents
to True since we want to see them in the response.
Response
JSON