White Paper: A Personal Knowledge Base Build
Building kb.miin.ai
I built kb.miin.ai as a searchable, web-based knowledge base that turns a Google Workspace folder into a private retrieval system with semantic search, source references, OCR, spreadsheet parsing, and a clean public-facing interface. The project started as a local prototype, moved through a Vercel and Supabase production version, and now combines Firebase App Hosting, a Firestore source catalog, and Gemini API File Search. Google manages the search index, and Gemini 3.5 Flash-Lite generates answers with native citations mapped to APA references. The big lesson: modern AI infrastructure is accessible if you break the build into small, testable pieces, and when in doubt, ask your favorite coding agent!
Tech Stack
The current system combines a static personal website, a Firebase-backed knowledge-base app, automated Google Drive ingestion through Cloud Scheduler and Cloud Run, Gemini API File Search, and a Firestore citation catalog. Codex automated much of the implementation work: scaffolding the Next.js app, writing the Google Drive sync pipeline, switching from local Ollama to Gemini, migrating the data layer from Supabase to Firebase, updating the UI, pushing code to GitHub, and helping debug deployment and authentication issues along the way.
Application
Next.js App Router, TypeScript, custom CSS, GitHub, and Firebase Hosting or App Hosting.
Models
Gemini 3.5 Flash-Lite for answers and Gemini Embedding 2 within managed File Search.
Data Layer
Gemini File Search for retrieval; Firestore for sources, APA metadata, sync state, and usage limits.
Automation
Codex for code generation, refactors, Git operations, local testing, and deployment support.
What I Built
1. A Google-style search surface
The front end began as a minimal Google-like search page, then evolved into a branded containerized page that matches the visual language of miin.ai: dark mode, pill buttons, block-M logos, and a clean search field.
2. A retrieval-augmented answer flow
User questions go to Gemini 3.5 Flash-Lite with the managed File Search store. Native answer-support metadata maps the cited passages to APA references, without exposing private Drive links.
3. Automatic Google Drive sync
Cloud Scheduler triggers a Cloud Run job that checks the Google Drive Knowledge Base folder. The job exports changed files, skips unchanged documents, and resumes interrupted indexing. Spreadsheet text conversion and scanned-PDF OCR remain as compatibility adapters.
4. A production deployment
The personal profile remains on GitHub Pages, while the knowledge base runs as a dynamic Firebase-backed app at kb.miin.ai. Cloudflare DNS maps the subdomain to Firebase, and the runtime reads Firebase and Gemini configuration without exposing secrets in the repository.
November 2026: Managed RAG with Gemini File Search
I migrated retrieval from custom Firestore vectors to Gemini API File Search. Google Drive remains the source of truth, and Gemini 3.5 Flash-Lite remains the answer model. Google now manages document chunking, Embedding 2, indexing, and retrieval; Firebase App Hosting still serves the Next.js app.
Sources and synchronization
The Cloud Run job tracks stable Drive IDs and content versions. It checks that missing sources were trashed before removing them from the index. Sheets and Excel use a text adapter, and image-only PDFs use OCR when needed.
Native citations, APA references
Google's answer-support metadata links passages to source IDs. Firestore supplies the reviewed APA details, and inline reference links point to the cited bibliography entries. Author and date accuracy still require source review.
File Search costs
File Search storage and query embeddings are free. Google bills for indexing and model tokens.
What changed, and the tradeoff
This removes manual vector handling and improves source attribution, while keeping a few format adapters. It also adds dependence on Google's indexing behavior, file limits, and citation metadata. All 117 Drive files were indexed; a 20-question evaluation passed source-mapping, format-coverage, cross-document evidence, and abstention checks. Native citations still require factual review.
Occasional-use cost depends on retrieved context, answer length, and changed files. At the November 2026 paid rates, 100 searches with 5,000 input and 500 output tokens each model about $0.28 in Gemini charges, excluding hosting and indexing. The full-corpus 20-question evaluation used about $0.11 in estimated model tokens; actual usage depends on the retrieved context. Incremental sync avoids paying to reindex unchanged documents. See Google's current pricing.
Tradeoffs
The first design considered Ollama with a local Gemma model. That was attractive because it kept inference local and avoided hosted model costs, but it created production complexity: a public site would need a persistent machine capable of running the model. Moving to Gemini 2.5 Flash reduced hosting burden and made the system easier to operate.
Answer generation later moved from Gemini 2.5 Flash to Gemini 3.5 Flash-Lite for a fast, cost-conscious model. That initial model swap kept the old embedding index unchanged. The later File Search migration replaced retrieval separately, as described above.
The first hosted version used Vercel for the dynamic Next.js runtime and Supabase for Postgres plus pgvector. That was a strong developer stack, but it split the system across multiple vendors. The Firebase migration trades some SQL flexibility for simpler operations, closer alignment with Google Workspace and Gemini, and a clearer path to private access controls.
The Cloud Run job uses a dedicated service account with read-only access to the source folder. Cloud Scheduler uses a separate identity to invoke the job.
Earlier Move to Firebase
After the Vercel and Supabase version was working, the architecture moved into Firebase. This earlier stage put hosting, server code, document storage, and vector retrieval into the Google ecosystem. The subsequent File Search migration kept Firebase hosting and metadata while moving retrieval into Google's managed Gemini service. The Gemini API billing project can differ from the Firebase project.
What Vercel + Supabase did well
Vercel made the Next.js deployment path fast, and Supabase gave the app Postgres, pgvector, SQL inspection, and RPC search in a very direct package. That stack is flexible and familiar for relational data.
What pushed the move
The split stack required more vendor boundaries, environment variables, service-role handling, logs, dashboards, and deployment surfaces. Firebase reduces that operational spread for a small, personal knowledge product.
What Firebase improves
Firebase keeps the app close to Google auth patterns, Cloud Functions or App Hosting, Firestore document data, vector indexes, and the existing Gemini workflow. It also creates a cleaner path for future private access and user-aware permissions.
What Firebase costs
The migration trades away plain Postgres ergonomics and requires reshaping chunk metadata into Firestore documents, rebuilding vector indexes, and watching read and function costs. It also deepens commitment to the Google ecosystem.
Final call
Firebase won because this knowledge base values low-ops maintenance, Google-native integration, and a coherent deployment story more than the extra SQL flexibility Supabase provides. For this use case, simpler ownership beat a more modular architecture.
Implementation Notes
These are the key command groups and setup steps behind the project. The exact values for secrets stay in local or hosted environment variables, not in the repository.
cd "/path/to/your/knowledge-base-app"
npm install
cp .env.example .env.local
Cloud Scheduler → Cloud Run job → Google Drive import into Gemini File Search
Firestore tracks source revisions and citation metadata.
npm run lint
npm run typecheck
npm run build
npm run dev
git add .
git commit -m "Build your-domain knowledge base app"
git push origin main
# Firebase App Hosting can roll out from the connected GitHub repo.
# For CLI-managed Hosting or Functions deployments:
firebase deploy --only hosting,functions
# Firebase production config:
# GEMINI_API_KEY
# FIREBASE_PROJECT_ID
# GEMINI_CHAT_MODEL=gemini-3.5-flash-lite
# KB_RETRIEVAL_BACKEND=file-search
# The active File Search store is recorded in Firestore.
The automatic sync updates the managed search store and source catalog. Content updates do not require a redeploy.