feat(py/google-genai): add Vertex AI rerankers and evaluators#4428
feat(py/google-genai): add Vertex AI rerankers and evaluators#4428
Conversation
Summary of ChangesHello @yesudeep, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the capabilities of the Google GenAI plugin by integrating Vertex AI's advanced reranking and evaluation services. It allows users to improve the relevance of retrieved documents in RAG pipelines and to automatically assess the quality and safety of AI model outputs using a suite of metrics. A foundational improvement to HTTP client management in asynchronous contexts has also been included to ensure stability and performance for these new features. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant feature addition, introducing Vertex AI rerankers and evaluators to the Google GenAI plugin. These are valuable for improving RAG quality and assessing model outputs. The implementation is well-structured, with clear separation of concerns into new modules for rerankers, evaluators, and a core HTTP client utility. The new http_client with per-event-loop caching is a robust solution to a common problem with async clients. The addition of a comprehensive sample application with an automated setup script is excellent for developer experience. The code is of high quality, and I have a few suggestions for refactoring to improve maintainability and adherence to best practices.
py/plugins/google-genai/src/genkit/plugins/google_genai/evaluators/evaluation.py
Show resolved
Hide resolved
py/plugins/google-genai/src/genkit/plugins/google_genai/google.py
Outdated
Show resolved
Hide resolved
py/plugins/google-genai/src/genkit/plugins/google_genai/rerankers/reranker.py
Outdated
Show resolved
Hide resolved
b04be26 to
6aaaeb1
Compare
89a7893 to
8415873
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant new features: Vertex AI rerankers and evaluators, along with a core HTTP client caching mechanism. The implementation is generally of high quality, with good structure, documentation, and comprehensive tests.
My review focuses on a few key areas for improvement:
- Asynchronous Correctness: There are a couple of instances of blocking I/O calls within async functions for authentication token refreshing. These should be converted to their async equivalents to avoid blocking the event loop.
- Error Handling: The exception handling in the new API clients can be made more specific to avoid catching unexpected errors.
- Code Simplification: A minor opportunity for code simplification in the reranker response handling.
- Test Accuracy: A small correction is needed in a test fixture to ensure it correctly mocks the state for the code under test.
Overall, this is a great contribution that adds valuable capabilities to the Genkit Google GenAI plugin. The new sample is also very helpful for demonstrating these features.
py/plugins/google-genai/src/genkit/plugins/google_genai/evaluators/evaluation.py
Outdated
Show resolved
Hide resolved
py/plugins/google-genai/src/genkit/plugins/google_genai/rerankers/reranker.py
Outdated
Show resolved
Hide resolved
py/plugins/google-genai/src/genkit/plugins/google_genai/evaluators/evaluation.py
Outdated
Show resolved
Hide resolved
py/plugins/google-genai/src/genkit/plugins/google_genai/rerankers/reranker.py
Outdated
Show resolved
Hide resolved
8415873 to
d7e9fd7
Compare
|
/gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
d7e9fd7 to
5d99e74
Compare
|
/gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
88c797c to
674de70
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for Vertex AI rerankers and evaluators. The implementation for both features is well-structured and includes comprehensive unit tests and a new sample application.
However, there are a few significant issues to address:
- The reranker implementation currently drops all original metadata from documents, which could break RAG pipelines.
- The evaluator feature appears to be incompletely integrated. The
VertexAIplugin does not register the evaluator actions, and the documentation provides an incorrect example of how to configure them, making the feature unusable as is.
I've also included a minor suggestion to improve the test code's clarity. Overall, this is a great addition, but the issues with metadata loss and evaluator integration need to be resolved before merging.
|
Addressed. |
Adds Vertex AI rerankers and evaluators to the Google GenAI plugin, enabling RAG quality improvements and automated model output evaluation. ## Vertex AI Rerankers Rerankers improve RAG quality by re-scoring documents based on semantic relevance to a query (two-stage retrieval pattern): 1. Fast retrieval: Get many candidates quickly 2. Quality reranking: Score candidates by relevance, keep top-k Supported models: - semantic-ranker-default@latest - semantic-ranker-default-004 - semantic-ranker-fast-004 - semantic-ranker-default-003 - semantic-ranker-default-002 ## Vertex AI Evaluators Evaluators assess model outputs for quality metrics using the Vertex AI Evaluation API. Supported metrics: - BLEU, ROUGE (translation/summarization quality) - FLUENCY (language mastery) - SAFETY (harmful content detection) - GROUNDEDNESS (hallucination detection) - SUMMARIZATION_QUALITY/HELPFULNESS/VERBOSITY ## HTTP Client Caching Introduces genkit.core.http_client module for per-event-loop client caching, solving "bound to different event loop" errors with httpx. ## Sample New sample: py/samples/vertexai-rerank-eval/ demonstrates both features with automated gcloud setup.
- Add reusable gcloud functions: check_gcloud_installed, check_gcloud_auth, is_api_enabled, enable_required_apis, run_gcp_setup - Interactive API enablement: only prompts if APIs are not enabled - Refactor vertexai-rerank-eval, firestore-retreiver, google-genai-vertexai-hello, google-genai-vertexai-image to use the common functions - Reduces ~175 lines of duplicate code per sample
- Fix README.md evaluator example to show correct usage (ai.evaluate()) - Update test fixture to use constructor parameters instead of setting private attributes
0e19bac to
bbb7e0e
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces significant new capabilities by adding support for Vertex AI rerankers and evaluators to the Google GenAI plugin. The changes are well-structured, including new modules for the features, comprehensive unit tests, and a new sample application to demonstrate usage. I especially appreciate the addition of reusable gcloud helper functions in _common.sh, which greatly improves the developer experience for all samples. The code quality is high, and my feedback consists of a few minor suggestions for simplification and documentation consistency.
py/plugins/google-genai/src/genkit/plugins/google_genai/google.py
Outdated
Show resolved
Hide resolved
py/plugins/google-genai/src/genkit/plugins/google_genai/rerankers/reranker.py
Outdated
Show resolved
Hide resolved
- Remove redundant location fallback in google.py (self._location is set in __init__) - Fix docstring to show correct DEFAULT_LOCATION (global, not us-central1) - Simplify _extract_score/_extract_reasoning by removing unnecessary None checks
Summary
Adds Vertex AI rerankers and evaluators to the Google GenAI plugin, enabling RAG quality improvements and automated model output evaluation. Also includes infrastructure improvements for interactive GCP API management.
Vertex AI Rerankers
New module:
plugins/google_genai/rerankers/Rerankers improve RAG quality by re-scoring documents based on semantic relevance to a query (two-stage retrieval pattern):
Supported Models:
semantic-ranker-default@latestsemantic-ranker-default-004semantic-ranker-fast-004semantic-ranker-default-003semantic-ranker-default-002Usage:
Vertex AI Evaluators
New module:
plugins/google_genai/evaluators/Evaluators are automatically registered when using the VertexAI plugin and accessed via
ai.evaluate().Supported Metrics:
BLEUROUGEFLUENCYSAFETYGROUNDEDNESSSUMMARIZATION_QUALITYSUMMARIZATION_HELPFULNESSSUMMARIZATION_VERBOSITYUsage:
HTTP Client Caching (Fixes #4420)
Introduces
genkit.core.http_clientmodule for per-event-loop client caching, solving "bound to different event loop" errors with httpx.AsyncClient.Interactive GCP API Management
Adds reusable gcloud helper functions to
_common.shfor all samples:check_gcloud_installedcheck_gcloud_authis_api_enabledenable_required_apisrun_gcp_setupSample
New sample:
py/samples/vertexai-rerank-eval/demonstrates both features with automated gcloud setup.Review Feedback Addressed
google.py(self._location is set in init)global, notus-central1)_extract_score/_extract_reasoningby removing unnecessary None checksai.evaluate()usageFiles Changed
packages/genkit/src/genkit/core/http_client.pypackages/genkit/tests/genkit/core/http_client_test.pyplugins/google-genai/evaluators/*plugins/google-genai/rerankers/*plugins/google-genai/tests/*plugins/google-genai/README.mdsamples/_common.shsamples/vertexai-rerank-eval/*samples/firestore-retreiver/run.shsamples/google-genai-vertexai-hello/run.shsamples/google-genai-vertexai-image/run.shsamples/README.mdTest Plan
Related Issues