Context

What are you building?

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

  1. 01
    Create 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.

  2. 02
    Create a Neon database

    Neon hosts Postgres so this app can store documents without a database running on your machine.

  3. 03
    Enable 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:

  4. 04
    Create 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`.

  5. 05
    Install dependencies

    Stop here and install every package the app uses. Run this from `rag-knowledge-base`:

  6. 06
    Environment 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

Open full guide