Retrieval-augmented generation, explained simply and built step by step: chunking, embeddings and similarity search you can run, prompts with citations and an honest "I don't know", the Next.js and AI SDK implementation, the UI that makes answers trustworthy, and how to evaluate and secure it.

A language model only knows what was in its training data. It has never seen your help center, your product docs, last week's release notes, or your customer's account. Ask it "How long do refunds take at our store?" and it will either say it doesn't know, or, worse, confidently make something up.
Retrieval-augmented generation (RAG) fixes that with a simple idea: before the model answers, look up the relevant passages from your own content, and hand them to the model along with the question. The model then answers from those passages, and cites them.
Think of it as an open-book exam. The model doesn't memorize your docs. Every time someone asks a question, you open the book to the right pages and say "answer from these".
Why not just paste all the docs into the prompt? Models have a limited context window, every token costs money and time, and models answer worse when the relevant sentence is buried in 200 pages. RAG sends only the few passages that matter.
Why not fine-tune a model on the docs? Fine-tuning teaches style and behavior well, but it's a poor way to store facts: it's slow to update when docs change, it can't cite where an answer came from, and it can't respect who's allowed to see what. RAG updates the moment you re-index a page.
Why this is a frontend topic: "Ask our docs" search, support chat, and in-product help are some of the most common AI features, and a lot of what makes them good is product and UI work: streaming the answer, showing sources people can click and check, saying "I don't know" honestly, and collecting feedback. This tutorial covers the whole thing, with code you can run.