Generative AI · Advanced level

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

  1. Add a poisoned document and test defences.
  2. Test access filtering with two roles.
  3. Run evaluation on 100+ questions.
  4. Plot results over three versions.
Dashboard

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

Retrieval hit and faithful answers by question type (%) Retrieval hit (%): Single document 95, Several documents 70, Numbers and tables 100, Recently updated policy 75. Faithful answers (%): Single document 90, Several documents 60, Numbers and tables 66.7, Recently updated policy 50 0255075100Single docu…Several doc…Numbers and…Recently up…Retrieval hit (%)Faithful answers (%)
Show the data behind the chart
Question typeQuestionsRetrieval hit (%)Faithful answers (%)
Single document209590
Several documents107060
Numbers and tables610066.7
Recently updated policy47550

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

  1. How should retrieved text be treated?

    Show answer

    As data, never as instructions.

  2. 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.