Skip to content

RAG explained: handing AI a reference book

How do chatbots answer from your company's documents? Here's how RAG, a pattern widely used in AI products, works.

BeginnerBeginnersDevelopers

9 minAs of Oct 2026

By the end of this guide

  • Explain why an LLM doesn't know your internal documents or recent information.
  • Understand how RAG works: question, document search, then answer.
  • Judge whether RAG or fine-tuning fits your situation.
Illustration of a question bubble, a stack of documents with a line found under a magnifier, and an AI answer bubble marked with a source ribbon
Illustration: AI Ping

Who this is for

  • Anyone considering a chatbot over internal documents
  • Anyone who keeps seeing RAG in AI product plans

What you need

  • Reading "What is an LLM?" first will help.

Key ideas

  1. The limit: it only knows what it was trained on

    An LLM only knows what was in its training data. It can't know your company's leave policy or the price list you changed yesterday.

  2. Hand it the reference material with the question

    RAG, or retrieval-augmented generation, finds relevant documents when a question comes in and passes them to the LLM along with the question.

    It's like an open-book exam. Because the answer comes from specific documents, you can show them as sources and check the answer.

    How an internal-docs chatbot handles one question (example)
    StepWhat happensExample
    1Take the question"How far ahead can I book a meeting room?"
    2Find relevant documentsFinds the "Booking rooms" section of the facilities guide
    3Send question and documents togetherPasses that section's text and the question to the LLM
    4Answer with sources"You can book up to two weeks ahead" + a link to the source
  3. Finding the right documents is half the job

    To find relevant documents, systems usually turn text into numbers that capture meaning — a technique called embedding — so documents with similar meaning match even when the words differ.

    Retrieve the wrong documents and you get the wrong answer. Most of a RAG system's quality is decided at this step.

    Check it

    • Open the source documents shown with an answer and check that the answer matches what they say.
    • If the wrong documents keep showing up as sources, fix how documents are organized or searched before tuning the answers.
  4. How it differs from fine-tuning

    Fine-tuning trains the model itself further; RAG leaves the model alone and changes the reference material. For information that changes often, RAG is much easier to maintain.

    RAG and fine-tuning at a glance
    CompareRAGFine-tuning
    What changesThe reference documentsThe model itself
    When information changesSwap the documentsTrain it again
    Showing sourcesCan show the documents it usedHard to show where an answer came from
    Good forPolicies and product facts that change oftenLearning a consistent tone or format

Common mistakes

  • Expecting good results from dumping in every file without organizing them
  • Reading the answer without checking the source documents

References

Keep learning

  • Explainer8 min

    Tokens and pricing, explained simply

    What "$2 per million tokens" on an AI price list means, and how to estimate what your own usage would cost.

    BeginnerBeginnersOffice workersDevelopers
  • Explainer9 min

    What is an AI agent?

    Unlike a chatbot that only answers, an agent takes a goal and keeps going, using tools and checking results, until the job is done. How it works, what it suits, and what to settle before you hand it work.

    BeginnerBeginnersDevelopers