Tutorial
parallel-cookbookpython-recipesvertex_ai_demo
Export
Vertex AI + Parallel Web Search Grounding Tutorial
This notebook teaches you how to ground Gemini responses with real-time web data using Parallel's web search API.
What you'll learn:
- How the Parallel grounding integration works
- How to make grounded API calls to Vertex AI
- How to parse sources and citations from responses
- How to compare grounded vs. ungrounded responses
Prerequisites
- A Google Cloud project with Vertex AI API enabled
- A Parallel API key from https://parallel.ai/products/search
- Google Cloud authentication configured (
gcloud auth application-default login)
Step 1: Setup
First, let's configure our credentials and imports.
[ ]
Step 2: Understanding the Grounding Config
To enable Parallel web search grounding, we add a tools parameter to our API request. Here's the structure:
[ ]
Step 3: Making a Grounded API Call
Now let's build a function to call the Vertex AI API with grounding enabled.
[ ]
Step 4: Make Your First Grounded Request
Let's ask a question that requires recent information.
[ ]
Step 5: Parsing the Response
The API response has a specific structure. Let's write a function to extract the useful parts.
[ ]
Step 6: Compare Grounded vs. Ungrounded
Let's see the difference grounding makes for time-sensitive questions.
[ ]
Summary
You've learned:
- Grounding config - Add
tools: [{"parallelAiSearch": {"api_key": "..."}}]to your request - Making calls - Use the standard Vertex AI REST API with the grounding tool
- Parsing responses - Extract text from
candidates[0].content.parts[0].textand sources fromgroundingMetadata.groundingChunks - Customization - Use
customConfigsto filter domains and limit results
Next Steps
- Check out
quickstart.pyfor a minimal example using the helper library - See
demo.pyfor a command-line demo - Read the Vertex AI documentation for more options