A production-ready MVP for document chat with Next.js 14, Supabase pgvector, and the raw OpenAI SDK. Upload PDFs, index them, and chat with streaming answers that include source citations.
- PDF upload -> chunk -> embed -> store in Supabase pgvector
- URL import/crawling with automatic content extraction
- Streaming chat responses with markdown rendering and source citations
- Feedback-driven retrieval — thumbs up/down votes adjust chunk quality scores to improve future results
- Admin monitoring dashboard with feedback rate, positive rate, knowledge gaps, and chunk usage stats
- Clickable source badges (links for crawled URLs, expandable content for uploads)
- Clean minimal light-mode UI using Tailwind + shadcn-style components
- Next.js 14 App Router + TypeScript
- Tailwind CSS + shadcn/ui-style components
- Supabase Postgres + pgvector
- OpenAI SDK (no LangChain)
npm installCreate a Supabase project and run the SQL migrations in order:
# Run each migration file in the Supabase SQL Editor:
supabase/migrations/0001_init.sql # Base tables, pgvector, match_chunks
supabase/migrations/0002_add_url_source.sql # URL source tracking on documents
supabase/migrations/0003_match_chunks_url.sql # source_url in match_chunks results
supabase/migrations/0004_feedback_quality.sql # quality_score, feedback-driven retrieval, chunk usage statsCreate a .env.local file:
OPENAI_API_KEY=sk-...
SUPABASE_URL=https://YOUR_PROJECT.supabase.co
SUPABASE_SERVICE_ROLE_KEY=YOUR_SERVICE_ROLE_KEYNotes:
- The app still runs without env vars. Upload + chat will return helpful warnings.
- Use the Supabase service role key for server-side writes.
npm run devVisit:
http://localhost:3000- main apphttp://localhost:3000/admin- admin dashboard
POST /api/upload- Upload PDF and index chunksPOST /api/crawl- Import and index content from a URLGET /api/documents- List uploaded documentsPOST /api/chat- Streaming chat with markdown and citationsPOST /api/feedback- Thumbs up/down (also updates chunk quality scores)GET /api/admin/stats- Dashboard stats, knowledge gaps, chunk usageGET /api/admin/queries- Recent queries
- Push the repo to GitHub.
- Create a new Vercel project and import the repo.
- Add the environment variables in Vercel project settings.
- Deploy.
If you want to self-host, ensure the same env vars are available at runtime.
app/- Next.js App Router pages and API routescomponents/- UI components and client UIlib/- OpenAI, Supabase, chunking, embeddings helperssupabase/migrations/- SQL migrations for pgvector tables and RPCs
MIT
