Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 8.7 — Checking the Answer Against the Sources
RAG and Vector Search · Example 1 of 1

Overlap and number checks on five sentences

Look at lines 4 and 5: the wrong number passes the overlap check, and the correct paraphrase fails it. Each check needs the other.

A valid citation does not prove a sentence is supported. Cheap checks in code (content-word overlap, numbers that must appear in the source) catch many unsupported claims, and a judge model gives a second opinion on the sentences that are flagged.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write numbers_in(text) that returns the list of digit-only words in text in order (use re.findall(r"[0-9]+", text)). Print it for "The pass costs 25 dollars for up to 45 minutes.".

02

Write missing_numbers(sentence, source) that returns the numbers of the sentence that do not appear among the numbers of the source. Print it for the sentence "The pass costs 30 dollars for 45 minutes." and the source "The monthly pass costs 25 dollars and includes unlimited rides of up to 45 minutes.".

Explain it without notes

01

Why is checking citations not the same as checking that an answer is grounded?

02

Explain how word overlap fails in both directions.

03

Why check numbers separately?

04

How would you use a judge model without making every answer twice as expensive?

Overlap and number checks on five sentences
Sign in to run this example in your browser.

Expected output

100%  supported      The monthly pass costs 25 dollars.
100%  supported      It includes unlimited rides of up to 45 minutes.
  0%  unsupported    Riders also get a free helmet.
 80%  wrong number 30 The monthly pass costs 30 dollars.
 60%  unsupported    A month of unlimited riding is 25 dollars.