AI / Google Antigravity Gemini Fundamentals Interview Questions
What is the Gemini API's grounded generation with Google Search and how does attribution work?
When Search Grounding is enabled, Gemini not only uses real-time web data to improve its response but also returns grounding metadata - source attributions showing which web pages contributed to the answer. This enables you to display proper citations in your application.
from google import genai from google.genai import types client = genai.Client() response = client.models.generate_content( model="gemini-3.5-flash", contents="What are the most recent Gemini API updates?", config=types.GenerateContentConfig( tools=[types.Tool(google_search=types.GoogleSearch())], ) ) print(response.text) # Access grounding metadata: candidate = response.candidates[0] if candidate.grounding_metadata: gm = candidate.grounding_metadata # Sources used: print("\nSources:") for chunk in gm.grounding_chunks: if chunk.web: print(f" - {chunk.web.title}: {chunk.web.uri}") # Which parts of the response are grounded: for support in gm.grounding_supports: text_segment = support.segment.text sources = [gm.grounding_chunks[i].web.uri for i in support.grounding_chunk_indices] print(f"\nClaim: {text_segment[:80]}...") print(f"Supported by: {sources}") # Search entry point (rendered search suggestion UI element): if gm.search_entry_point: print(f"\nSearch UI: {gm.search_entry_point.rendered_content[:100]}")
The grounding_supports array maps specific text segments in the response to the sources that support them - enabling you to render inline citations (like footnotes) in your UI. The search_entry_point contains a rendered HTML element that displays a Google Search suggestion, which some applications are required to show.
More Related questions...