Nishaglobal Education logo

Retrieval-augmented generation (RAG)

How to make AI answer from your own documents, with sources: the two halves of a RAG system, what makes it good or bad, how it compares with fine-tuning, and the questions to ask before building one.

Lesson 9 of 3817 min readQuiz: 5 questions

๐ŸŽฏ By the end of this lesson you will be able to:

  • Describe the RAG pipeline: prepare documents, retrieve, augment the prompt and generate
  • Explain why RAG reduces hallucinations and keeps answers up to date
  • Diagnose the common reasons a RAG assistant gives poor answers
In this lesson
  1. Why RAG exists
  2. The RAG pipeline
  3. What makes RAG good or bad
  4. RAG or fine-tuning?
  5. Questions to ask before building a RAG assistant
  6. What this means for your role
  7. Key takeaways
  8. Quiz

Why RAG exists

A language model on its own has three problems for business use. It does not know your private information, such as policies, product docs or past tickets. Its knowledge stops at its training cut-off. And when it does not know, it may invent a plausible answer. Retrieval-augmented generation (RAG) tackles all three by finding relevant passages from your own documents and giving them to the model as part of the prompt, with an instruction to answer only from them.

The RAG pipeline

Preparation (ahead of time)DocumentsSplit into chunksEmbedVector storeAnswering (every question)Question1. Retrievetop passages2. Augmentadd to prompt3. GenerateAnswer with sources[Leave Policy v4, s.3.2]
Preparation happens once (and whenever documents change). Every question then retrieves relevant passages, adds them to the prompt, and the model answers with sources.

A RAG system has two halves. Preparation happens ahead of time: documents are collected, split into passages (called chunks), turned into embeddings (Lesson 8) and stored. Answering happens for every question:

  1. Retrieve: create an embedding for the question and fetch the few most relevant chunks, often with hybrid search.
  2. Augment: put those chunks into the prompt with clear instructions, for example "Answer only from the sources below. If the answer is not there, say you don't know. Cite the source for each fact."
  3. Generate: the model writes an answer grounded in the retrieved text, with citations the user can click to check.

An HR policy assistant

Question: How many days can I carry over to next year?
Retrieved: Leave Policy v4, section 3.2: "Employees may carry over up to five unused days, to be used by 31 March."

You can carry over up to five unused days, and they must be used by 31 March. [Source: Leave Policy v4, section 3.2]

Without RAG, a model might confidently state a typical number from the internet that is wrong for your company.

What makes RAG good or bad

Most RAG problems are retrieval problems: if the right passage is not retrieved, even the best model cannot answer correctly. Teams check each stage separately.

SymptomLikely causeTypical fix
Says "I don't know" but the answer existsRight chunk not retrievedBetter chunking, hybrid search, more results, rewriting the question
Answer mixes up two policiesChunks lack context such as document name or versionAdd titles and metadata to each chunk; filter by version
Quotes an out-of-date ruleOld documents still indexedRemove or flag old versions; refresh on change
Answer adds facts not in the sourcesWeak instructions or long, noisy contextStricter instructions, fewer but better chunks, check citations
Shows a document the user shouldn't seeRetrieval ignores permissionsFilter results by the user's access rights before generating

RAG or fine-tuning?

RAGFine-tuning
What it changesWhat the model can look up for each questionThe model's behaviour, style or skills
Best forFacts that change: policies, docs, products, ticketsConsistent format, tone or a specialised task
Updating knowledgeUpdate the documents, doneRetrain with new examples
Shows sourcesYes, naturallyNo

For "answer questions about our information", RAG is almost always the right first step. Fine-tuning is for teaching behaviour, and the two can be combined.

Questions to ask before building a RAG assistant

  • Which documents are in scope, who owns them, and are they accurate and current?
  • Who may see which documents, and how will the system enforce that?
  • What are 30 to 50 real questions users ask, with the correct answers and sources? This becomes the test set (Lesson 11).
  • What should happen when the answer is not in the documents?
  • How will documents be kept up to date in the system?

What this means for your role

Developer

Most of your effort goes into ingestion and retrieval: chunking, metadata, hybrid search, permission filters and refresh jobs. Log which chunks were used for every answer so problems can be traced.

Tester / QA

Test retrieval and generation separately: for each test question, was the right source retrieved, and was the answer faithful to it? Include questions with no answer in the documents.

Business Analyst / PO

Define scope, sources of truth, document owners and the expected behaviour when no answer exists. Collect the real questions and correct answers early.

Tech Lead / Architect

Design for permissions, freshness and traceability from day one. Plan how documents flow in, how they are versioned and how they are removed.

Project / Delivery Manager

Content clean-up is often the biggest hidden task. Budget time for owners to fix, retire and tag documents before launch.

Scrum Master / Agile

A team knowledge assistant over your own wiki is a great first RAG pilot. Track the questions it fails on as backlog items to improve the docs.

Try it: a mini RAG by hand

  1. Choose a public policy or product document of two to three pages.
  2. Paste it into an AI assistant between <document> tags with the instruction: "Answer only from the document. Quote the sentence you used. If it isn't there, say so."
  3. Ask three questions: one clearly answered, one partly answered and one not covered. Check whether the quotes are real and whether it admits what it doesn't know.

Key takeaways

  • RAG retrieves relevant passages from your documents and makes the model answer from them, with sources.
  • It reduces hallucinations, adds private knowledge and stays current when documents are updated.
  • Most RAG failures are retrieval failures: chunking, search, metadata and freshness matter most.
  • Respect permissions, plan for "no answer" cases, and choose RAG for knowledge and fine-tuning for behaviour.

Key terms

RAG
Retrieval-augmented generation: answering with a model after retrieving relevant passages from your own data.
Chunk
A passage of a document stored and retrieved as one unit.
Grounding
Making a model base its answer on provided sources rather than memory.
Fine-tuning
Further training a model on examples to change its behaviour or skills.

Check your understanding

Answer all 5 questions. Score 3 or more to complete the lesson.

  1. 1. What does RAG add to a language model?

  2. 2. A RAG assistant says "I don't know" although the answer is in the documents. What is the most likely cause?

  3. 3. Your company wants an assistant that answers questions about policies that change monthly. What is the best first approach?

  4. 4. Why must retrieval respect user permissions?

  5. 5. Which instruction best reduces made-up answers in RAG?

Answer all 5 questions to check.

Practise more