// blueprint · working codeest. 2026 · no ads · anonymous stats
Blueprint · intermediate · 7 steps

Build Agentic RAG with Supabase + Gemini

Upload text, PDFs, or a URL; ask questions; get answers with sources. A Next.js page on Vercel plus two Supabase Edge Functions — a write phase (chunk, embed with Supabase's built-in model, store in pgvector) and a read phase (retrieve nearest chunks, ground Gemini) — with the model key kept server-side. Deployable in about ten minutes.

A tactile paper build kit
Your progress0 / 7 steps· 0%

All steps

01Step 1: What We're BuildingA one-page app where you upload text, PDFs, or a URL, then ask questions and get answers *with sources* — powered by two Supabase Edge Functions, Postgres + pgvector, and Gemini, with the browser never touching a model key.4 min02Step 2: The Database — One Table, One Index, One FunctionA single migration turns on pgvector, creates a `documents` table where each row is a chunk plus its `vector(384)` embedding, adds an hnsw cosine index, and defines the `match_documents()` retrieval function — all behind RLS with no policies, so only the service-role key gets in.4 min03Step 3: The Write Phase — Chunk, Embed, StoreThe `ingest` function takes text or a URL, cleans it, slices it into overlapping ~1000-character chunks, embeds each one with Supabase's built-in `gte-small` model, and bulk-inserts the rows — all through a few tiny shared helpers.5 min04Step 4: The Read Phase — Retrieve, Ground, AnswerThe `query` function embeds the question with the same built-in `gte-small` model, calls the `match_documents` RPC for the nearest chunks, builds a strict grounded prompt with numbered sources, asks Gemini, and returns `{ answer, sources }` — which is where "answers with sources" comes from.3 min05Step 5: The Front-End — One Page, Zero KeysA single Next.js client component with an upload panel (text / URL / PDF) and an ask box; PDFs are parsed to text *in the browser*, two thin fetch wrappers hit the functions, and the only config the front-end knows is a public URL — no keys anywhere.3 min06Step 6: Deploy — The Five Steps AI Can't Do For YouCreate the Supabase project and grab your keys, push the migration, set the three server-side secrets, deploy both functions with `--no-verify-jwt`, then deploy the front-end to Vercel — and finish with an end-to-end smoke test that returns a cited answer.3 min07Step 7: Production — What to Change Before It's RealThe demo tier is honest about being a demo — public functions, synchronous ingestion, naive chunking, no evals. Here are the six things to fix before you point it at real users or real money, each with what to change and why.4 min