Grounding with Google Search is a tool in the Gemini API. The model runs Google searches before it answers and bases its response on the web content it finds. The response includes source references that an application can display.
How does grounding work?
According to the Gemini API documentation, the process has five steps. The application sends a prompt with the Google Search tool enabled. The model analyzes whether a search would improve the answer, generates search queries and runs them. The results are processed, and the API returns a grounded response with metadata. Google announced the feature for the Gemini API and AI Studio on October 31, 2024.
In the Firebase and generateContent interface, the metadata has four parts:
webSearchQuerieslists the searches that were run.groundingChunkslists web sources with URI and title.groundingSupportslinks text segments of the answer to the sources.searchEntryPointprovides HTML and CSS for the Google Search suggestions.
Applications that show the answer must display the search suggestions and the sources. Other interfaces name the fields differently, for example url_citation annotations.
What does it mean for SEO and GEO?
The queries come from Google Search. Content that is found well there may therefore have better chances of appearing as a source (assumption). The queries in webSearchQueries also show how a model breaks a prompt into search terms, similar to query fan-out.
Example
Example using the generateContent interface (Python SDK). The Gemini API docs now show the newer Interactions API, which uses different field names.
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="<gemini-model>",
contents="What is a canonical tag?",
config=types.GenerateContentConfig(
tools=[types.Tool(google_search=types.GoogleSearch())]
),
)
print(response.candidates[0].grounding_metadata.web_search_queries)
Sources
- Grounding with Google Search – Gemini API (Google AI for Developers)ai.google.dev
- Grounding with Google Search – Firebase AI Logicfirebase.google.com
- Grounding with Google Search in the Gemini API – Google Developers Blog (Oct 31, 2024)developers.googleblog.com
Last updated: