VoyageAI Reranker
Voyage AI provides cutting-edge embedding/vectorizations models.
This notebook shows how to use Voyage AI's rerank endpoint in a retriever. This builds on top of ideas in the ContextualCompressionRetriever.
%pip install --upgrade --quiet voyageai
%pip install --upgrade --quiet langchain-voyageai
%pip install --upgrade --quiet faiss
# OR (depending on Python version)
%pip install --upgrade --quiet faiss-cpu
# To obtain your key, create an account on https://www.voyageai.com
import getpass
import os
if "VOYAGE_API_KEY" not in os.environ:
os.environ["VOYAGE_API_KEY"] = getpass.getpass("Voyage AI 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)]
)
)