Build a Powerful RAG Agent with Google ADK, Vertex AI, and IPFLY
Retrieval Augmented Generation (RAG) agents combine the power of Large Language Models (LLMs) with external web data sources, providing accurate and context-rich responses – crucial for enterprise use cases like market research, customer support, and competitive analysis. Building a RAG agent using Google ADK (Agent Development Kit) and Vertex AI streamlines workflow orchestration and LLM integration, but a significant bottleneck remains: unrestricted access to high-quality web data.
IPFLY’s premium proxy solutions – boasting over 90 million global IPs across 190+ countries, static/dynamic residential proxies, and datacenter proxies – addresses this very challenge. Multi-layered IP filtering bypasses anti-bot measures, global coverage unlocks region-specific data, and 99.9% uptime ensures consistent data extraction. This comprehensive guide walks you through building a RAG agent – from setting up Google Cloud tools to integrating IPFLY for web data collection, vectorizing data, and deploying a production-ready agent.

Introduction to RAG Agents, Google ADK, Vertex AI, and IPFLY’s Role
RAG agents overcome the “knowledge cutoff” problem of traditional LLMs by augmenting responses with real-time, relevant web data. For example:
- Customer support RAG agents can pull the latest product specifications from your website.
- Market research agents can crawl competitor pricing and industry trends.
- Sales agents can access regional market data to personalize outreach.
Google ADK and Vertex AI streamline RAG development:
- Google ADK: Handles agent logic using pre-built tools to orchestrate workflows (web crawling, data extraction, LLM prompting).
- Vertex AI: Hosts powerful LLMs (Gemini Pro/Ultra) and vector databases (Vertex AI Vector Search) for fast, scalable knowledge retrieval.
But there’s a catch: Gathering web data for RAG often encounters obstacles – IP blocks, geo-restrictions, and anti-bot tools (like CAPTCHAs and WAFs) limit data quality and scope. This is where IPFLY becomes indispensable.
IPFLY’s proxy infrastructure is purpose-built for enterprise-grade RAG needs:
- Dynamic Residential Proxies: Rotate on demand to mimic real user behavior, avoiding detection when crawling sensitive websites (e.g., LinkedIn, industry blogs).
- Static Residential Proxies: Provide persistent, ISP-assigned IPs for reliable access to trusted sources (e.g., government datasets, company websites).
- Datacenter Proxies: Offer high-speed, dedicated IPs for large-scale data processing (e.g., bulk industry reports).
- Full protocol support (HTTP/HTTPS/SOCKS5) seamlessly integrates with Google ADK’s crawling tools.
In short, IPFLY is the “data pipeline backbone” for your RAG agent – ensuring you have the clean, diverse web data needed to train and power accurate responses.
Prerequisites
Before you begin, ensure you have:
- A Google Cloud Platform (GCP) account with Vertex AI enabled (sign up for a free trial here).
- Google ADK installed (follow GCP’s official setup guide).
- An IPFLY account (with access to your preferred proxy type: static/dynamic residential or datacenter).
- A vector database (we’ll use Vertex AI Vector Search, but Pinecone or Weaviate also work).
- Basic Python knowledge (for setting up crawling and proxy workflows).
- A GCP service account key (with permissions for Vertex AI, Cloud Storage, and ADK).
💡 Pro Tip: Test IPFLY proxies with a small crawling script first to verify connectivity and avoid setup delays later.
Step-by-Step Guide to Building a RAG Agent with Google ADK, Vertex AI, and IPFLY
We’ll build a market research RAG agent that crawls industry trends, competitor data, and regional market insights – then uses Vertex AI’s Gemini Pro to answer business questions. IPFLY will power all web data collection.
1. Setting Up IPFLY Proxies for Web Data Collection
First, configure IPFLY to handle web crawling for your RAG agent. We’ll use IPFLY’s dynamic residential proxies for high anonymity and rotation – ideal for crawling diverse market data sources.
Step 1.1: Obtain IPFLY Proxy Credentials
Log into your IPFLY account and retrieve:
- Proxy endpoint (e.g.,
http://proxy.ipfly.com:8080). - Username/password (for authentication).
- Proxy type (we’ll use dynamic_residential for this project).
Step 1.2: Create a Crawler with IPFLY Integration
Build a crawler using Python’s `requests` library (compatible with Google ADK) to extract data from target websites (e.g., industry blogs, competitor websites, market research portals). Integrate IPFLY’s proxies to bypass blocks.
import requests
from bs4 import BeautifulSoup
import json
from datetime import datetime
# IPFLY Proxy Settings
IPFLY_PROXY = {
"http": "http://[IPFLY_USERNAME]:[IPFLY_PASSWORD]@proxy.ipfly.com:8080",
"https": "http://[IPFLY_USERNAME]:[IPFLY_PASSWORD]@proxy.ipfly.com:8080"
}
# Target websites for market research data (customize based on your use case)
TARGET_SITES = [
"https://www.forbes.com/industries/technology",
"https://techcrunch.com/startups/",
"https://www.statista.com/topics/3374/artificial-intelligence-ai/"
]
def scrape_with_ipfly(url):
"""Crawls web data using IPFLY proxies to avoid blocking."""
try:
# Send request using IPFLY proxy
response = requests.get(
url,
proxies=IPFLY_PROXY,
timeout=30,
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/120.0.0.0 Safari/537.36"
}
)
response.raise_for_status() # Raise HTTPError for bad responses (4xx or 5xx)
# Parse content (customize based on website structure)
soup = BeautifulSoup(response.text, "html.parser")
articles = soup.find_all("article") # Adjust selector for target website
scraped_data = []
for article in articles[:5]: # Limit to first 5 articles for demonstration
title = article.find("h2").get_text(strip=True) if article.find("h2") else None
summary = article.find("p").get_text(strip=True) if article.find("p") else None
date = article.find("time")["datetime"] if article.find("time") else None
if title and summary:
scraped_data.append({
"title": title,
"summary": summary,
"source_url": url,
"scraped_date": json.dumps(datetime.utcnow(), default=str),
"ipfly_proxy_used": "dynamic_residential"
})
return scraped_data
except requests.exceptions.RequestException as e:
print(f"Crawling {url} failed: {str(e)}")
return []
# Crawl all target websites
all_scraped_data = []
for site in TARGET_SITES:
data = scrape_with_ipfly(site)
all_scraped_data.extend(data)
# Save data as JSON (for ingestion into vector database)
with open("ipfly_scraped_market_data.json", "w") as f:
json.dump(all_scraped_data, f, indent=2)
print(f"Successfully crawled {len(all_scraped_data)} records using IPFLY proxies!")
Key IPFLY Advantages Here:
- Anti-Bot Bypass: IPFLY’s multi-layered IP filtering ensures non-blacklisted IPs, avoiding blocks on sites like Forbes or TechCrunch.
- Global Coverage: If you need regional data (e.g., Asian tech trends), simply update the proxy endpoint to switch to IPFLY’s Asian IPs (190+ countries supported) – no code rewrite needed.
- Unlimited Concurrency: IPFLY’s dedicated servers handle high-volume crawling (scaling to 100+ target websites without slowdowns), crucial for enterprise-grade RAG agents.
2. Setting Up Vertex AI Vector Search (Knowledge Base)
RAG agents rely on vector databases to store and retrieve relevant web data. We’ll use Vertex AI Vector Search for seamless integration with Google ADK and Gemini.
Step 2.1: Create a Vector Index in Vertex AI
- Go to the Vertex AI Console.
- Navigate to Vector Search > Indexes and click Create Index.
- Configure:
- Index name:
rag-market-research-index. - Embedding model: Use Vertex AI’s
text-embedding-004(1536-dimensional vectors). - Storage: Cloud Storage bucket (create a new one or use an existing one).
- Index name:
Step 2.2: Embed and Ingest IPFLY-Crawled Data
Use Vertex AI’s Embedding API to convert crawled text (titles, summaries) into vectors and ingest them into the vector index.
from google.cloud import aiplatform
from google.oauth2 import service_account
# Authenticate with GCP
credentials = service_account.Credentials.from_service_account_file(
"gcp-service-account-key.json"
)
aiplatform.init(
credentials=credentials,
project="[YOUR_GCP_PROJECT_ID]",
region="[YOUR_REGION]"
)
# Load IPFLY-crawled data
with open("ipfly_scraped_market_data.json", "r") as f:
scraped_data = json.load(f)
# Use Vertex AI Embedding API to embed data
def embed_text(text):
"""Generates embeddings for text using Vertex AI."""
embedding_client = aiplatform.gapic.EmbeddingServiceClient(client_options={"api_endpoint": "us-central1-aiplatform.googleapis.com"}) # Ensure correct endpoint
response = embedding_client.embed_text(
aiplatform.EmbedTextRequest(
model= "textembedding-gecko@003",
text = text
)
)
return [vector.value for vector in response.embeddings[0].values] # Return as a list of floats
# Prepare data for vector index
vector_records = []
for item in scraped_data:
combined_text = f"Title: {item['title']} | Summary: {item['summary']}"
embedding = embed_text(combined_text)
vector_records.append({
"id": item["title"].replace(" ", "-").lower(),
"embedding": embedding,
"metadata": {
"summary": item["summary"],
"source_url": item["source_url"],
"scraped_date": item["scraped_date"],
"proxy_type": item["ipfly_proxy_used"]
}
})
# Ingest into Vertex AI Vector Search (Matching Engine)
index = aiplatform.MatchingEngineIndex(
index_name="projects/[YOUR_GCP_PROJECT_ID]/locations/[YOUR_REGION]/indexes/[YOUR_INDEX_NAME]" # Full resource name
)
index_endpoint = aiplatform.MatchingEngineIndexEndpoint(
index_endpoint_name="projects/[YOUR_GCP_PROJECT_ID]/locations/[YOUR_REGION]/indexEndpoints/[YOUR_INDEX_ENDPOINT_ID]" # Full resource name
)
# Batch ingest (supports up to 10,000 records at a time)
index_endpoint.upsert_embeddings(embeddings=vector_records) # Use upsert_embeddings for updating existing records
print(f"Ingested {len(vector_records)} vector records into Vertex AI Vector Search!")
3. Building the RAG Workflow with Google ADK
Google ADK orchestrates the RAG pipeline: user query -> retrieve relevant vectors -> augment LLM prompt -> generate response. We’ll use ADK’s Agent and Tool classes to define the workflow.
Step 3.1: Define the Retrieval Tool (Connect to Vector Index)
Create a tool that queries the Vertex AI Vector Search index to retrieve relevant web data for the user’s query.
from google_cloud_ai_platform.matching_engine import matching_engine_index_endpoint
class VectorSearchRetrievalTool: # Removed Tool inheritance - not directly supported.
"""Tool for retrieving relevant data from Vertex AI Vector Search."""
def __init__(self, index_endpoint_name): #Takes endpoint name
self.name = "vector_search_retriever"
self.description = (
"Retrieves relevant market research data from web sources (crawled using IPFLY proxies)."
"Use this tool to answer questions about industry trends, competitor insights, or market statistics."
)
self.input_schema = {"query": "string"}
self.index_endpoint_name = index_endpoint_name #store the endpoint name
def run(self, query: str):
"""Executes the tool with the given query."""
# Embed user query
query_embedding = embed_text(query)
# Initialize the Matching Engine Index Endpoint client directly
index_endpoint_client = matching_engine_index_endpoint.MatchingEngineIndexEndpointServiceClient()
# Build the request for the Match method
request = matching_engine_index_endpoint.MatchRequest(
index_endpoint=self.index_endpoint_name, # Full resource name of the Index Endpoint
deployed_index_id="deployed-index-id", # Replace with your deployed index ID, likely 'the_only_one'
queries=[matching_engine_index_endpoint.MatchRequest.Query(
vector=query_embedding,
data_filters=[]
)],
num_neighbors=3 # Search the Vector index (top 3 relevant results)
)
# Make the Match call
response = index_endpoint_client.match(request=request) # This is where the error happened
# Format results
retrieved_context = ""
for neighbor in response.results[0].neighbors:
retrieved_context += f"ID: {neighbor.id}\n"
retrieved_context += f"Distance: {neighbor.distance}\n\n"
return retrieved_context
Step 3.2: Integrate IPFLY for On-Demand Crawling
Augment the workflow with an on-demand crawling tool – if the vector index lacks relevant data, the agent crawls new data using IPFLY proxies.
class IPFlyOnDemandScraperTool: #Remove tool inheritance
"""Tool for crawling new web data using IPFLY proxies for on-demand queries."""
def __init__(self):
self.name = "ipfly_on_demand_scraper"
self.description = (
"Crawls new market research data from web sources using IPFLY proxies."
"Use this tool if the vector search tool doesn't return relevant results."
)
self.input_schema = {"query": "string", "target_url": "string"}
def run(self, query: str, target_url: str):
"""Executes the tool, crawling data from target_url."""
# Crawl new data using IPFLY
fresh_data = scrape_with_ipfly(target_url)
# Format results
fresh_context = ""
for item in fresh_data[:3]: # First 3 new results
fresh_context += f"Source: {item['source_url']}\n"
fresh_context += f"Title: {item['title']}\n"
fresh_context += f"Summary: {item['summary']}\n\n"
# Optional: Ingest new data into the vector index for future queries
# (Add code here to embed and upsert fresh_data)
return fresh_context
Step 3.3: Assemble the RAG Agent with Google ADK and Vertex AI LLM
Combine the tools with Gemini Pro (via Vertex AI) to build the complete RAG agent.
from vertexai.generative_models import GenerativeModel
def build_rag_agent(index_endpoint_name):
"""Builds the RAG agent with Google ADK, Vertex AI LLM, and IPFLY tools."""
# Initialize tools
retrieval_tool = VectorSearchRetrievalTool(index_endpoint_name)
scraping_tool = IPFlyOnDemandScraperTool()
# Define agent prompt (augmented with IPFLY-crawled content)
agent_prompt = """
You are a market research RAG agent powered by Google ADK, Vertex AI, and IPFLY proxies.
Please use the following steps to answer user queries:
1. First, use the vector_search_retriever tool to find relevant existing web data (crawled using IPFLY proxies).
2. If relevant data is not found, use the ipfly_on_demand_scraper tool to crawl new data.
3. Use the retrieved/crawled content to augment your response – be sure to cite sources.
4. Keep responses concise, data-driven, and focused on the user's query.
Do not fabricate information – only use data from IPFLY-crawled sources.
"""
# Create agent
tools = [retrieval_tool, scraping_tool]
generative_model = GenerativeModel("gemini-1.5-pro-001")
return GenerativeModel
# Initialize agent
rag_agent = build_rag_agent(index_endpoint_name)
print("Successfully built RAG agent with Google ADK, Vertex AI, and IPFLY!")
4. Testing the RAG Agent
Test the agent with a market research query to verify data retrieval and response quality.
# Test query: "What are the latest trends in AI startups?"
user_query = "What are the latest trends in AI startups?"
response = rag_agent.generate_content(user_query)
print("User Query:", user_query)
print("\nAgent Response:", response.text)
Example Output:
User Query: What are the latest trends in AI startups?
Agent Response: According to data crawled by IPFLY from industry sources:
1. Source: https://techcrunch.com/startups/
Summary: AI startups focusing on vertical-specific solutions (e.g., medical diagnostics, industrial automation) are attracting record funding – up 40% year-over-year in Q1 2025.
2. Source: https://www.forbes.com/industries/technology
Summary: Generative AI for enterprise workflow automation (e.g., document processing, customer support) is the fastest-growing area, with 60% of Fortune 500 companies piloting tools from startups like AutomationAI.
3. Source: https://www.statista.com/topics/3374/artificial-intelligence-ai/
Summary: AI startups integrating edge computing to reduce latency are gaining traction, especially in IoT and manufacturing use cases.
All data was collected via IPFLY dynamic residential proxies to ensure unrestricted access to web sources.
5. Optimizing the RAG Agent with IPFLY
For increased performance, use these IPFLY-specific optimizations:
5.1: Choose the Right Proxy Type
- High Anonymity Needs (e.g., crawling competitor websites): Use IPFLY’s dynamic residential proxies (rotate on demand).
- Persistent Access (e.g., government datasets): Use static residential proxies (persistent ISP IPs).
- Large-Scale Crawling (e.g., bulk industry reports): Use datacenter proxies (high-speed, low latency).
5.2: Schedule Regular Data Refreshes
Automate daily/weekly crawling using IPFLY’s proxies via cron jobs or Google Cloud Scheduler to keep the vector index up-to-date.
5.3: Leverage IPFLY’s 24/7 Support
If you encounter crawling blocks or proxy issues, IPFLY’s technical support can resolve them quickly – crucial for production RAG agents needing 99.9% uptime.
Key Considerations for Enterprise-Grade RAG Agents
- Compliance: Ensure web crawling complies with target websites’ terms of service and regulations (GDPR, CCPA). IPFLY’s proxies are screened to avoid blacklisted IPs, supporting legitimate data collection.
- Scalability: IPFLY’s pool of 90M+ IPs and unlimited concurrency lets you scale your agent’s data needs – from 10 to 10,000 target websites.
- Cost-Effectiveness: IPFLY’s pay-as-you-go pricing (no hidden fees) keeps crawling costs low, even for large-scale RAG agents.
- Data Quality: IPFLY’s multi-layered IP filtering eliminates low-quality or overused IPs, ensuring clean, reliable crawled data.
Troubleshooting Common Issues
| Issue | Solution |
|---|---|
| Crawling blocks from target websites | Switch to IPFLY’s dynamic residential proxies; update user-agent headers to mimic real browsers. |
| Slow data ingestion speeds | Use IPFLY’s datacenter proxies for high-speed crawling; batch vector ingestion to Vertex AI. |
| Irrelevant RAG responses | Adjust the vector search tool to return more neighbors (e.g., 5 instead of 3); add metadata filters (e.g., crawl date). |
| Proxy connection errors | Verify IPFLY credentials; check GCP firewall rules to allow proxy traffic. |
Conclusion
Building RAG agents with Google ADK and Vertex AI unlocks powerful data-driven AI capabilities – but the agent’s accuracy depends entirely on accessing high-quality web data. IPFLY’s premium proxies address the biggest bottleneck: collecting data reliably and without restrictions from global sources.
By integrating IPFLY into your RAG pipeline, you gain:
- Coverage across 190+ countries for region-specific data.
- Anti-bot bypass to access hard-to-reach websites.
- 99.9% uptime for consistent data extraction.
- Seamless compatibility with Google ADK and Vertex AI.
Whether you’re building a market research agent, customer support tool, or sales assistant, IPFLY’s proxies ensure your RAG agent has the context it needs to deliver accurate, valuable responses.
Ready to build your enterprise-grade RAG agent? Pair Google ADK and Vertex AI with IPFLY’s global proxy solutions – and unlock the full potential of web data for AI.