Cohere reranker
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. This builds on top of ideas in the ContextualCompressionRetriever.
%pip install --upgrade --quiet cohere
%pip install --upgrade --quiet faiss
# OR (depending on Python version)
%pip install --upgrade --quiet faiss-cpu
# get a new token: https://dashboard.cohere.ai/
import getpass
import os
if "COHERE_API_KEY" not in os.environ:
os.environ["COHERE_API_KEY"] = getpass.getpass("Cohere API Key:")
# Helper function for printing docs
def pretty_print_docs(docs):
print(
f"\n{'-' * 100}\n".join(
[f"Document {i + 1}:\n\n" + d.page_content for i, d in enumerate(docs)]
)
)