Skip to content

[FirebaseAI] Add support for Grounding with Google Search #1285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025

Conversation

dlarocque
Copy link
Contributor

Description

Adds support for Grounding with Google Search. This includes adding a new GoogleSearch tool to include in the generation config, and the GroundingMetadata which is populated for grounded results.

Stray changes:

  • updated the commit we pull the mock responses from to get the latest grounding mock responses. I had to make a stray change to a citations test to fix a failure caused by a change in a mock response
  • Renamed Functions in Tool to FunctionsDeclarations- I think it's more clear.

API proposal: go/fal-grounding-api (internal)

Testing

Added new tests in the sample app, including an integration test and unit tests against the mock responses.

Type of Change

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

@dlarocque dlarocque requested a review from a-maurice July 8, 2025 20:51
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @dlarocque, 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 introduces a significant new capability to the Firebase AI SDK: support for grounding AI model responses with Google Search. This allows the model to leverage up-to-date information from the web to enhance its generations. The changes involve both configuring the model to use Google Search as a tool and providing rich, structured grounding metadata within the model's responses. Comprehensive tests have been added to validate this new functionality and the parsing of its associated data structures.

Highlights

  • New Feature: Google Search Grounding: I've added support for grounding AI model responses with Google Search. This includes a new GoogleSearch tool that can be included in the generation configuration to enable this functionality.
  • Grounding Metadata in Responses: The Candidate response object now includes GroundingMetadata. This new structure provides detailed information about how the model's response is grounded, including WebSearchQueries, GroundingChunks (retrieved content), GroundingSupports (links between response segments and chunks), and SearchEntryPoint (an HTML/CSS snippet for a Google Search entry point).
  • Enhanced Tool Configuration: The Tool class has been updated to flexibly support both traditional function declarations and the new GoogleSearch grounding tool, allowing for diverse model configurations.
  • Comprehensive Testing: I've added extensive tests for the new grounding feature. This includes an integration test (TestSearchGrounding) and several unit tests (InternalTestVertexAIGrounding, InternalTestGoogleAIGrounding, etc.) to validate the parsing and behavior of grounding metadata from various mock responses.
  • Code Clarity Improvement & Mock Data Update: For improved clarity, I've renamed the Functions property to FunctionDeclarations within the Tool struct. Additionally, the commit hash for the external mock response data repository has been updated to ensure the latest grounding mock responses are used for testing, and a minor fix was applied to a citations test due to a mock response change.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Grounding with Google Search. I've suggested using JsonParseOptions.ThrowEverything for stricter JSON parsing and using Any() to improve the correctness of assertions in a new test case.

@dlarocque dlarocque requested a review from a-maurice July 9, 2025 14:21
@a-maurice a-maurice merged commit d76e5fa into main Jul 9, 2025
5 checks passed
@a-maurice a-maurice deleted the dl/grounding branch July 9, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants