Skip to content
Introducing AI OS for Business & School — our most powerful products yet.Explore →
App Corp iconApp Corp
RAG
retrieval augmented generation
RAG
vector search

What Is Retrieval-Augmented Generation?

A practitioner's guide to how RAG works, where it breaks, what it costs and when another approach is a better fit

AE

App Corp Engineering

Editorial Team

November 14, 202613 mins read
13 mins readRead time
1,496Words
Nov 2026Published
App Corp Engineering·Editorial Team

What is What Is Retrieval-Augmented Generation??

Retrieval-augmented generation is an architecture that retrieves relevant passages from an external corpus at query time and supplies them to a language model as context, so the generated answer is grounded in specific source material instead of relying only on parameters learned during training.

Retrieval-augmented generation, usually shortened to RAG, is the most practical way to make a language model answer from your own content. It is also surrounded by more confusion than almost any other AI pattern. Vendors describe it as a feature. Tutorials reduce it to a vector database and a prompt. Neither description helps you decide whether it will work for your problem. This guide treats RAG as an information system: sources, retrieval, ranking, context, generation and evaluation. Once you see those parts clearly, the build decisions become ordinary engineering decisions rather than AI mysticism.

The Definition Without the Mystery

A plain-language version: instead of asking a model to remember everything, you let it read the relevant pages before it answers. The model still writes the response, but the facts come from documents you control. That is the whole idea. Everything else is engineering around how to find the right pages, how much to show, how to keep permissions intact and how to know whether the answer is any good.

The term comes from a 2020 paper by Lewis and colleagues, which combined a parametric sequence-to-sequence model with a non-parametric index of Wikipedia passages. Modern systems vary widely, but the core loop is the same: query, retrieve, rank, assemble context, generate, cite.

Why Language Models Need Retrieval

A model's weights encode patterns, not a live database. It can write a convincing answer about a policy that changed last week, a product released yesterday or a customer contract signed this morning, because it has learned the shape of plausible language. That is the hallucination problem in practical terms: fluency is not evidence.

Retrieval changes the economics of correctness. You do not need to retrain a model every time a document changes. You update the index, and the next answer reflects it. You also get provenance, which matters for audits, customer support and any regulated workflow. A citation does not guarantee the answer is right, but it gives a reviewer something concrete to check, which is often the difference between a useful tool and an untrustworthy one.

The Pipeline, Stage by Stage

Ingestion pulls documents from drives, wikis, ticketing systems, databases and APIs. Parsing turns PDFs, HTML and slides into clean text with structure preserved. Chunking splits content into retrievable units. Embedding converts each unit into a vector. Indexing stores vectors and metadata for search. At query time, the system rewrites or expands the question, retrieves candidates, reranks them, assembles a context window and asks the model to answer with citations.

Each stage has failure modes. Bad parsing loses tables. Bad chunking severs a heading from its explanation. Bad metadata breaks permission filtering. Bad reranking puts a plausible but irrelevant passage first. The generation prompt gets blamed for all of it. When a RAG system gives a poor answer, the cause is more often upstream than in the model.

Retrieval Methods: Keyword, Vector and Hybrid

Keyword search, typically BM25, is excellent when exact terms matter: product codes, legal citations, error messages and names. Vector search captures semantic similarity, which helps when the user's wording differs from the document. Neither is sufficient alone. Hybrid retrieval combines both and usually wins on real enterprise content.

The practical default is hybrid with a reranker. Retrieve a generous candidate set with both methods, merge and deduplicate, then use a cross-encoder or a strong model to score the top few dozen results against the query. Keep metadata filters for date, source, tenant and classification. Measure each stage separately. If recall is poor, no prompt can recover the missing evidence.

Chunking and Data Preparation

Chunking is where most RAG quality is won or lost. Fixed-size chunks are easy and frequently wrong: they cut sentences in half, separate a table from its caption and strip the heading that gives a paragraph meaning. Prefer structure-aware splitting by heading, section or record, with overlap only where continuity matters.

Keep the metadata that supports filtering and citation: source, URL, author, last modified date, department, access labels and document type. Clean out navigation, boilerplate and duplicated content. For structured data, consider retrieving rows or summaries rather than flattening everything into prose. A smaller, well-labelled corpus almost always outperforms a large, messy one.

Reranking and Context Assembly

Retrieval returns candidates; reranking decides what the model actually sees. A reranker scores each candidate against the original question, which is slower than vector similarity but much more accurate. Put the strongest evidence first, respect a token budget, and include source labels so the model can cite them.

Context assembly is a product decision as much as a technical one. Too little context and the model guesses. Too much and it loses the relevant passage among noise, while cost and latency rise. Include adjacent chunks when a section spans a boundary. Deduplicate near-identical passages. If the answer requires combining several documents, say so explicitly in the prompt and require the model to attribute each part.

Evaluation: The Part Most Teams Skip

You cannot improve a RAG system you do not measure. Build a question set from real user queries, with known correct answers and source documents. Measure retrieval recall first: did the right passage appear in the candidate set? Then measure context precision, answer correctness, citation accuracy and refusal behaviour.

Use a mix of automated scoring and human review. LLM-as-judge is useful for scale but needs calibration against people. Track regressions when you change a chunker, embedding model or prompt. Keep a small adversarial set: questions with no answer, questions that require current data, and questions designed to surface a document the user is not allowed to see. Evaluation is the only reliable way to know whether a change helped.

Common Failure Modes

The first is missing evidence: the right document was never ingested, or parsing destroyed it. The second is retrieval miss: the passage exists but the query did not find it. The third is context poisoning: an outdated or low-authority document outranks the correct one. The fourth is permission leakage, where retrieval ignores access labels. The fifth is citation theatre, where the model cites a source that does not support the claim.

Each has a different fix. Missing evidence is a content problem. Retrieval misses need better queries, hybrid search or reranking. Poisoning needs freshness signals and source authority. Leakage needs filters applied before ranking. Citation theatre needs claim-level verification and a refusal path. Diagnose before you tune the prompt.

RAG vs Fine-Tuning vs Long Context

Fine-tuning changes how a model behaves: tone, format, classification boundaries and task-specific patterns. It is a poor way to add facts that change often. Long context windows can hold a lot of material, but stuffing a knowledge base into every request is expensive, slow and still prone to lost-in-the-middle effects. RAG is the right default when answers depend on a changing corpus and provenance matters.

Many production systems combine approaches. Fine-tune for format and domain language, retrieve for facts, and use a long context only when the task genuinely requires reading a whole document. The decision should follow from the failure you are trying to fix, not from which technique is currently fashionable.

What It Costs to Run

RAG has three cost layers: ingestion, retrieval and generation. Ingestion includes parsing, embedding and re-indexing when documents change. Retrieval includes vector search, keyword search and reranking. Generation includes the prompt tokens for retrieved context and the output tokens. Ingestion is usually a batch cost; retrieval and generation scale with usage.

Cost control comes from freshness policy, chunk size, candidate depth and model routing. Re-embed only what changed. Cache frequent queries. Use a smaller model for query rewriting and a stronger one for final answers. Measure cost per answered question and compare it with the value of the task. A support answer that saves ten minutes of agent time can afford more inference than a casual chatbot turn.

Watch the hidden cost of re-indexing. A large corpus with frequent changes can spend more on embedding and parsing than on answering questions. Use incremental updates, content hashes and change feeds rather than rebuilding the world every night. Keep an eye on storage growth too: old versions, duplicate chunks and debug artefacts accumulate quietly. A monthly cost review of the index itself is worth the hour.

Agentic RAG and the Next Step

Basic RAG answers one question with one retrieval pass. Agentic RAG lets the model decide when to search, which source to query and whether the evidence is sufficient. It can decompose a complex question, retrieve from multiple systems, compare results and ask a follow-up. That improves coverage on hard questions and increases cost, latency and unpredictability.

Use it selectively. Start with a deterministic pipeline you can evaluate. Add agentic behaviour for tasks where a single pass demonstrably fails, and keep hard limits on the number of retrieval steps and tool calls. The goal is not autonomy for its own sake; it is a better answer with a trace a human can follow.

Sources and Further Reading

The original RAG paper by Lewis et al. is still worth reading for the architecture and the evaluation framing. NIST's AI Risk Management Framework provides a governance structure for the risks that retrieval does not remove. OWASP's Top 10 for LLM Applications covers prompt injection, insecure output handling and data leakage, all of which apply to RAG systems that read untrusted content.

RAG, fine-tuning and long context compared

ApproachBest atMain limitation
RAGFresh facts, citations, permission-aware answersRetrieval quality and pipeline complexity
Fine-tuningTone, format, classification and domain languageDoes not reliably add changing facts
Long contextReading one large document end to endCost, latency and attention dilution

Most production systems need retrieval for facts and tuning for behaviour. Choose based on the failure you are fixing.

Conclusion

Retrieval-augmented generation is not a model feature or a database product. It is a disciplined pipeline for finding evidence, presenting it to a model and checking the result. The teams that succeed invest in parsing, chunking, permissions and evaluation before they invest in prompt cleverness. If you are starting, choose one question set and prove retrieval recall first. Everything else gets easier once the right evidence is reliably in front of the model.

Frequently Asked Questions

Key Takeaways

  • RAG grounds answers in a changing corpus and provides provenance; it is not just a vector database
  • Hybrid retrieval with reranking is the practical default for enterprise content
  • Parsing and chunking failures are blamed on the model more often than they should be
  • Evaluate retrieval recall separately from answer quality and citation accuracy
  • Use RAG for facts, fine-tuning for behaviour, and long context only when the task needs it

We value your privacy

We use strictly necessary cookies to keep our site secure and functional. With your consent, we also use performance cookies to understand how you interact with our site, and functional cookies to remember your preferences. Read our full Cookie Policy