Build mode
RAG
Retrieval-augmented generation finds passages that might answer the question and places those passages in the prompt before the model writes.
Vercel AI SDK 7 · OpenRouter AI SDK Provider 3 · Drizzle ORM 0.45 · Neon 1
Add document → Split into chunks → Embed chunks → Store vectors → Embed question → Similarity search → Ground the model → Stream the answer
- 01Create an OpenRouter API key
OpenRouter sells access to many models through one key. This app uses that key twice: once to embed text, and once to write an answer.
- 02Create a Neon database
Neon hosts Postgres so this app can store documents without a database running on your machine.
- 03Enable pgvector
Postgres does not store embedding vectors until you enable the extension that teaches it how. Drizzle will not do this for you. Open the Neon SQL Editor for the project you just created and run:
- 04Create the Next.js app
From an empty folder, create the app with the App Router, TypeScript, and Tailwind. The flags skip the prompts. There is no `src/` directory. Files in this guide live at the project root, next to `package.json`.
- 05Install dependencies
Stop here and install every package the app uses. Run this from `rag-knowledge-base`:
- 06Environment variables
In the project root, create `.env.local`. `create-next-app` already gitignores `.env*`, so this file stays off GitHub.
6 more steps in Plan.
Verify: A known question retrieves the expected document An unsupported question does not hallucinate an answer