Course module
RAG Fundamentals
RAG is not a vector database plus a prompt.
RAG is not a vector database plus a prompt.
A useful RAG system is a trust pipeline. It decides which knowledge is allowed, which source is current, which evidence is relevant, whether the user can see it, and how the final answer should explain uncertainty.
If you remember only one line from this lesson, remember this:
RAG quality is not only answer quality. It is evidence quality plus answer quality.
Scenario: HR policy assistant
Imagine we are building an internal assistant for employees.
A user asks:
Can I carry forward unused leaves into next year if I joined in October?
This sounds simple. It is not.
The answer may depend on:
- employee location
- joining date
- employment type
- current policy year
- old policy PDFs
- newer handbook pages
- manager-only clarifications
- leave category
- exceptions for probation or notice period
A demo system may retrieve a paragraph that looks similar and answer confidently. A production system must know whether the evidence is specific, current, allowed, and enough.
Why naive RAG fails
The naive version looks like this:
This is useful for a demo. It is dangerous as the whole design.
What goes wrong
| Problem | What it looks like | Why it matters |
|---|---|---|
| Stale source | Old policy PDF retrieved | User gets outdated answer |
| Bad chunking | Table split from heading | Model loses exception conditions |
| Weak ranking | Broad handbook chunk retrieved | Answer becomes generic |
| Missing permissions | Restricted note enters context | Data leakage risk |
| No citations | Answer sounds confident | User cannot verify |
| No abstention | Model answers anyway | Unsupported claim becomes product behavior |
Bad v1 design
A bad v1 usually has these decisions:
- Ingest everything quickly.
- Split by fixed token size.
- Store only text and embedding.
- Retrieve top five chunks.
- Ask the model to answer.
- Add citations later.
- Evaluate by reading a few outputs manually.
This is exactly how many demos start. The issue is not that it is useless. The issue is that it hides the real failure points.
Bad signal
If your team says, “The answer looks good,” but cannot show the exact source, source date, access rule, and retrieval trace, the system is not ready.
Better v1 design
A better v1 is still simple, but it is designed for debugging.
The important change is not just adding more components. The important change is that every step creates a signal we can inspect.
Step 1: define trusted sources
Before embeddings, decide what sources are allowed.
For the HR assistant, a source inventory may look like this:
| Source | Owner | Update frequency | Access | Risk |
|---|---|---|---|---|
| Employee handbook | HR policy team | Quarterly | All employees | Medium |
| Leave policy PDF | HR operations | Yearly | All employees | High if stale |
| Region-specific policy page | Regional HR | As needed | Region employees | High |
| Manager clarification note | HR leadership | As needed | Managers only | Very high |
| FAQ page | HR support | Monthly | All employees | Medium |
This table matters because retrieval quality starts before retrieval. If sources are messy, answers will be messy.
Step 2: capture useful metadata
Embeddings do not know whether a document is current, restricted, official, or location-specific.
Add metadata like:
Metadata lets the system answer questions like:
- Is this source current?
- Does this user have access?
- Is this region-specific?
- Is this a policy, FAQ, or informal note?
- Should this source override an older document?
Step 3: classify the question
Not every question should be handled the same way.
The question:
Can I carry forward unused leaves into next year if I joined in October?
is not a simple keyword lookup. It is an exception case.
A useful classifier might label it as:
This classification decides retrieval filters and answer style.
Step 4: retrieve evidence, not just text
The retrieval target should be an evidence pack.
An evidence pack contains:
- source title
- exact snippet
- section heading
- effective date
- access level
- why it was selected
- whether it conflicts with another source
Example:
Now the model has something structured to reason from.
Step 5: answer with boundaries
A good answer should not just say yes or no.
It should say:
- what the policy says
- what assumptions were used
- where the answer came from
- what is uncertain
- what the user should do next
Example answer shape:
Notice the answer does not pretend to know everything. It gives a useful answer and marks the boundary.
Evaluation signals
Do not evaluate only final answers.
Evaluate the full path.
| Signal | Question | Failure example |
|---|---|---|
| Retrieval precision | Did the exact policy section appear in top results? | Broad handbook page retrieved |
| Freshness | Did the current policy outrank old PDFs? | 2023 PDF used for 2026 query |
| Permission safety | Were restricted sources excluded? | Manager-only note used |
| Groundedness | Can every claim be traced to evidence? | Model invents exception |
| Usefulness | Did the answer help the user act? | Answer gives policy but no next step |
| Abstention | Did the system refuse weak evidence? | Model answers despite conflict |
Debugging playbook
When an answer is wrong, do not immediately change the prompt.
Ask where the failure happened:
- Source failure: Was the right document ingested?
- Metadata failure: Was the source date, region, or access rule missing?
- Retrieval failure: Did the right source fail to appear?
- Ranking failure: Did the right source appear but too low?
- Context failure: Was the evidence pack too noisy?
- Generation failure: Did the model ignore or distort evidence?
- UX failure: Did the answer omit next steps or uncertainty?
This is how a RAG system becomes improvable.
What I would ship first
For a first production version, I would not ingest the whole company knowledge base.
I would ship:
- one workflow
- one department
- 20 to 50 trusted documents
- 50 gold questions
- mandatory citations
- retrieval logs
- answer feedback
- review queue for low-confidence answers
That is enough to learn whether the architecture works.
Practice exercise
Pick one domain:
- college notices
- pharmacy FAQs
- HR policies
- product documentation
- internal SOPs
Then answer these:
- What are the trusted sources?
- Who owns each source?
- What metadata is required?
- What are three common user questions?
- Which question is simple lookup?
- Which question is an exception case?
- What should the system refuse to answer?
- What five eval cases will catch bad retrieval?
Summary
RAG is not just a retrieval pattern. It is a product-quality system.
A good RAG system does five things well:
- Finds the right evidence.
- Filters by user and source context.
- Builds a compact evidence pack.
- Answers with citations and uncertainty.
- Produces debug signals when it fails.
If you design only for generation, you get demos.
If you design for evidence, evaluation, and debugging, you get a system people can trust.
