Deep Research in Gemini is really an amazing feature, it can help you gather a lot of information on a topic and get an insightful and detailed report.
But what do you do when you need to explore multiple topics? Based on this need, I worked on a lightweight Deep Research solution using Gemini 2.5 Flash and Pro with the Google Search tool to perform multiple analyses.
Technical details
Models used
To get a well-structured and detailed response while keeping the cost of the Deep Research controlled, the code uses Gemini 2.5 Flash and Gemini 2.5 Pro.
- Gemini 2.5 Pro is used to break down the search query into sub-search queries and build the report.
- Gemini 2.5 Flash is used for the Google Search.
Tools used
To break down the search, a function is called in the first request to the LLM to ask Gemini to define the research steps to perform.
const tools = [{
functionDeclarations: [{
name: "draftQuestions",
description: "Draft all the questions that need to be answered to fulfill the user's request.",
parameters: {
type: "OBJECT",
properties: {
questions: {
type: "ARRAY",
description: "An array of strings, where each string is a question to be investigated.",
items: { type: "STRING" }
}
},
required: ["questions"]
}
}]
}];
To perform the Google search for each sub-question, the code uses Grounding with Google Search, which is available in the Gemini API (ref).
const groundingTool = {
googleSearch: {},
};
Parameters
We added some parameters to get a more personalized experience in the search and be more accurate.
Search Queries: This parameter is used to define the number of search queries we need Gemini 2.5 Pro to break down from the main search. This is useful to minimize the cost of the deep research and speed up the process. The more sub-queries are treated, the longer the search runs.
Language: We set the output language. Even if the prompt is in English, this parameter allows you to get the output in the desired language.
Current Date/Time: The model doesn’t know the current date, so it is important to give the model this information if your search concerns recent events. It can help prevent getting outdated information in the final output.
Main function structure
The Deep Search can be split into three different steps :
- Generate sub-search queries
- Perform sub-query searches
- Create the final report
See it in action
The video is a bit long, but there are nice log messages to follow the process 🙂
Bulk Deep Research code
Full code is available on GitHub. Follow the Get Started section to setup the script.
Source Credit: https://medium.com/google-cloud/bulk-deep-research-with-gemini-and-google-apps-script-0ff01f5462d0?source=rss—-e52cf94d98af—4
