Skip to content
OwnlyPlans

Plan

AI Chatbot for Your Docs (RAG)

Chat with your own Markdown docs: answers grounded in your content, with sources, streaming replies and an "I don't know".

Remix

Overview

Turn a folder of Markdown docs into a chatbot that answers only from your content and shows its sources. It uses retrieval-augmented generation (RAG): your docs are split into chunks, embedded and stored in Postgres with pgvector, and the most relevant chunks are given to the model for each question.

Includes a Context7 MCP so your AI coding tool uses the current AI SDK docs instead of guessing.

Before you start: Node.js 20+, a Supabase project, an OpenAI API key and Claude Code or Cursor. About 2.5 hours.

Build it step by step

Sign in to tick steps off
  1. 1

    Create the app and add the docs MCP

    Run npx create-next-app@latest docs-bot (TypeScript, App Router, Tailwind). Save CLAUDE.md, add the Context7 MCP, and put your Markdown docs in a /docs folder (start with 5–20 files).

    Prompt
    Read CLAUDE.md. Use context7 to look up the current AI SDK docs for: streaming chat in a Next.js App Router route handler, the React chat hook, and embedding many values with OpenAI. Summarise the exact imports and function names for the current version. Do not write app code yet.

    Done when You have a short summary of the current AI SDK API from Context7.

    Uses CLAUDE.md Context7 MCP Vercel AI SDK

  2. 2

    Create the vector database

    Run supabase-schema.sql in Supabase → SQL Editor. Add OPENAI_API_KEY, NEXT_PUBLIC_SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY to .env.local (never commit it).

    Prompt
    Save the schema as supabase/schema.sql. Create lib/supabase-admin.ts with a server-only Supabase client using the service role key (import "server-only" so it can never reach the browser).

    Done when The documents table and match_documents function exist; npm run build passes.

    Uses supabase-schema.sql Supabase AI & Vectors docs

  3. 3

    Ingest your docs

    A script reads /docs, splits by headings into ~800-token chunks with overlap, embeds them in batches and upserts into documents.

    Prompt
    Write scripts/ingest.ts (run with npx tsx scripts/ingest.ts): read all .md/.mdx files in /docs, split by headings then into ~800-token chunks with 100-token overlap, embed with text-embedding-3-small in batches using the AI SDK, and upsert into documents on (source, chunk_index). Delete old chunks of a file before re-inserting it. Print files, chunks and estimated tokens.

    Done when Running the script fills the documents table; running it again does not create duplicates.

    Uses supabase-schema.sql

  4. 4

    Retrieval

    Embed the question and fetch the closest chunks with match_documents.

    Prompt
    Create lib/retrieve.ts: embed the question with the same model, call rpc("match_documents") with match_count 6 and min_similarity 0.3, and return chunks with source and similarity. Add a tiny test page /debug/search (dev only) that shows the chunks for a query.

    Done when Searching a topic from your docs returns the right chunks at the top.

  5. 5

    Streaming chat route

    The model answers only from retrieved context and lists sources.

    Prompt
    Create the chat route handler using the current AI SDK streaming API (check with context7). For the latest user message: retrieve chunks, then stream an answer with a system prompt that says: answer only from the context below, quote sources by file name, and if the context does not contain the answer say "I don't know based on these docs". Send the list of sources to the client with the response.

    Done when A request to the route streams a grounded answer.

    Uses Context7 MCP

  6. 6

    Chat interface

    A clean chat with streaming text, sources under each answer and suggested questions.

    Prompt
    Build the chat page with the current AI SDK React chat hook: message list, input, stop button, streaming text, and under each answer the source files as small links. Show 3 suggested questions when the chat is empty. Make it work on mobile.

    Done when You can ask questions and see answers stream with sources.

  7. 7

    Test with 10 real questions

    Measure before you polish. Fill in eval.md with questions you know the answers to.

    Prompt
    Read eval.md. For each question, call the chat route and record the answer and sources in a table. Mark which ones are wrong and suggest fixes (chunk size, min_similarity, system prompt). Apply the safest fix and re-run.

    Done when At least 8 of 10 answers are right, and the out-of-scope question gets "I don't know".

    Uses eval.md

  8. 8

    Limits and deploy

    Protect your API key from abuse, then deploy.

    Prompt
    Add a simple per-IP rate limit to the chat route (e.g. 20 requests per 10 minutes, in-memory is fine for one server; explain options for production), cap the question length, and log token usage. Then list the env vars for Vercel and deploy.

    Done when The bot is live, and rapid repeated requests get a polite "slow down" message.

Files and links

What people built

Show yours

Nobody has shared a build yet. Yours could be the first.

Show what you built

Built this plan? Sign in to share your demo video, live app and screenshots.

Your AI tool
Starter prompt

		

Download the plan