Add Vertex AI Ranking API as reranker option#233
Add Vertex AI Ranking API as reranker option#233harsh-kumar-patwa wants to merge 2 commits intoThe-OpenROAD-Project:masterfrom
Conversation
Add support for Google Vertex AI Ranking API alongside the existing HuggingFace CrossEncoder reranker. The reranker type is controlled by the RERANKER_TYPE env var (default: HF). When RERANKER_TYPE=VERTEX_AI, uses langchain-google-community's VertexAIRank as a drop-in replacement for CrossEncoderReranker in ContextualCompressionRetriever. Signed-off-by: Harsh Kumar Patwa <harshkumarpatwa@gmail.com> Signed-off-by: Harsh Kumar <harshkumar3446@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds Google Vertex AI Ranking API as an optional reranker in the backend hybrid retriever chain, controlled via environment configuration, while keeping HuggingFace CrossEncoder as the default.
Changes:
- Add
RERANKER_TYPE-based selection between HuggingFace CrossEncoder reranker and Vertex AI Ranking API (VertexAIRank). - Add configuration knobs for Vertex AI (
VERTEX_AI_PROJECT_ID,VERTEX_AI_LOCATION) to.env.example. - Add dependency on
langchain-google-community[vertexaisearch]and tests covering the Vertex AI reranker path + missing project ID validation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
backend/src/chains/hybrid_retriever_chain.py |
Select reranker implementation (HF vs Vertex AI) based on RERANKER_TYPE and configure VertexAIRank. |
backend/tests/test_hybrid_retriever_chain.py |
Add unit tests for Vertex AI reranker creation and validation error when project ID is missing. |
backend/pyproject.toml |
Add langchain-google-community[vertexaisearch] dependency for VertexAIRank. |
backend/.env.example |
Document new reranker-related environment variables. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| logging.info("Using HuggingFace CrossEncoder reranker") | ||
|
|
||
| self.retriever = ContextualCompressionRetriever( | ||
| base_compressor=compressor, base_retriever=ensemble_retriever | ||
| ) |
There was a problem hiding this comment.
ensemble_retriever can be referenced here even when it was never assigned. If self.vector_db is None or processed_docs is empty, bm25_retriever is never set, which prevents the ensemble_retriever = EnsembleRetriever(...) block from running; later this code still uses ensemble_retriever, leading to UnboundLocalError. Initialize bm25_retriever/ensemble_retriever to None and either raise a clear error when the ensemble cannot be constructed or provide a fallback retriever composition before reaching this point.
Initialize bm25_retriever to None and raise a clear ValueError if the ensemble retriever cannot be constructed due to missing sub-retrievers. Signed-off-by: Harsh Kumar Patwa <harshkumarpatwa@gmail.com> Signed-off-by: Harsh Kumar <harshkumar3446@gmail.com>
Fixes #91
Summary
RERANKER_TYPEenv var (HForVERTEX_AI, defaults toHF)langchain-google-community[vertexaisearch]which providesVertexAIRank— a drop-inDocumentCompressorforContextualCompressionRetrieverChanges
backend/src/chains/hybrid_retriever_chain.py— conditionally useVertexAIRankorCrossEncoderRerankerbased onRERANKER_TYPEenv varbackend/.env.example— addedRERANKER_TYPE,VERTEX_AI_PROJECT_ID,VERTEX_AI_LOCATIONbackend/pyproject.toml— addedlangchain-google-community[vertexaisearch]dependencybackend/tests/test_hybrid_retriever_chain.py— added tests for Vertex AI reranker path and missing project ID validationConfig
Test plan
RERANKER_TYPE=HF(default)