Book a free call

What Is Retrieval Augmented Generation (RAG)?

Retrieval augmented generation, or RAG, pairs a language model with your own documents so answers come from your data. Here is how it works and when to use it.

Hertiv engineering teamReviewed by a senior engineer
5 min read
What Is Retrieval Augmented Generation (RAG)?
On this page

Short answer

Retrieval augmented generation is a way of building AI answers that first searches a set of documents for the facts that matter, then hands those facts to a language model so it can write an answer grounded in your data. It cuts down on made-up details, keeps answers current without retraining, and works well for support, search and internal knowledge tools.

What is retrieval augmented generation?

Retrieval augmented generation, usually called RAG, is a way of building AI answers that first searches a set of documents for the facts that matter, then hands those facts to a language model so it can write an answer grounded in your data.

StepWhat happensExample
RetrieveThe system searches your documents for relevant passagesFinds the refund policy and two help articles
AugmentThose passages are added to the model's promptThe prompt now includes the policy text
GenerateThe model writes an answer using the passagesA reply that quotes the policy, not a guess

RAG matters because a language model on its own can only answer from what it learned in training, which goes out of date and never includes your private documents. RAG gives the model fresh, specific facts at the moment of the question, so answers stay current and tied to your own content.

How retrieval picks the right facts

Retrieval works by turning your documents and the user's question into numbers called embeddings, which capture meaning rather than exact words. Passages whose numbers sit close to the question's numbers are the most relevant, so the system returns those first.

Before any question arrives, your documents are split into chunks, usually a few hundred words each, and each chunk is stored with its embedding in a vector database. When a question comes in, the system compares its embedding with the stored chunks and picks the top few, often three to five.

Chunk size matters. Chunks that are too small lose context, so the model gets fragments it cannot use. Chunks that are too large waste space on text the question does not need. Most teams start with chunks of about 500 words and adjust after testing real questions.

Metadata filters add a second layer of control. A chunk can carry tags such as product, region or date, so the system only searches chunks that match the question's scope. That keeps a support answer from quoting a sales page, and it keeps old versions out of current answers.

RAG vs fine-tuning

RAG and fine-tuning solve different problems, and many teams use both. RAG adds facts at question time, while fine-tuning changes the model itself by training it further on your data.

QuestionRAGFine-tuning
What does it change?The facts in the promptThe model weights
When do answers update?As soon as documents changeOnly after retraining
Cost to startLower, no training runHigher, needs training data and runs
Best forFast-changing factsTone, format and stable knowledge

Pick RAG when your facts change often, such as prices, policies or product docs. Pick fine-tuning when you want the model to write in a certain tone or follow a fixed format. If you need both, start with RAG, since it is cheaper to test. For project ideas, RAG project ideas lists small builds that show the pattern.

When RAG is the right choice

RAG is the right choice when answers must come from documents that change, such as a help centre, a policy library or a product catalogue. It is also the right choice when answers must be checked, since each answer can point back to the passage it came from.

It suits support search, internal knowledge tools, document question-answering and research helpers. In each case the value is the same: the model answers from your content, not from memory, so a wrong answer can be traced to a missing or outdated document.

RAG is a poor choice when the knowledge is stable and the tone matters more than the facts, such as a brand voice guide. It is also a poor choice when there are no good documents to retrieve from, since retrieval cannot fix thin or messy source material.

Example (hypothetical): a support-search pilot

Example (hypothetical): a software company has 5,000 help pages, each about 500 words long, which is 5,000 x 500 words, or 2,500,000 words in total. Split into chunks of 500 words, that gives 2,500,000 divided by 500, which is 5,000 chunks stored in a vector database.

The team runs a pilot on 300 real support questions. Without RAG, the model answers 141 of the 300 correctly. With RAG, retrieving the top five chunks for each question, it answers 231 of the 300 correctly. The gain is 231 minus 141, which is 90 more correct answers, or 90 out of 300, which is 30%.

The pilot also shows where RAG fails: 69 questions still miss, mostly because the help pages do not cover the answer at all. That tells the team to write new pages, not to tune the model, which is the kind of fix RAG makes easy to spot.

Common mistakes

The most common mistake is feeding the model too many chunks. Five good passages beat twenty mediocre ones, since extra text dilutes the prompt and the model loses the key fact. Start with three to five chunks and add more only if answers miss.

Another mistake is skipping evaluation. Teams that never test answers against a set of known questions cannot tell whether a change helped or hurt, so build a small test set first. A third mistake is poor chunking, where a key fact is split across two chunks and neither one ranks well on its own.

Finally, do not treat RAG as a fix for bad documents. If the source pages are outdated or unclear, the answers will be too, so fix the documents first and let retrieval do the rest.

How to start: five steps

Starting with RAG is a small project, and a pilot can run in a few weeks. Follow these steps in order.

  1. Pick one document set. Choose a single source, such as the help centre, and leave the rest for later.
  2. Clean the documents. Remove duplicates and outdated pages, since retrieval will surface whatever you store.
  3. Chunk and store. Split the text into chunks of about 500 words and store them with embeddings in a vector database.
  4. Build a test set. Write 50 to 100 real questions with known answers, so you can score the system.
  5. Measure and iterate. Run the test set, fix the worst failures, and repeat until the score stops improving.

When the pilot scores well, compare frameworks before you build the full version. The best RAG frameworks for startups compares the main options.

How to build an AI proof of concept covers the pilot itself, from scope to a working demo.

Key takeaways

  • RAG retrieves facts from your documents, then hands them to a model to answer.
  • Chunk size matters: about 500 words is a good starting point.
  • RAG suits fast-changing facts; fine-tuning suits tone and stable knowledge.
  • A small test set of real questions is how you know if RAG is working.
  • Fix bad documents first; retrieval cannot fix thin source material.

Frequently asked questions

What does RAG stand for?

RAG stands for retrieval augmented generation. It is a way of building AI answers that first searches your documents for relevant facts, then gives those facts to a language model so it can write an answer based on your data.

Is RAG better than fine-tuning?

Neither is better in general. RAG is better when facts change often, since answers update as soon as documents change. Fine-tuning is better when you want a fixed tone or format, or knowledge that rarely changes.

How many chunks should RAG retrieve?

Start with three to five chunks per question. More chunks can dilute the prompt and hide the key fact, while too few can miss it. Test with real questions and adjust the number based on the score.

What is a vector database used for in RAG?

A vector database stores document chunks with their embeddings, which are numbers that capture meaning. When a question arrives, the system compares its embedding with the stored ones and returns the closest chunks.

Can RAG work with private documents?

Yes, RAG is often used with private documents, since the model only sees the passages retrieved for each question. Keep access controls in place, so the system cannot retrieve documents a user is not allowed to see.

How long does a RAG pilot take?

A small pilot usually takes a few weeks. Pick one document set, clean it, chunk it, build a test set of 50 to 100 questions, and measure. Scale up only after the pilot scores well.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a RAG pilot for your documents?

A senior engineer replies within one business day. Or see our AI POC Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call