Search Grounding For Research Report
Copyright 2025 Google LLC.
Search tool with Gemini 2+
In this tutorial you are going to leverage the latest search tool of the Gemini model to write a company report. Note that the search tool is a paid ony feature and this tutorial does not work with a free tier API key.
You may be asking, why does one need to use the search tool for this purpose? Well, as you may be aware, today's business world evolves very fast and LLMs generally are not trained frequently enough to capture the latest updates. Luckily Google search comes to the rescue. Google search is built to provide accurate and nearly realtime information and can help us fulfill this task perfectly.
Note that while Gemini 1.5 models offered the search grounding feature which may also help you achieve similar results (see a previous notebook using search grounding), the new search tool in Gemini 2.0 and later models is much more powerful and easier to use, and should be prioritized over search grounding. It is also possible to use multiple tools together (for example, search tool and function calling).
Setup
Install SDK
The new Google Gen AI SDK provides programmatic access to the Gemini models using both the Google AI for Developers and Vertex AI APIs. With a few exceptions, code that runs on one platform will run on both. This means that you can prototype an application using the Developer API and then migrate the application to Vertex AI without rewriting your code.
More details about this new SDK on the documentation or in the Getting started notebook.
Setup your API key
To run the following cell, your API key must be stored it in a Colab Secret named GOOGLE_API_KEY. If you don't already have an API key, or you're not sure how to create a Colab Secret, see Authentication
for an example.
Import the libraries
Initialize SDK client
With the new SDK you now only need to initialize a client with you API key (or OAuth if using Vertex AI). The model is now set in each call.
Select a model
Search tool is a new feature in the Gemini models that automatically retrieves accurate and grounded artifacts from the web for developers to further process. Unlike the search grounding in the Gemini 1.5 models, you do not need to set the dynamic retrieval threshold.
For more information about all Gemini models, check the documentation for extended information on each of them.
Write the report with Gemini
Select a target company to research
Next you will use Alphabet as an example research target.
Have Gemini plan for the task and write the report
The newest Gemini models are a huge step up from previous models since they can reason, plan, search and write in one go. In this case, you will only give Gemini a prompt to do all of these and the model will finish your task seamlessly. You will also using output streaming, which streams the response as it is being generated, and the model will return chunks of the response as soon as they are generated. If you would like the SDK to return a response after the model completes the entire generation process, you can use the non-streaming approach as well.
Note that you must enable Google Search Suggestions, which help users find search results corresponding to a grounded response, and display the search queries that are included in the grounded response's metadata. You can find more details about this requirement.
Very impressive! Gemini starts by planning for the task, performing relevant searches and streams out a report for you.
Final output
Render the final output.
As you can see, the Gemini model is able to write a concise, accurate and well-structured research report for us. All the information in the report is factual and up-to-date.
Note that this tutorial is meant to showcase the capability of the new search tool and inspire interesting use cases, not to build a production research report generator. If you are looking to use a tool, please check out Google Deep Research in the Gemini app.
Next Steps
- To learn more about the search tool, check out the Search tool documentation.
- To get started with streaming, check out the Streaming Quickstart.
- To get started with the search tool, check out the Search tool quick start.
- To see how much easier and more powerful the search tool in Gemini 2.0 is than the previous search grounding feature, compare this tutorial with the previous example.
To learn more about all the Gemini features, check out the Gemini quickstart notebooks.