Cohere Reranker
The Cohere Reranker is a postprocessor that uses the Cohere API to rerank the results of a search query.
Setup
Firstly, you will need to install the llamaindex
package.
Now, you will need to sign up for an API key at Cohere. Once you have your API key you can import the necessary modules and create a new instance of the CohereRerank
class.
Load and index documents
For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.
Increase similarity topK to retrieve more results
The default value for similarityTopK
is 2. This means that only the most similar document will be returned. To retrieve more results, you can increase the value of similarityTopK
.
Create a new instance of the CohereRerank class
Then you can create a new instance of the CohereRerank
class and pass in your API key and the number of results you want to return.
Create a query engine with the retriever and node postprocessor
API Reference
Last updated on