How to do retrieval augmented generation (RAG) with an LLM
Retrieval augmented generation (RAG) means your app retrieves relevant documents when a question arrives and gives them to the LLM as context, so the answer rests on your sources and not on the model's memory alone. You build it in five steps: prepare your documents, index them, retrieve, generate, and then check retrieval and answers separately.
By Arun Prasad · Published · Last updated
On this page
Why retrieval augmented generation matters
A model answers from what it learned in training. It can't know your private documents or anything written after training, and it can still state a wrong answer with confidence. Research on language models has long noted that they store knowledge in their parameters and have limited ability to access and precisely manipulate it. RAG addresses this by letting the model read an external source at question time.
RAG only helps if retrieval returns the right passage. Say a user asks about your refund window and the retriever returns an outdated policy page. The model will write a fluent, confident answer from the wrong text.
This is the core reliability problem with agents. A tool can return a 200 and the task can still fail. Standard monitoring shows that the request went through, not whether the answer was right. A RAG app can show green on every request and still give users wrong answers, so you need to check the quality of each step.
Step 1: Collect and split your documents
Gather the documents your app should answer from, then split them into passages. A passage (often called a chunk) is a piece of a document small enough to be retrieved on its own, such as a section of a help article.
Keep each passage about one idea, so a retrieved passage can answer a question without needing the text around it. Remove duplicates and out-of-date versions at this stage. Every document in your index is something the model may quote.
This guide stays tool-neutral. The choice of vector store, embedding model and LLM is yours.
Step 2: Turn passages into embeddings and index them
Convert each passage into an embedding and store the embeddings in an index. An embedding is a list of numbers that represents the meaning of a piece of text, so passages with similar meaning end up close together.
The index keeps each embedding next to its original text and any details you want to track, such as the document name and date. Re-run this step whenever the source documents change. Otherwise the index drifts out of date.
Step 3: Retrieve the top passages for each question
When a question arrives, embed it the same way and fetch the passages closest to it. The retrieve-then-generate structure is what makes this RAG.
Decide how many passages to fetch. Too few and the answer may be missing. Too many and the useful passage is buried among noise. Log which passages were returned for each question, because you will need them in Step 5.
Step 4: Put the passages in the prompt
Insert the retrieved passages into the prompt and tell the model to answer only from them. Include an instruction for the case where the passages don't contain the answer, such as: "If the passages do not answer the question, say you don't know."
Without that instruction, the model fills gaps from memory. Those answers sound the same as grounded ones.
Step 5: Check retrieval and the answer separately
Test the retriever and the generator as two different steps, so a failure tells you which one to fix. Ask two questions of every test case:
- Retrieval: did the returned passages contain the information needed to answer?
- Answer: did the response say only what those passages support, and did it address the question?
If retrieval failed, changing the prompt won't help; fix the documents, splitting or search. If retrieval succeeded but the answer is wrong, look at the prompt or the model. Build a test set that includes questions your documents can't answer, and check that the app says so.
How this looks in production
Once the pipeline is live, PRISM by Block Convey shows what happened on real runs. This depends on what your integration sends: retrieval context, timing, token, cost and error data appear in PRISM when you supply them. If your app doesn't send the retrieved passages, they won't be in the trace.
What you can see in Agent Observability:
- Traces: the request, response, model, cost, timing and scores for each run.
- Sessions: the multi-turn journey, including drift.
- Agent Runs: steps, tool calls, retries, handoffs and state.
- Scores and alerts.
When your integration sends retrieval context, PRISM collects it with the run.
PRISM also looks across runs. It groups repeated failures into patterns and shows how many sessions share each one. Agent Intelligence surfaces patterns in user intent, how conversations feel, repeated failures and missing knowledge.
Evaluators score real runs. Deterministic rules give the same verdict for the same input and run on 100% of sessions. An LLM-as-judge rule has a model read the exchange. It scores every incoming trace until your plan's allowance runs out (Free: 100 a day), and after that only the deterministic rules run. Each verdict links to the rule, the span, the source checked and the reason, so you can see why a run was marked as failing.
AI Remediation traces a failure to a likely cause. The possible causes include the prompt, a missing source, retrieval, stale state, tool choice, a parameter, a guardrail or a workflow step. It suggests changes to prompts, retrieval, Knowledge Base content, guardrails, workflow state and tool use, and it produces a backlog where each item has severity, suggested fix, owner, expected impact and status. A person reviews every change. After a fix is merged, PRISM compares pass rates for the 7 days before and the 7 days after.
If you want to trace a wrong answer to a likely cause such as retrieval or a missing source, connect your app to PRISM.
Common mistakes
1. Judging only the final answer. A fluent answer can hide a retrieval failure. Fix: score retrieval and response separately, as in Step 5, so you know which step failed.
2. Blaming the model when the source isn't in the index. If the answer was never in your documents, no model can retrieve it. Fix: look for missing knowledge in failing sessions, add the content, and re-index.
3. Testing only the questions you expect. Users ask things your documents can't answer, and a RAG app that guesses is worse than one that says it doesn't know. Fix: include out-of-knowledge questions in your tests and check that the app declines. Synthetic Scenarios (Beta) can generate simulated users from your app description and Knowledge Base, including out-of-knowledge questions, and judge whether the user got what they came for. It is switched off in production; "Request beta access" joins a waitlist.
4. Treating launch as the end. Documents change, users change, and failures repeat. Fix: watch live sessions for repeated failure patterns and re-check after each change.
What is the use of a RAG?
RAG grounds an LLM's answers in your own documents. Typical uses are customer support answers, internal search and policy questions, where the answer must come from a specific, current source and not from the model's general knowledge.
Is RAG still relevant in 2026?
Yes, when answers must rest on your current, private sources. A model can't read documents it has never seen, and retrieval is a direct way to supply them. The limit is that retrieval quality caps answer quality. If the wrong passage comes back, the answer will usually be wrong too, which is why Step 5 checks retrieval on its own.
What are the 7 types of RAG?
There is no standard list of seven types of RAG. The original paper describes two formulations, which differ in whether the same retrieved passages are used for the whole answer or different passages for each token. In practice, what varies between systems is how you split documents, how you retrieve, and whether you re-rank results before generation.
Find out which step of your RAG app fails
Send your app's runs to PRISM and trace failures to a likely cause, such as retrieval, a missing source or the prompt.
Free to start, 100 credits each month.