Data and accuracyBuilds on other terms

RAG

Written by Minh Khang

What is RAG?

RAG (retrieval-augmented generation) is letting AI find and read your documents before it answers, instead of answering from memory.

RAG (Retrieval-Augmented Generation) has two steps: find the relevant passages in the knowledge base, then give them to the AI together with the question. The AI then answers from your data and can cite it; if the wrong passage is found, the answer is still wrong.

RAG in a shop

A customer asks "can I swap sizes?": the system finds the returns section of the policy, and the AI answers with its conditions.

How does RAG work?

  1. 1The shop's documents (prices, policies, FAQs) are cut into small passages and stored so they can be searched by meaning.
  2. 2When a customer asks, the system finds the few passages closest in meaning to the question, even if the wording differs.
  3. 3Those passages go to the AI with the question and an instruction: answer only from these.
  4. 4The AI answers, possibly citing the source; if nothing fits, it should say it does not know and hand over to a person.

What a shop or café can use it for

  • A chatbot answering size exchanges, delivery fees and warranty questions from the current policy.
  • A new staff member asking "what discount for wholesale orders over 50 pieces?" and getting the answer from internal documents.
  • A bakery answering "does this cake contain egg?" from each cake's ingredient list.

What to watch out for

  • Old documents next to new ones make the AI pick the wrong one: delete the old price list when prices change.
  • If it retrieves the wrong passage it still answers wrongly, so keep guardrails and human approval where money is involved.
  • Do not put sensitive customer data in the document store unless you need to.

Quick questions

  • RAG gives the AI documents at question time, so edits take effect at once; it suits prices and policies that change. Fine-tuning trains the model further on examples; it suits a writing voice or a repeated task.

  • Close, but costlier: every question sends the whole document, using more tokens and confusing the AI when documents are long. RAG sends only the relevant passages.

  • It reduces it a lot, but not completely. The AI can still misread a passage or retrieve the wrong one, so instruct it to say "I don't know" when the answer is not in the documents.

Sources

The dated facts on this page come from the original sources below.

  1. arXiv
    Lewis et al., Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

Keep learning beyond the glossary