Skip to main content
Cohere is a Canadian startup that provides natural language processing models that help companies improve human-machine interactions.
This notebook shows how to use Cohere’s rerank endpoint in a retriever.

Set up the base vector store retriever

Let’s start by initializing a simple vector store retriever and storing the 2023 State of the Union speech (in chunks). We can set up the retriever to retrieve a high number (20) of docs.
The langchain-community package is no longer maintained. Examples that import from langchain_community may be outdated or broken. Use with caution.

Doing reranking with CohereRerank

Now let’s wrap our base retriever with a ContextualCompressionRetriever. We’ll add an CohereRerank, uses the Cohere rerank endpoint to rerank the returned results. Do note that it is mandatory to specify the model name in CohereRerank!
You can of course use this retriever within a QA pipeline