Basic RAG (Retrieval-Augmented Generation) is a design pattern that grounds LLM responses in external knowledge by retrieving relevant documents at query time and injecting them into the prompt. It solves the hallucination problem by giving the model factual source material instead of relying on training data alone.
At a Glance
- Problem: A language model knows nothing about documents created after its training cutoff or held in private systems, so questions about them produce refusals or confident answers built from pattern-matching on training data.
- Forces: Generative fluency versus factual grounding; chunks small enough to stay focused, but large enough to stand alone; more retrieved chunks improve coverage, but irrelevant ones add noise and get lost in long contexts.
- Solution: Split documents into chunks and store them in a searchable index ahead of time. At query time, retrieve the top-k relevant chunks and place them in the prompt with the question, so the model answers from that source material.
- Consequences: Gains: answers grounded in current and private documents, plus an audit trail that separates retrieval failures from generation failures. Costs: an extra search hop adds latency, and the index needs an ingestion pipeline to stay in sync with the source of truth.
What problem does Basic RAG solve?
Large language models are trained on a fixed snapshot of text. Once training ends, the model knows nothing about events, documents, or data that appeared after the cutoff date. It also has zero visibility into your private databases, internal wikis, customer records, or proprietary codebases. If you ask it a question about any of those things, it will either refuse to answer or, more dangerously, produce a confident-sounding response built entirely from pattern-matching on its training data.
This is the hallucination problem, and no patch will make it go away. The architecture of a generative model rewards fluency over accuracy. When the model lacks real information, it fills the gap with plausible-sounding text. For consumer chat applications this might be a minor annoyance. For enterprise systems where answers drive decisions, it is a serious reliability risk.
You want the generative fluency of a language model combined with the factual grounding of a search engine, and Basic RAG is the simplest pattern that gives you both.
How does Basic RAG work?
RAG splits the work into two separate pipelines that run at different times.
The first is the indexing pipeline. You take your document corpus, whatever it may be (PDFs, Markdown files, database rows, Confluence pages), and break it into smaller chunks. Each chunk should be a self-contained unit of information, typically a few hundred tokens. You then store these chunks in a searchable index. In the simplest version this could be a full-text search engine. In more advanced setups you would use vector embeddings, but the basic pattern does not require them.
The second is the query pipeline. When a user asks a question, you first send that question to the search index and retrieve the top-k most relevant chunks. You then construct a prompt that includes both the user question and the retrieved chunks as context. The language model generates its answer based on this assembled context rather than relying on its parametric memory alone.
With the source material in its context window, the model no longer has to guess. The quality of the generated answer depends heavily on the quality of what you retrieved. If you retrieve the right passages, the model will synthesize a good answer. If you retrieve irrelevant noise, the model will either ignore it or weave it into a misleading response.
This two-stage approach also gives you an audit trail. You can show users which documents were used to generate the answer. You can log retrieval results separately from generation results. You can debug failures by asking: was the retrieval bad, or was the generation bad? That separation of concerns makes the system much easier to operate.
When should you use Basic RAG?
Use basic RAG when you have a corpus of documents that contains the answers your users need, and the language model does not have access to that information through its training data. This covers most enterprise knowledge base scenarios: internal documentation search, customer support bots grounded in help articles, legal research over case files, medical reference systems over clinical guidelines.
The pattern works well when your latency budget can tolerate the retrieval step, which typically adds 100 to 500 milliseconds depending on your index. It also works best when the answers exist somewhere in your documents. RAG is not a reasoning pattern. If the answer requires multi-step inference that is not spelled out in any single document, basic RAG will struggle. You will need more advanced patterns like chain-of-thought prompting on top of retrieval for those cases.
When not to use it: Do not add retrieval when the model already has what it needs in the prompt or conversation, since every query pays for an extra search hop. If the data changes by the minute or lives in live databases and APIs, a static index goes stale; fetch it with Tool Calling instead. If questions need several retrieval rounds across sources, one top-k pass will miss pieces, so move to Deep Search or Agentic RAG.
Implementation
Worked Example: Cost and Latency
A support assistant answers 10,000 questions a day on the large model, with a 300-token question plus system prompt and a 300-token answer.
| Setup | Calls per request | Tokens per request (in / out) | Cost per 1,000 requests | Latency per request |
|---|---|---|---|---|
| No retrieval (model alone) | 1 LLM | 300 / 300 | $5.40 | 5.5 s |
| Basic RAG (5 chunks of 400 tokens) | 1 search + 1 LLM | 2,300 / 300 | $11.40 | 5.8 s |
Assumptions: the large model costs $3.00 per million input tokens and $15.00 per million output tokens, writes 60 tokens per second, and takes 0.5 s to the first token; the search step takes 0.3 s, inside the 100 to 500 ms range above. Without retrieval, 300 × $3.00 per million = $0.0009 plus 300 × $15.00 per million = $0.0045, so $5.40 per 1,000 requests. With retrieval, 2,300 × $3.00 per million = $0.0069 plus the same $0.0045, so $11.40 per 1,000. Embedding a 20-token query at $0.02 per million adds $0.0004 per 1,000, which rounds to nothing. Generation takes 0.5 s + 300 / 60 = 5.5 s in both cases, and retrieval adds 0.3 s.
Retrieval roughly doubles the cost per answer but adds only 0.3 s, because the 300 output tokens dominate latency; it pays off whenever an ungrounded answer costs you more than the extra $0.006 per request.
What are the common pitfalls?
Chunk size is the first thing people get wrong. If your chunks are too large, you waste context window space on irrelevant surrounding text and risk pushing out other relevant chunks. If your chunks are too small, each chunk lacks enough context to be useful on its own. A chunk that says "see the table above" is worthless when the table is in a different chunk. Finding the right granularity takes experimentation, and the optimal size varies by document type.
The second failure mode is poor relevance filtering. If your retrieval returns ten chunks but only two are relevant, the other eight are noise that the model must wade through. Worse, the model may anchor on an irrelevant chunk and produce a wrong answer with high confidence. Setting a relevance threshold (a minimum similarity score below which you discard results) helps, but calibrating that threshold is tricky.
Context window overflow is the third risk. If you stuff too many retrieved chunks into the prompt, you hit the model's token limit and either truncate content or fail entirely. Even before hitting hard limits, models tend to lose track of information buried in the middle of very long contexts. Keeping retrieved context focused and concise matters more than volume.
What are the trade-offs?
Every RAG query is at least two operations: a search call and a generation call. That extra network hop adds latency. For applications where sub-second response time matters, this overhead is significant and you need to optimize both your index performance and your chunk selection strategy. Caching frequent queries can help, but cache invalidation becomes another thing to manage as your documents change.
Index maintenance is the other ongoing cost. Documents get updated, deleted, and added. Your index must stay in sync with the source of truth. Stale indexes produce stale answers, and users lose trust quickly when the system confidently quotes outdated information. Building a reliable ingestion pipeline that keeps the index fresh is just as important as the retrieval and generation logic, and often more work than people expect.
Goes Well With
Semantic Indexing upgrades the retrieval step from keyword matching to meaning-based search. Basic RAG works with any search backend, but pairing it with vector embeddings raises recall a great deal for natural language queries where the user's phrasing does not match the exact terms in the documents.
Tool Calling extends RAG beyond static document retrieval. Instead of searching a pre-built index, the model can call functions to fetch real-time data from APIs, query live databases, or access any dynamic data source. This turns retrieval into a flexible, programmable layer rather than a fixed index lookup.
References
- Lewis, P., et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020. arXiv
- Robertson, S., & Zaragoza, H. (2009). The Probabilistic Relevance Framework: BM25 and Beyond. Foundations and Trends in Information Retrieval. Link
Further Reading
- Lewis et al., "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks" (2020). The paper that introduced RAG, demonstrating how combining retrieval with generation outperforms pure parametric models on knowledge-intensive tasks. arXiv:2005.11401