Reranker
gllm-retrieval | Involves EM | Tutorial: Reranker | API Reference
What's a Reranker?
A reranker is a component that reorders retrieved chunks based on their relevance to a query. After initial retrieval returns a set of candidate chunks, the reranker scores and sorts them to ensure the most relevant content appears first. This improves the quality of context provided to language models in RAG pipelines.
Rerankers are particularly useful when:
Initial retrieval returns many candidates that need prioritization
You want to combine results from multiple retrieval sources
The retrieval method does not perfectly capture semantic relevance
Installation
pip install --extra-index-url https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/ "gllm-retrieval"pip install --extra-index-url https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/ "gllm-retrieval"FOR /F "tokens=*" %T IN ('gcloud auth print-access-token') DO pip install --extra-index-url "https://oauth2accesstoken:%T@glsdk.gdplabs.id/gen-ai-internal/simple/" "gllm-retrieval"Quickstart
Let's start with a basic example using SimilarityBasedReranker, which uses embedding similarity to rerank chunks:
Expected Output
The chunks are reordered with the most relevant content first:
Available Rerankers
The SDK provides multiple reranker implementations for different use cases:
SimilarityBasedReranker
Uses embedding similarity scores
General-purpose semantic reranking
TEIReranker
Uses Text Embedding Inference endpoint
High-performance, self-hosted deployments
FlagEmbeddingReranker
Uses FlagEmbedding models
Multilingual and specialized domains
CohereBedrockReranker
Uses AWS Bedrock Cohere service
Cloud-based, managed reranking
Similarity-Based Reranking
The SimilarityBasedReranker calculates embedding similarity between the query and each chunk, then sorts by score:
TEI Reranking
The TEIReranker uses a reranker model hosted on Text Embedding Inference (TEI):
FlagEmbedding Reranking
The FlagEmbeddingReranker uses FlagEmbedding models for reranking:
Installation: FlagEmbeddingReranker requires the FlagEmbedding package. Install with:
Cohere Bedrock Reranking
The CohereBedrockReranker uses Cohere's reranker models hosted on AWS Bedrock:
Installation: CohereBedrockReranker requires the cohere package. Install with:
Using Rerankers in Pipelines
Rerankers integrate seamlessly with the SDK's pipeline system:
API Reference
For detailed API documentation, see the Reranker API Reference.
Last updated