RAG Explained: Retrieve, Then Answer (the Prompt That Kills Hallucinations) A developer explains that RAG (Retrieval-Augmented Generation) reduces LLM hallucinations by fetching relevant document chunks at query time and instructing the model to answer using only that context. The technique involves embedding the question, performing a vector search to retrieve the top chunks, and constructing a prompt that forces the model to rely solely on the provided context. The developer shares a simple template and notes that the key is including the phrase 'ONLY the context' to prevent the model from blending in its own memory. An LLM only knows what it saw in training. It doesn't know your company wiki, last week's news, or the PDF you just uploaded. Ask it anyway and it either refuses or — worse — confidently makes something up. RAG Retrieval-Augmented Generation fixes that, and it's far simpler than the name suggests. This is Day 5 of my PromptFromZero series. Fetch the relevant facts at question time, and hand them to the model to read. You're not asking the model to remember . You're giving it the page to read . Embed the question, find the closest document chunks vector search , grab the top few: js const hits = await search question, { k: 3 } ; // the 3 most relevant chunks The retrieval half is its own topic — embeddings + a vector database. I built exactly that in TechFromZero Day 45 with Postgres + pgvector. This template is 80% of RAG quality: js const prompt = Answer using ONLY the context below. If the answer isn't there, say "I don't know." Context: ${hits.map h = "- " + h.text .join "\n" } Question: ${question} ; The words "ONLY the context" matter. Without them, the model blends its own possibly wrong memory back in. With them, it sticks to the source you gave it. Send that prompt to the LLM. Done. The answer is now grounded in your documents. Hallucinations mostly happen when the context doesn't contain the answer but the model answers anyway. Two instructions turn a guesser into a librarian: That's it. Retrieve → Augment → Generate. Pair this prompt half with a vector store pgvector, Pinecone, Chroma... and you've built "chat with your docs." 📎 Try the interactive RAG playground — watch retrieval + the prompt + the answer: https://dev48v.infy.uk/prompt/day5-rag-basic.html https://dev48v.infy.uk/prompt/day5-rag-basic.html Day 5 of PromptFromZero. One prompting technique a day, explained for beginners.