Advanced level · Module 6: Advanced RAG Architecture and Evaluation · Lesson 3 of 3
RAG Security and Evaluation at Scale
Learners defend RAG against poisoned documents and access leaks, and run large evaluations with automated metrics, sampling and regression tracking.
In this lesson you will
- Secure RAG pipelines
- Evaluate RAG at scale
Key concepts
document poisoningindirect prompt injectionaccess controlautomated metricsregression tracking
The lesson
Documents can contain false facts or hidden instructions. Accept only approved, versioned documents; scan for instruction-like text; treat retrieved text as data; and filter by access level before retrieval results reach the model. OWASP lists prompt injection and vector and embedding weaknesses among the top LLM risks.
At scale, combine automated metrics (hit rate, faithfulness, citation correctness) on hundreds of questions with human review of a sample, and track results over time.
Add every incident and user-reported failure to the evaluation set.
Step by step
- Add a poisoned document and test defences.
- Test access filtering with two roles.
- Run evaluation on 100+ questions.
- Plot results over three versions.
Evaluating a school document assistant on 40 questions
Retrieval and faithfulness by question type show that multi-document and updated-policy questions need work.
Retrieval hit rate (top 5)
87.5%
35 of 40 questions
Illustrative evaluation run
Faithful answers
75.0%
30 of 40 fully supported by cited passages
Unanswerable questions declined
5 of 6
Separate 6-question set
Updated-policy questions
50.0%
2 of 4 faithful; old version retrieved
Show the data behind the chart
| Question type | Questions | Retrieval hit (%) | Faithful answers (%) |
|---|---|---|---|
| Single document | 20 | 95 | 90 |
| Several documents | 10 | 70 | 60 |
| Numbers and tables | 6 | 100 | 66.7 |
| Recently updated policy | 4 | 75 | 50 |
Interpretation
Single-document questions work well (19 of 20 retrieved, 18 of 20 faithful).
Questions that need several documents are the weakest: the right passages were retrieved for only 7 of 10, and only 6 answers were fully supported.
Number and table questions always retrieved the right passage, but 2 of 6 answers misread a table, so retrieval is not the problem there. For updated policies, the old version was retrieved twice.
Recommendations
- Keep tables whole with their headers, and add a check that numbers in the answer appear in the cited passage.
- Remove superseded document versions from the index and show the source date in every answer.
- Retrieve more candidates with reranking for multi-document questions, and re-run the set before release.
Practice activity
Produce a RAG security test and a scaled evaluation report.
Expected result: Defences that hold and a clear trend of evaluation results.
Check your understanding
-
How should retrieved text be treated?
Show answer
As data, never as instructions.
-
Why add incidents to the evaluation set?
Show answer
To prevent the same failure returning.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.