· 14 min read

What Is RAG in AI? Retrieval-Augmented Generation Explained

RAG stands for retrieval-augmented generation. It is a way of building AI applications in which the system first searches a body of content you control, such as documents, tickets or database records, and then gives the passages it found to a language model together with the user's question. The model writes its answer from those passages instead of relying only on what it memorized in training. This guide explains how that works, what it does and does not fix, and how to decide whether your product needs it.
Documents flowing into a search index, a magnifier selecting passages and a language model producing an answer with citations, illustrating retrieval-augmented generation
Considering RAG for your product?Tell us what questions the system should answer and where the knowledge lives today. We’ll tell you whether RAG fits and what a first version would involve.
Discuss my RAG project

What RAG means, in plain terms

A language model knows two kinds of things: what it absorbed during training and what is in the prompt in front of it. Training knowledge is broad but frozen at a cutoff date, and it never included your contracts, your help center or last week's price list. Ask about those and the model either says it doesn't know or, worse, produces a fluent guess.

RAG closes that gap through the prompt. The three words describe the three moves:

  • Retrieval. A search step finds the passages in your content that are most relevant to the question.
  • Augmented. Those passages are inserted into the prompt next to the question, usually with an instruction to answer only from them and cite them.
  • Generation. The model writes the answer, now with the facts in front of it.

The usual analogy is an open-book exam. The model still does the reading and the writing, but it works from the right pages instead of from memory. The term comes from a 2020 paper, "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks", by Patrick Lewis and co-authors at Facebook AI Research, University College London and New York University. The original work trained the retriever and the generator together. What the industry calls RAG today is looser: any system that retrieves content at question time and feeds it to a general-purpose model.

When people say "RAG in generative AI", they mean this pattern applied to chat assistants, search, copilots and document tools. It is the default way to make a general model useful on private or fast-changing knowledge.

How RAG works, step by step

A RAG system has two halves. Indexing happens ahead of time, whenever content changes. Answering happens on every question, usually within seconds.

The two halves of a RAG system (simplified) INDEXING · when content changes Sources docs, tickets, DB Parse and chunk clean, split, tag Embed text to vectors Search index vectors + keywords metadata, permissions ANSWERING · on every question Question from a user Retrieve search, filter, rerank Build prompt question + passages Language model answer + citations top passages the user is allowed to see The model never searches the corpus itself. It only sees the handful of passages retrieval selected, so the quality of the answer is capped by the quality of the search.
Indexing prepares the content once. Answering reuses the index on every question and sends only a few passages to the model.
  1. Collect and parse the sourcesPull content from where it lives: PDFs, wikis, help centers, ticket systems, databases. Extract clean text and keep the structure that carries meaning, such as headings, tables and page numbers. Poor parsing of PDFs and tables is a frequent cause of wrong answers later.
  2. Split into chunksCut each document into passages along natural boundaries such as sections or paragraphs; a few hundred tokens per chunk is a common starting point, to be tuned on your own test questions. Chunks that are too small lose context; chunks that are too large bury the relevant sentence and waste prompt space. Attach metadata to each chunk: source, date, product, language and who may see it.
  3. Embed and indexAn embedding model turns each chunk into a vector, a list of numbers positioned so that texts with similar meaning sit close together. Store the vectors in an index, usually next to a classic keyword index over the same chunks.
  4. Retrieve for each questionEmbed the user's question, find the nearest chunks, and combine that with keyword matches. This combination is called hybrid search, and it matters because vectors catch paraphrases while keywords catch exact terms such as part numbers, error codes and names. Filter by the user's permissions before anything else.
  5. Rerank and trimA reranking model reads the question together with each candidate passage and scores how well it actually answers. Keep the top handful. This step can improve answer quality more than switching to a larger language model.
  6. Generate with instructionsPut the question and the chosen passages in the prompt, with rules: answer only from the sources, cite them, and say so when they do not contain the answer.
  7. Check, cite and logShow the sources next to the answer so users can verify it. Log the question, the retrieved passages and the response, because that record is how you find out which half failed when an answer is wrong.

The component-level view, with the design choices at each stage, is in our RAG architecture guide. If you plan to build on a framework, see RAG with LangChain and our comparison of the best RAG tools.

What RAG fixes and what it does not

RAG is popular because it solves several problems at once without retraining a model. It also has limits that no amount of prompt tuning removes.

RAG helps withRAG does not help with
Private knowledge. The model can answer from documents it never saw in training.Bad sources. Outdated, contradictory or missing documents produce outdated, contradictory or missing answers.
Freshness. Update the index and the next answer reflects it. No retraining.Aggregation. "How many contracts expire next quarter?" needs a database query, not five retrieved passages.
Verifiability. Answers can cite the passages they came from.Whole-corpus reasoning. "Summarize the themes across all 4,000 tickets" does not fit in a handful of chunks.
Access control. Retrieval can filter by user, so one model serves people with different permissions.Behavior. Tone, output format and task skill come from prompts or fine-tuning, not from retrieved facts.
Fewer invented facts. The model has the real text in front of it.All hallucinations. The model can still misread a passage or answer from memory when retrieval comes back empty.

The right-hand column is why mature systems rarely stop at plain RAG. Aggregate questions get routed to SQL or an analytics tool. Multi-step questions go to an agent that can search several times and call other tools; our articles on RAG agents and RAG vs agentic AI cover that step. For connecting a model to live systems and actions, as opposed to documents, see RAG vs MCP. And for the remaining wrong answers, RAG hallucinations explains where they come from and how to reduce them.

RAG vs fine-tuning vs long context

These three are the usual candidates when a general model doesn't know enough about your business. They are not interchangeable, and the decision rule is short: if the model lacks facts, retrieve them; if it lacks a behavior, train it; if the facts are few and stable, just put them in the prompt.

RAGFine-tuningLong context
What it doesSearches your content per question and adds the best passages to the promptTrains the model further on your examples, changing its weightsPuts the whole document set into every prompt
Best forLarge, changing or permissioned knowledgeConsistent format, tone or a narrow task at high volumeA small, stable set of documents; one-off analysis of a long file
Keeping knowledge currentRe-index the changed documentsRetrainEdit the prompt content
CitationsNatural: each passage has a sourceNot available: knowledge is blended into weightsPossible, but harder to verify across a long prompt
Per-user access controlYes, by filtering retrievalNo, everyone gets the same modelOnly by assembling a different prompt per user
Cost per requestLow to moderate: a few passages plus a searchLow: short prompts, sometimes a smaller modelHigh: you pay for the full corpus in tokens every time, less with prompt caching
Upfront workIngestion pipeline, index, evaluationLabeled training data, training runs, re-evaluation on every base model changeAlmost none
Main riskRetrieval misses the right passageKnowledge goes stale; quality regressions are hard to traceCost, latency and missed details as the prompt grows

The options combine well. A common production setup retrieves passages with RAG, uses a generous context window so it can pass more of them, and fine-tunes a small model only for a narrow sub-task such as classifying incoming questions. A practical order is to start with long context while the corpus is small, move to RAG when cost, latency or permissions start to hurt, and consider fine-tuning last. The detailed comparison, with cost examples, is in RAG vs fine-tuning.

The components of a RAG system

If you are scoping a build or reading a vendor proposal, these are the parts you should expect to see named. A proposal that only mentions "a vector database and an LLM" is describing a demo.

ComponentWhat it doesDecision to make
Connectors and parsersPull content from sources and extract clean text, tables and structureWhich sources first; how to handle scans, tables and attachments
ChunkerSplits documents into retrievable passages with metadataChunk size and boundaries; what metadata to keep
Embedding modelTurns text into vectors for meaning-based searchHosted or self-hosted; language coverage; changing it later means re-embedding everything
IndexStores vectors and keywords and searches them fastA vector extension in your existing database, your search engine, or a dedicated vector database
Retriever and rerankerFinds candidates, applies filters, orders them by relevanceHybrid search or vector only; how many passages to pass on
Language model and promptWrites the answer from the passagesWhich model; how strict the "answer only from sources" rule is
Access controlEnsures users only retrieve what they may openHow source permissions are synced into the index
Evaluation and monitoringMeasures retrieval and answer quality before and after releaseWho owns the test set and the release gate

Product teams adding this to a multi-tenant application have extra concerns, such as tenant isolation and per-customer indexes, covered in RAG pipeline for SaaS. If you would rather buy than assemble, compare enterprise RAG platforms and RAG-as-a-service providers first.

Where RAG fails

When a RAG answer is wrong, the cause is usually in one of five places. Knowing them lets you ask the right question in a review: was the right passage retrieved or not?

  • The passage was never retrieved. The answer exists in the corpus, but search ranked other chunks higher. Typical causes are vector-only search missing exact terms, questions phrased very differently from the documents, and no reranking.
  • The chunk lost its meaning. A table was split from its header, or a clause from the definition it depends on. The retrieved text is technically relevant and practically useless.
  • The index is stale or duplicated. Three versions of a policy are indexed and the model quotes the oldest. Deleted documents still answer questions.
  • The model ignored or misread the sources. The right passage was in the prompt, and the answer still contradicts it or adds unsupported detail. Stricter instructions, fewer and better passages, and a check of answers against sources reduce this.
  • Security was treated as a prompt. Permissions enforced by telling the model "don't reveal HR documents" will leak. So will a system that follows instructions hidden inside a retrieved document, which is known as indirect prompt injection. Filter in retrieval, and treat retrieved text as data, never as commands.
Measure the two halves separately

A useful evaluation set has real questions, the expected answer and the passages that contain it. It lets you score retrieval (did the right passage reach the prompt?) apart from generation (is the answer supported by the passages, and is it correct?). Without that split, a team can spend weeks tuning prompts to fix what is actually a search problem. Our RAG evaluation guide covers metrics and tooling.

Built by Gilzor

Results we’ve shipped

70+products launched
98%delivered on time
85%clients come back
5.0on Clutch
Art Scherbakov, Co-FounderAndrew Laminsky, CTOYuri Rudenya, Head of Mobile Development at GilzorAlena Timofeeva, Product Marketing Lead

Talk to the people who build it. Tell us about your project and get a free estimate of scope, timeline and cost.

See how we’d approach yours

What RAG costs, at a glance

RAG has a build cost and a running cost, and they behave differently. The build is mostly engineering time. The running cost scales with usage and corpus size.

Cost lineWhen you payWhat drives it
Ingestion and parsingBuild, then on every content changeNumber and messiness of sources; scans and tables cost the most effort
EmbeddingsOnce per chunk, again if you change the embedding modelCorpus size; usually a small line compared with generation
Index hostingMonthlyNumber of vectors, replicas, managed or self-hosted
GenerationPer requestModel tier, passages per prompt, answer length, request volume
Reranking and guardrailsPer requestExtra model calls; they add latency as well as cost
Evaluation and maintenanceOngoingSomeone reviewing samples, growing the test set and re-running it on every change

For the build, our 2026 estimates with a Central/Eastern European or Latin American vendor are about $15,000–40,000 for a prototype on one source, $40,000–120,000 for a production system for one use case with permissions, evaluation and monitoring, and $120,000–300,000 and more for a multi-source enterprise system. US onshore agencies usually quote about 2–2.5 times as much. These are estimates, not quotes. The biggest swing factors are the number of sources, how strict access control must be, and whether the system runs in your own infrastructure. Our RAG development cost guide breaks the numbers down, and RAG development walks through the project phases.

Is RAG the right fit? A quick check

Tick what is true for your use case. The more boxes you tick, the stronger the case for RAG over a plain model call or fine-tuning.

RAG fit check

Typical products that tick most of these boxes are customer support assistants, internal knowledge search, sales and onboarding copilots, and contract or policy lookup. RAG use cases goes through them by industry with what each needs to work.

Where to go next

This page is the overview. Each topic has its own guide:

FAQ

What does RAG stand for in AI?
RAG stands for retrieval-augmented generation. Retrieval is the search step that finds relevant passages in your content. Augmented means those passages are added to the prompt. Generation is the language model writing the answer from them. The term comes from a 2020 research paper by Patrick Lewis and co-authors at Facebook AI Research, University College London and New York University.
What is RAG in simple terms?
It is an open-book exam for a language model. Without RAG, the model answers from memory, which ends at its training cutoff and never included your internal documents. With RAG, the system first looks up the relevant pages in your content, hands them to the model with the question and asks it to answer from those pages and cite them.
Is RAG the same as a large language model?
No. The language model is one component. RAG is a system design around it: an ingestion pipeline that prepares your content, an index you can search, a retrieval step that picks passages for each question, and a prompt that tells the model to answer from them. You can swap the model without rebuilding the rest.
Does RAG stop hallucinations?
It reduces them and makes them easier to catch, but it does not remove them. If retrieval returns the wrong passages, or none, the model may still produce a confident answer from memory. A well-built system instructs the model to say when the sources do not contain the answer, shows citations, and measures how often answers are actually supported by the retrieved text.
Do I need a vector database for RAG?
Not always. Retrieval can run on keyword search, on vector search, or on both together, which is the common production setup. For a few thousand documents, a vector extension in the database you already run or the search engine you already have is often enough. A dedicated vector database earns its place at larger scale or when you need its filtering and operational features.
Is RAG still needed now that models have very long context windows?
For a small, stable set of documents, putting everything into the prompt can be simpler than building retrieval. Beyond that, RAG keeps its advantages: you pay for a few passages per request instead of the whole corpus, responses are faster, each user only sees content they are allowed to see, and the index can be updated without touching prompts. Long context and RAG are often used together.
How much does it cost to build a RAG system?
Our estimates for 2026, with a Central/Eastern European or Latin American vendor: a prototype on one source costs about $15,000–40,000, a production system for one use case with permissions, evaluation and monitoring $40,000–120,000, and a multi-source enterprise system $120,000–300,000 and more. US onshore agencies usually quote about 2–2.5 times these numbers. Running costs for embeddings, search and model calls come on top. Our RAG development cost guide shows how the estimates are built.

Where Gilzor fits

If this overview left you with "we probably need RAG, but for which questions and over which sources?", that is the right place to start a conversation. Gilzor builds custom RAG systems, RAG applications and chatbots, adds RAG to existing products, and consults on and evaluates systems that are already running. Our AI work includes an AI payroll platform with PDF data extraction that cut salary calculation errors by 17% and QLode, an AI fashion commerce product with image and text search. We have launched 70+ products, and 85% of clients come back. The team works from Poland with partial overlap with the US working day, and a 2-week fixed-price Discovery Sprint is the usual way to turn a use case into a scoped first version. See our RAG development services, or RAG consulting if you want a second opinion on an approach before you build.

No sales pitch

Get a straight answer for your project

Tell us what you’re building. We’ll reply with options, a rough cost and timeline. If we’re not the right fit, we’ll say so.

Next, a few optional questions so the first call is useful. We use your details only to reply to your request. Privacy Policy

Andrew Laminsky
Written byAndrew Laminsky

CTO of Gilzor. Responsible for architecture and the engineering standards our teams work by.

LinkedIn →

Gilzor · AI/ML Solutions partner

Need a team for your AI product?

95%referred by business partners
70+successful launches
85%repeat business
98%delivered on time

The team behind them

Art Scherbakov
Art ScherbakovCo-Founder
Andrew Laminsky
Andrew LaminskyCTOLinkedIn
Yuri Rudenya
Yuri RudenyaHead of Mobile Development at GilzorLinkedIn
Alena Timofeeva
Alena TimofeevaProduct Marketing LeadLinkedIn
Tell us what you’re buildingOptions, a rough cost and timeline for your project. No commitment.

More insights