Static RAG can’t answer “what happened this week.” Adding a live web-search step with a Google Search API grounds your LLM in current, citable sources. Here’s the pattern, using serp.cheap.
The architecture
user query
→ SERP API search (top N results) ← live, fresh
→ fetch the result pages
→ chunk + embed on the fly
→ retrieve most relevant chunks
→ LLM answers, citing the source URLs
Step 1 — retrieve fresh sources
import requests
def web_sources(query, n=5, gl="us"):
data = requests.post(
"https://api.serp.cheap/v1/search",
headers={"X-API-Key": "YOUR_KEY"},
json={"q": query, "gl": gl},
timeout=30,
).json()
return [
{"title": r["title"], "url": r["link"], "snippet": r.get("snippet", "")}
for r in data["organic"][:n]
]
Step 2 — fetch and chunk
Fetch each url, extract main text, split into ~500-token chunks. (Use your existing loader/splitter — e.g. trafilatura + a text splitter.)
Step 3 — embed, retrieve, generate
Embed the chunks, retrieve the top-k for the query, and pass them to the model with an instruction to cite the source URLs. Because the sources came from the live SERP, the answer reflects what authoritative pages currently say.
Why a cheap SERP API matters here
RAG fans out a search on every query. At $0.0006 per fresh search (half cached), serp.cheap keeps per-answer retrieval cost negligible — and recurring identical queries hit the cache automatically.
Snippet-only fast path
For lightweight grounding you can skip fetching pages and feed the model the SERP titles + snippets directly — one API call, no crawling. It’s cheaper and often enough for quick factual answers.
Next
Try serp.cheap
Ground your RAG pipeline in the live SERP. 100 free searches on signup — no card required; pay-as-you-go from $0.75/1k after that, and credits stay valid for 12 months.
- Get your free API key →
- Prefer paying by card? serp.cheap is also on RapidAPI (
$0.90/1k) and Apify ($1.50/1k).