RAG Systems That Stay Grounded

Retrieval-augmented generation is often introduced as a simple recipe: split documents, create embeddings, search a vector database, and place the results in a prompt. That recipe is enough to produce a demo. It is not enough to produce a system people can trust.

The real promise of RAG is not that a model can say more. It is that the model can say why it believes something, show where the answer came from, and stop when the available evidence is not good enough. That changes the engineering goal from “generate a convincing response” to “make every important claim traceable.”

Start with an explicit retrieval contract

Before choosing an embedding model or tuning a prompt, define the contract between retrieval and generation. A useful result should include a stable source identifier, the original document or page title, a focused passage, its position in the source, and a relevance signal. If the answer cannot point back to that information, the system will be difficult to debug and even harder to explain to a user.

Chunking deserves the same care. Very small chunks remove context; very large chunks bury the relevant sentence in noise. I prefer starting with sections that follow the document's natural structure, then adding a small amount of overlap only where a sentence genuinely depends on the previous section. Tables, headings, and list items should be preserved instead of flattened into an indistinguishable block of text.

This also makes re-indexing safer. Store the document version, source URL, ingestion timestamp, and chunking configuration alongside every chunk. When a result looks wrong, you should be able to answer whether the problem came from stale content, a poor split, or retrieval itself.

Measure grounding separately from fluency

A polished answer can still be unsupported. Track at least three separate signals:

These measurements identify different failures. If the correct passage never appears, changing the prompt will not help. If the passage is present but ignored, the problem may be ranking, context ordering, or instructions. If the answer is well-supported but the citations are confusing, the issue is in the presentation layer.

Build a small evaluation set before making changes. Include straightforward questions, questions that require combining two sources, ambiguous questions, and questions whose answers are deliberately absent. A dozen carefully chosen cases often reveals more than a large collection of random prompts.

Give the model a safe stopping rule

The assistant should be allowed to say that the available context is insufficient. That is not a failure of the product; it is an important product behavior.

The generation prompt should distinguish between evidence and instructions inside the retrieved text. It should require the model to separate direct answers from reasonable inferences, cite the relevant sources, and ask a clarifying question when the request is underspecified. A confidence score invented by the model is not a substitute for this discipline.

For high-impact workflows, add a second check after generation. A lightweight claim verifier can compare each sentence against the retrieved passages and flag answers that contain new names, numbers, dates, or commitments. It does not need to rewrite every response. Its first job is to make suspicious responses visible.

Make retrieval useful before making it clever

Hybrid search is often a better next step than a larger model. Semantic search handles paraphrases, while keyword search protects exact product names, error codes, identifiers, and domain vocabulary. Reranking can help when the first-stage search returns several plausible passages, but it should be added because the evaluation set demonstrates a ranking problem—not because it sounds sophisticated.

Log the question, filters, retrieved source IDs, scores, final citations, latency, and failure reason. Avoid storing sensitive document text unless there is a clear retention policy. Good observability lets you inspect one bad answer without turning every user interaction into an unstructured data dump.

A practical loop for reliable iteration

Start with a small, representative evaluation set. Inspect retrieved passages before reading the generated answer. Change one layer at a time: ingestion, chunking, search, ranking, prompt construction, or presentation. Then rerun the same cases and record what changed.

Reliable RAG is not a single model choice. It is a chain of modest decisions that make evidence easier to find, easier to inspect, and harder to ignore. The best system is not the one that answers every question. It is the one that knows when an answer has earned the user's trust.