Macalinao StudioLearnAll enriched lessons ↗
College path · 7 sectionsSwitch to high school ↗

College / LONGER LESSON 20

RAG: retrieve evidence, then test the answer

Measure retrieval and grounding separately, including missing evidence and hostile passages.

Preparation: Fractions, ranking and basic language models.

Plan 20–35 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

Begin with an answerable question

College path. Measure retrieval and grounding separately, including missing evidence and hostile passages.

Preparation: Fractions, ranking and basic language models. Work through one section at a time. Predict the experiment result before changing its controls, then explain what the example leaves out.

Retrieval-augmented generation supplies selected documents to a generator. Retrieval can help an answer use external evidence, but neither retrieving nor citing a passage guarantees that the answer is supported. Separate corpus construction, retrieval, reranking, context assembly and generation. The original RAG formulation is one architecture; modern systems use many variants and optimization choices.

Worked step 1. Write a question with a known supporting passage.

Worked step 2. Retrieve candidates.

Worked step 3. Compare the final answer with the passage.

Try it yourself. Can a correct-looking citation still be misleading?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. Yes. It may point to a real document that does not support the attached claim.

Section 02 / 07

Choose chunks with their context

Chunk boundaries can separate a statement from its condition, date or negation. Store enough metadata to recover the source and interpret the passage accurately. Chunk size, overlap and document structure trade retrieval specificity against context completeness. Deduplicate overlapping evidence in evaluation and preserve source offsets or stable identifiers.

Worked step 1. Split a paragraph before its exception clause.

Worked step 2. Read the isolated first chunk.

Worked step 3. Then restore the exception and compare the claim.

Try it yourself. Does larger overlap always improve the system?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. It can increase redundancy and cost. Evaluate whether the retrieved context preserves meaning.

Section 03 / 07

Measure precision and recall

Precision asks what fraction of retrieved passages are relevant. Recall asks what fraction of all relevant passages were retrieved. Increasing the retrieval count can affect them differently. Define relevance and the judged corpus before computing metrics. Incomplete relevance judgments can bias recall; retrieval metrics alone do not evaluate generated-answer faithfulness.

precision = hits/k; recall = hits/relevant-total

Worked step 1. Ranked relevance is [1,1,0,1,0,0,1,0].

Worked step 2. Top three has two hits: precision 2/3 and recall 2/4.

Worked step 3. Top four has precision 3/4 and recall 3/4.

Try it yourself. Can recall decrease when adding items to this fixed ranked prefix?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Existing hits remain. Precision can rise or fall depending on the added item.

Section 04 / 07

Understand the discrete selection

Selecting the top-ranked passages is a discrete operation. Ordinary backpropagation through a generator does not automatically train every part of an arbitrary retrieval pipeline. Hard top-k indices are not generally differentiable. Retriever training may use contrastive objectives, marginalization, surrogate methods or separate supervision; specify the actual route for gradients.

Worked step 1. Change a score slightly without changing the top three.

Worked step 2. The selected set remains fixed.

Worked step 3. Cross a rank boundary and the set changes abruptly.

Try it yourself. Does end-to-end branding prove gradients pass through hard top-k?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Inspect the objective and implementation; separate training or approximations may be involved.

Section 05 / 07

Treat retrieved text as evidence, not authority

A retrieved document can contain instructions aimed at the assistant. Those instructions should not acquire permission to change the system’s task, reveal private data or operate tools. Keep instruction hierarchy and tool authorization outside untrusted retrieved content. Test prompt injection, data exfiltration attempts and citation spoofing as application behaviors, not merely embedding quality.

Worked step 1. Retrieve a passage containing a fake system instruction.

Worked step 2. Ask for a factual summary.

Worked step 3. Verify the application treats the instruction as quoted content.

Try it yourself. Should a retrieved page authorize sending a private file?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Tool permissions must come from the application’s trusted authorization flow.

Section 06 / 07

Know when evidence is missing

A useful system can state that the corpus does not support an answer. Evaluate missing, stale and contradictory evidence rather than forcing a confident response to every question. Measure answer correctness, support coverage, citation precision and abstention behavior separately. Include corpus freshness and access control in the evaluation design.

Worked step 1. Ask one supported and one unsupported question.

Worked step 2. Check claim-level citations.

Worked step 3. Record unsupported assertions and appropriate abstentions.

Try it yourself. What should a high retrieval score mean?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. It indicates the retriever’s ranking preference, not proof of truth. The supporting text must still be inspected.

Section 07 / 07

Mastery and transfer

Bring the pieces together. First answer the checkpoint without the worked solutions. Then explain the mechanism in your own words, using one numerical example from this lesson.

Retrieval recall is… Option 1: Relevant retrieved divided by all relevant items. Option 2: All retrieved divided by corpus size. Option 3: A guarantee of answer truth.

Pause here and choose an answer before continuing. The checkpoint explanation follows.

Reveal worked solution

The correct choice is option 1: Relevant retrieved divided by all relevant items. Recall measures coverage under the relevance judgments; grounding is another check.

Transfer task. Change one assumption in the worked example. State your prediction, calculate or test it in Workbench, then explain whether the result supports your prediction.

Reveal worked solution

Self-check rubric. Name the changed assumption, keep the other inputs fixed, show at least one intermediate calculation, and distinguish what the toy example guarantees from what would require a trained model or a real measurement.

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

Reset this college path?

This removes only this path’s notes, progress and experiments from this browser.