Skip to main content
Reggie Pangilinan
HomeBlogAbout
GitHubLinkedIn

© 2026 reggiepangilinan.com All rights reserved.

GitHubLinkedIn
Evolving Blog Search into a Site-Wide AI Assistant with…
←Back to Blog

Evolving Blog Search into a Site-Wide AI Assistant with Next.js & Google Gemini

How I turned a blog-only search bar into a site-wide ⌘K assistant—covering plain-English architecture, UX restraint, privacy-by-allowlist, free-tier runway math, and 5 real-world use cases beyond personal blogs.

December 3, 2026·Reggie Pangilinan·11 min read
Evolving Blog Search into a Site-Wide AI Assistant with Next.js & Google Gemini

In my previous post, I built a hybrid search bar for /blog that combined 0 ms instant client-side filtering with Google Gemini AI answers. It worked great—if you were already on the blog page.

Then I thought about how real visitors actually navigate a personal engineering site. A recruiter lands on / and wants to know if I have led cloud-native platforms in Sydney. A founder lands on /about and wonders what my core tech stack looks like. A reader clicks to /blog/page/2 and expects search to still be there. Asking all of them to click over to /blog first just to ask a question adds unnecessary friction.

So I evolved that blog search into a site-wide ⌘K AI assistant accessible from every page on reggiepangilinan.com—without turning static pages into slow server-rendered routes, without adding a database, and without blowing past Google Gemini's $0 free tier.

Even better: the architecture behind it is not specific to personal portfolios. The exact same zero-database pattern works for SaaS documentation, agency portfolios, local businesses, internal team wikis, and e-commerce buying guides. I will start with the plain-English concepts and work my way into the engineering, UX, cost math, and broader use cases.

💡 The Big Ideas (In Plain English First)

Before diving into Next.js routes and CSS Flexbox quirks, four simple ideas explain the entire design:

  • 1. Lazy Loading (Don't Pack What You Might Not Open): Most visitors who open the home page never touch search. If I stuffed every blog post into the home page's HTML just in case someone searches, every visitor would pay a speed penalty. Instead, my home and about pages stay 100% static with 0 KB of search data. The search index is only fetched the _very first time_ someone clicks Ask AI or presses ⌘K.

  • 2. Two Binders on the AI's Desk (Dual-Grounding): Previously, I handed Gemini one binder: my published blog posts. Now I hand it —Binder A is the live Contentful blog catalog, and Binder B is a compact, hand-curated covering my 20 years of engineering experience across Makati, Singapore, and Sydney. Gemini reads both and answers strictly from what is inside them.

Keep Reading

Related Posts

December 3, 2026

Adding AI-Powered Blog Search with Google Gemini in Next.js

How we added an intelligent, Gemini-powered search bar to a Next.js + Contentful blog—covering AI basics for non-specialists, why hybrid search beat Google Search Grounding and Vertex AI Search, real-world free-tier traffic estimates, and built-in cost guardrails.

Next.jsTypeScript
December 2, 2026

Generative Engine Optimization (GEO) in Next.js 16: llms.txt, RSS, JSON-LD & Crawler Access

A plain-English primer on Generative Engine Optimization (GEO) plus six concrete Next.js 16 upgrades: dynamic /llms.txt, /rss.xml, Person & WebSite JSON-LD, explicit AI bot rules, and non-JS visibility.

Next.jsSEO
December 2, 2026

Four Silent Sitemap & SEO Bugs I Found Auditing My Next.js 16 Blog

What sitemaps, robots.txt, and canonical URLs actually do for search indexing—plus four silent SEO bugs I found and fixed auditing my Next.js 16 + Contentful blog.

Next.jsSEO
Topics
Next.jsTypeScriptContentfulNetlifyAIUXSEOSecurity

Share this article

Found this helpful? Copy the link or scan the QR code to share it.

←All blog posts
two small binders
~700-token profile brief
  • 3. Privacy by Allowlist (Not "Please Don't Tell"): You should never put private information into an AI prompt and then ask the AI politely not to repeat it—prompt injection can bypass polite instructions. Instead, I use an allowlist: only public career facts, published articles, and approved site links ever enter the prompt. Sensitive personal details (like date of birth, mobile phone numbers, or personal email addresses) simply do not exist in the knowledge base at all.

  • 4. UX Restraint (Less Chrome, Better Answers): AI interfaces easily become loud and cluttered—floating chat bubbles, glowing pills, walls of suggested prompts. I intentionally stripped away visual noise until the trigger felt like a natural part of the site's typography, capped starter prompts to 2, and kept idle quick links to 2.

  • The takeaway: Going from "blog search" to "site-wide AI assistant" did not require a chatbot framework, a vector database, or server-rendering the whole site. It only required lazy-loading the index, adding a ~700-token curated profile brief, and tightening the UI.

    🏗️ Under the Hood: Zero-Overhead Site-Wide Architecture

    Keeping the site fast meant protecting one core rule in my Next.js App Router setup: the Home (/) and About (/about) pages must remain statically generated (SSG) at build time.

    Architecture diagram of the site-wide AI search assistant: 0 KB initial load on static pages, lazy GET /api/search/index cached at the edge, POST /api/search combining Contentful blog digests with a ~700-token allowlisted profile knowledge base, and ~$0.0036 per search
    Architecture diagram of the site-wide AI search assistant: 0 KB initial load on static pages, lazy GET /api/search/index cached at the edge, POST /api/search combining Contentful blog digests with a ~700-token allowlisted profile knowledge base, and ~$0.0036 per search

    Here is how the pieces fit together in the codebase:

    • Global Modal Mounted Once: SiteSearchModal is mounted once in src/app/layout.tsx. It renders nothing (null) when closed, listens globally for ⌘K / Ctrl+K, and listens for a lightweight browser custom event (open-site-search).

    • Decoupled Header Trigger: src/components/Header/Header.tsx simply dispatches open-site-search when a visitor clicks Ask AI (desktop) or taps the sparkle icon (mobile). The Header does not need to know anything about Contentful, Gemini, or modal state.

    • Lazy Edge-Cached Index (GET /api/search/index): The first time the modal opens, it fetches /api/search/index, which returns lightweight serialized post summaries via my shared src/lib/blog-post-serializer.ts helper and caches the response for 5 minutes at the CDN edge (s-maxage=300, stale-while-revalidate=600). Once fetched, typing in the modal filters articles in 0 ms locally.

    • Dual-Grounded AI Route (POST /api/search): When the visitor presses Enter or clicks Ask AI, src/app/api/search/route.ts delegates to src/lib/site-search.ts. It combines the compact Contentful post digests with src/config/profile-knowledge.ts and calls Gemini with a strict JSON responseSchema.

    • Verified Links Only: Gemini can return both matching blog posts (results[] with a 1-sentence relevanceReason) and relevant site pages (relatedPages[] like /about, /blog, or the resume download). On the server, every single returned post slug is checked against Contentful and every site route is checked against an explicit route allowlist—so the model can never invent a broken 404 link or redirect someone to an external URL.

    • Paginated Blog Parity: I also wired the compact <BlogSearch> bar and RSS link into src/app/blog/page/[page]/page.tsx using the same serializer, keeping 1-hour ISR intact across paginated archives.

    🎨 UX Restraint: What I Removed, Refined, and Fixed

    Shipping the first working version of site-wide search was only half the job. Testing it on real desktop and mobile screens immediately surfaced details that separate a bolted-on AI widget from a cohesive product:

    • Removing the Redundant Inline Widget on /about: Early on, I tried placing an inline AI prompt box directly on /about. In practice, it made the page feel busy and competed with the narrative. Removing it and relying on the global header trigger kept /about calm and readable while keeping AI Q&A one click away from every page.

    • Dialing Back the Header Trigger: A bright yellow pill button in the navigation bar looked too loud next to minimal Swiss typography. I refined Header.module.css down to subtle rainbow-gradient Ask AI text on desktop (matching the weight and rhythm of About Me and Blog) and a clean, bare 20px Gemini sparkle icon on mobile—no heavy circle badge, no visual clutter.

    • Capping Choices to Reduce Decision Fatigue: I trimmed starter prompt chips to a maximum of 2 across both the site-wide modal and /blog search, and narrowed the modal's idle quick links to just 2 (About Me and Blog Posts). Two clear options invite a click; six options feel like homework.

    • Preserving Muscle Memory on the Home Page: Clicking About Me in the navigation while on / kept its original smooth-scroll behavior down to #what-i-do rather than forcing an unexpected route jump.

    • Three Subtle Mobile Bugs Caught on Real Devices:

    • The Flexbox Cropping Bug: On iOS Safari, long AI answers inside the scrollable .body flex column were getting vertically clipped. Why? Flex children default to flex-shrink: 1, so when the modal body overflowed, CSS squashed the .aiCard container (which had overflow: hidden) instead of scrolling it. Adding flex-shrink: 0 to .aiCard and .section in SiteSearchModal.module.css fixed it completely.

    • Full-Height Mobile Sheet (100dvh): Instead of a floating centered dialog that fights the on-screen keyboard, the modal switches on mobile viewports to a clean full-height 100dvh sheet with generous tap targets.

    • No Blue Emoji Arrows on iOS: The Unicode ↗ character renders as a chunky blue emoji button on iOS Safari. Swapping it for a crisp 14px inline SVG kept the Swiss monochrome aesthetic intact across every OS.

    🛡️ Privacy, Security & Guardrails by Design

    A site-wide AI assistant answers questions about a real person, which raises the stakes compared to blog-only search. Every guardrail in src/lib/site-search.ts and src/app/api/search/route.ts was built around defensive defaults:

    • Strict Data Allowlist: src/config/profile-knowledge.ts contains only public professional facts—career timeline, engineering leadership focus, public links, and skills. Private details are never added, and the system prompt instructs Gemini to politely decline personal or out-of-scope questions.

    • 200-Character Query Cap: Blocks prompt-stuffing payloads with HTTP 400 before they ever reach Gemini.

    • 10 Requests/Minute Per-IP Rate Limiter: Prevents bots from draining daily quotas. If an IP hits the limit, the endpoint gracefully degrades to local instant search rather than showing a broken error state.

    • Smart 10-Minute Cache (AI-Only): Normalized queries ("Sydney experience" and " sydney experience ") share a 10-minute server cache entry. Crucially, only successful mode === 'ai' responses are cached—if Gemini ever has a brief hiccup and falls back to local lexical search, that fallback never gets stuck in cache.

    • Zero-Secret Local & Preview Builds: If GEMINI_API_KEY is absent in local development or CI, the build still passes and the modal seamlessly serves instant local search and quick navigation.

    💰 Strategy, Cost & Free-Tier Runway Math

    A natural question when upgrading from blog search to a site-wide AI assistant is: does adding a profile knowledge base and putting Ask AI in the global header blow up my token budget?

    Here are the updated numbers building directly on the baseline from my first post:

    • Marginal Token Cost of the Profile Knowledge Base:

    • In my first post, 15 published blog posts took ~8,500 input tokens per AI query (~550 tokens/post).

    • Adding src/config/profile-knowledge.ts adds only ~700 input tokens—less than a 10% increase.

    • Total per site-wide AI search today: ~9,200 input tokens + ~350 output tokens ≈ ~9,550 total tokens.

    • Per-Search Dollar Cost (Flash-Lite / Paid Credits):

    • On gemini-3.5-flash-lite (roughly $0.25–$0.30 per 1M input tokens and $1.50–$2.50 per 1M output tokens), one site-wide AI search costs roughly $0.0036 (just over one-third of a penny).

    • On Google AI Pro's included $10/month API credits, that covers roughly ~2,750 site-wide AI searches/month today—with higher rate limits and zero free-tier data retention.

    • Google AI Studio Free Tier ($0/month, no credit card):

    • Even with higher visibility in the global header, remember two filters sit in front of Gemini: most visitors still read and leave without searching, and those who open ⌘K often click a 0 ms instant match or one of the 2 Quick Links without ever hitting the AI endpoint.

    • Assume 5% to 7% of monthly visitors trigger an AI query (higher than blog-only's 3%–5%) and 25% to 30% hit the 10-minute cache (starter prompts and common recruiter questions like _"What is Reggie's tech stack?"_ cache heavily).

    • A conservative 250 free AI requests/day (~7,500/month) still supports roughly 150,000+ monthly site visitors for $0/month.

    • Multi-Year Runway at 1 Post/Week:

    • Notice a subtle advantage: the profile knowledge base does not grow every week—it stays around ~700 tokens even as years pass. Only the blog catalog grows (~52 posts/year).

    • Year 1 (~67 posts): ~37,700 input tokens/search (3.8% of Gemini's 1M context window). Still $0/month on Free Tier for typical traffic (~$0.012/search on AI Pro credits).

    • Year 2 (~119 posts): ~66,200 input tokens/search (6.6% of context window). I can simply bump maxCatalogPosts in src/config/blog.ts around post #100.

    • Years 3.5 to 4 (~180–220 posts · Stage 2 Upgrade Point): Crosses ~100K–120K input tokens. Turning on lightweight embedding pre-filtering (pick top 15 candidate posts + always include the ~700-token profile KB) drops every query right back down to ~9,200 input tokens—extending the free/low-cost runway to 10+ years.

    Bottom line: Making AI search site-wide costs less than 10% extra tokens today, adds 0 KB to initial page loads, and keeps the exact same 3.5–4 year zero-database runway (and 10+ years with Stage 2 pre-filtering).

    🌍 5 Real-World Use Cases Beyond Personal Blogs

    Here is the most exciting part of this architecture: a personal website is just one skin on a universal pattern. Any site with 10 to 200 core pages and a short curated facts document can deploy this exact zero-database, hybrid ⌘K assistant in a weekend.

    Infographic showing 5 real-world use cases for the zero-database hybrid AI search pattern: SaaS Docs & Help Centers, Local & Service Businesses, Creative Agencies & Studios, Internal Team Wikis & ADRs, and E-Commerce Buying Guides & Store FAQs
    Infographic showing 5 real-world use cases for the zero-database hybrid AI search pattern: SaaS Docs & Help Centers, Local & Service Businesses, Creative Agencies & Studios, Internal Team Wikis & ADRs, and E-Commerce Buying Guides & Store FAQs

    Here are five high-leverage places where this pattern shines:

    • 1. SaaS Documentation & Help Centers

    • The two binders: Your Markdown docs / changelog digests + a ~1,000-token pricing, limits, and SLA summary.

    • Why it works: Users stop filing repetitive support tickets asking _"Does the Pro plan support SAML SSO on self-hosted runners?"_—they get a grounded 2-sentence answer with direct verified links to the exact setup doc, without paying $500+/month for an enterprise AI support widget.

    • 2. Local & Service Businesses (Clinics, Law Firms, Consultancies, Trades)

    • The two binders: Service pages and blog FAQs + a curated facts file covering hours, locations, insurance/billing policies, and booking steps.

    • Why it works: Visitors hate aggressive pop-up chat widgets that demand their email before answering a basic question. A quiet Ask AI trigger answers _"Do you offer Saturday appointments and accept Bupa?"_ instantly and links straight to the booking page.

    • 3. Creative Agencies & Product Studios

    • The two binders: Published case studies + a curated agency profile (industries, core tech stack, team locations, engagement models).

    • Why it works: Prospective clients can type _"Have you built HIPAA-compliant mobile apps or Next.js migrations?"_ and immediately see ranked case studies with a 1-sentence explanation of _why_ each project is relevant.

    • 4. Internal Team Wikis, Runbooks & ADRs (Behind SSO)

    • The two binders: Architecture Decision Records (ADRs) and runbooks + a team ownership directory (who owns which service, on-call escalation links).

    • Why it works: New engineers onboarding onto a codebase can press ⌘K and ask _"Why did we choose ISR instead of SSR for marketing pages?"_ and jump straight to the exact ADR without interrupting senior engineers in Slack.

    • 5. E-Commerce Buying Guides & Store FAQs

    • The two binders: Buying guides, care instructions, and curated catalog summaries + a shipping, warranty, and returns policy brief.

    • Why it works: Shoppers can ask natural questions like _"Which waterproof commuter backpack fits a 16-inch MacBook and ships to Melbourne?"_ and get grounded answers paired with verified product links—zero hallucinated SKUs, zero broken URLs.

    ✅ A Weekend Checklist to Build Your Own

    If you want to adapt this pattern for your own Next.js site or product, keep the checklist simple:

    • Keep static pages static: Mount the modal once in your root layout and lazy-fetch a CDN-cached search index only on first open.

    • Separate live content from curated facts: Pull articles, docs, or case studies from your CMS, and keep core business/profile facts in a version-controlled allowlisted TypeScript file.

    • Enforce strict JSON schemas + server-side link checks: Never trust raw model URLs—verify every slug and route on the server before returning JSON to the browser.

    • Put instant local search in front of AI: Let typing filter in 0 ms for free, and reserve LLM calls for intentional questions (Enter or Ask AI).

    • Ship guardrails on day one: 200-char cap, per-IP rate limiting, normalized query caching (AI-only), and graceful local fallback when keys or quotas are unavailable.

    Press ⌘K (or tap Ask AI in the header) anywhere on reggiepangilinan.com to try it out—ask about my engineering background, Next.js architecture trade-offs, or how I keep this site running at near-zero cost.