
Grounding: Anchoring AI in the Real World
Learn how to stop AI from making things up. We explore 'Grounding' in Vertex AI, using Google Search or your own data to verify facts and provide citations.
The Trust Problem
In a business context, an AI that "sounds confident" but is wrong is dangerous. It can damage your brand, annoy customers, or cause legal liability.
In the previous lesson, we looked at RAG (Retrieval Augmented Generation) as a way to feed private data to the model. Grounding is a closely related concept, often provided as a turnkey feature in Vertex AI, that specifically focuses on verification and citations.
For the Google Cloud Generative AI Leader exam, you need to understand the difference between grounding with Google Search and providing your own Enterprise Data.
1. What is Grounding?
Grounding is the process of linking the model's generated response to a verifiable source of information.
- Un-Grounded: "The capital of Australia is Sydney." (Incorrect, but the model says it confidently because it appears often in text training).
- Grounded: "The capital of Australia is Canberra [Source: australia.gov.au]." (Correct, verified against a reliable source).
Vertex AI Grounding services
Google Cloud offers a simpler way to implement this than building a full custom RAG pipeline from scratch. You can simply "toggle on" grounding in Vertex AI Studio.
2. Grounding Options in Vertex AI
There are two primary flavors:
A. Grounding with Google Search
This connects Gemini to the live internet using the power of Google Search.
- How it works: When you ask a question, the AI first Googles it, finds the top results, reads them, and synthesizes an answer.
- Benefits:
- Freshness: It knows about events that happened 5 minutes ago (stock prices, sports scores, news).
- Trust: It provides clickable numbered citations [1][2] so the user can verify the claim.
- Use Case: A "Market Research Assistant" that summarizes competitor news.
B. Grounding with Enterprise Data (Vertex AI Search)
This connects Gemini to your internal data (the RAG pattern we discussed in Lesson 3.2), but managed by Google.
- How it works: It connects to your Vertex AI Search data store (indexed PDFs, Intranet).
- Benefits: The answers are "grounded" in your company policy, not the public internet.
- Use Case: An "Employee HR Bot" that answers questions about dental benefits.
3. The "Grounding Check" Workflow
When you enable grounding, the system essentially performs a two-step validation:
graph TD
User[User Prompt] --> Model[Gemini]
Model -->|Draft Response| Checker{Grounding Check}
Checker -->|Search Source| Source[Google Search / Intranet]
Source -->|Verify Claims| Checker
Checker -->|Supported?| Yes[Output with Citations]
Checker -->|Contradicted?| No[Rewrite or Warning]
style Checker fill:#34A853,stroke:#fff,stroke-width:2px,color:#fff
If the facts in the model's "Draft Response" do not match the facts found in the "Source," the system will correct the response or flag it as low confidence. This acts as a safety net against hallucinations.
4. Code Example: Enabling Grounding
In the Vertex AI SDK, enabling grounding is as simple as adding a tool configuration. You don't need to build the search scraper yourself.
import vertexai
from vertexai.preview.generative_models import GenerativeModel, Tool, grounding
# Initialize
vertexai.init(project="my-project")
# Define the Tool: Use Google Search as the source of truth
tools = [
Tool.from_google_search_retrieval(
grounding.GoogleSearchRetrieval()
)
]
model = GenerativeModel("gemini-1.5-pro")
# Generate content with the tool attached
response = model.generate_content(
"What is the stock price of Alphabet right now?",
tools=tools
)
# The response object contains the text AND the grounding metadata (citations)
print(response.text)
# Output: "As of 10:30 AM EST, Alphabet (GOOGL) is trading at $175.50..."
# Accessing citations
# print(response.candidates[0].grounding_metadata.search_entry_point)
Leadership Takeaway: This code snippet shows that "connecting AI to the internet" isn't a 6-month engineering project. It is a configuration setting in Vertex AI.
5. Summary
- Grounding prevents hallucinations by anchoring answers in reality.
- Grounding with Google Search gives you the "World's Knowledge" (fresh, public facts).
- Grounding with Enterprise Data gives you "Company Knowledge" (private, policy facts).
- Citations are the key UI feature—they allow human users to trust and verify the AI's work.
In the final lesson of Module 3, we will answer the expensive question: "Should we fine-tune the model?" We will compare Prompt Engineering vs. Fine-Tuning.
Knowledge Check
?Knowledge Check
You are building a 'Competitor Analysis Bot' for your Strategy team. They need to know the latest pricing and product launches from your competitors as they happen this week. Which grounding strategy is appropriate?