Deutsch
Retrieval & grounding

Grounding with Google Search

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:

  • webSearchQueries lists the searches that were run.
  • groundingChunks lists web sources with URI and title.
  • groundingSupports links text segments of the answer to the sources.
  • searchEntryPoint provides 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.

Retrieval-augmented generation: retrieve first, then answerA question triggers a search in a search index or vector database. The best passages are added to the prompt together with the question. The language model writes the answer from them and points to the sources of the passages. The answer can only cite what was retrieved first.1 QUESTION2 RETRIEVAL3 CONTEXT4 ANSWERQuestionfrom a useror an appRetrievalsearch orvector search findsmatching passagesKnowledge sourcesearch index, web,vector databasePrompt with contextquestion + passages[1] passage · URL A[2] passage · URL B[3] passage · URL CLLMAnswertext withsource links[1][3]Citations point to retrieved passagesSchematic, based on Lewis et al. (2020) and Google’s grounding docs.
In retrieval-augmented generation, the system first retrieves matching passages and passes them to the language model as context. Google calls the link between model output and verifiable sources grounding. The answer can only cite what was retrieved first (an inference from the method, not a Google statement). Sources: Lewis et al. (2020): Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (arXiv 2005.11401); Google Cloud: Grounding overview (Vertex AI); Google Cloud: Grounding with Google Search (Vertex AI).

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.

Python
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

  1. Grounding with Google Search – Gemini API (Google AI for Developers)ai.google.dev
  2. Grounding with Google Search – Firebase AI Logicfirebase.google.com
  3. Grounding with Google Search in the Gemini API – Google Developers Blog (Oct 31, 2024)developers.googleblog.com

Last updated: