Blog
Three questions for your first RAG project
Test a document assistant with a deadline, an exception, and a question the source cannot answer.
A document assistant can cite the right section and still give the wrong answer. A deadline may be correct while an exception goes missing. Retrieval-augmented generation, or RAG, searches your documents before writing an answer.
In five minutes, you'll run three questions against a fictional handbook. You'll inspect the exact passages and decide which fix to try first.
Use this sample handbook
Copy the sample into a plain-text file named handbook_v1.txt. Keep the blank line between C1 and C2. The Python exercise uses it to split the handbook into two passages, called chunks.
[C1 - Section 2] Standard submissions
2.1 Upload weekly programming assignments through the portal.
2.2 The standard deadline is Friday at 6:00 pm IST.
2.3 Keep the upload receipt for your records.
[C2 - Section 4] Approved extensions
4.1 Approved extensions allow submission until Sunday at 11:59 pm IST.
4.2 Submit the assignment through the same portal.
4.3 Keep the extension confirmation with your upload receipt.Print the evidence in Python
Save this as rag_check.py beside the handbook and run python rag_check.py with Python 3.10 or later. The script fixes which chunks come back, so you can reproduce the search failures without an API.
from pathlib import Path
text = Path("handbook_v1.txt").read_text(encoding="utf-8")
chunks = dict(zip(("C1", "C2"), text.strip().split("\n\n"), strict=True))
def context(ids):
return "\n\n".join(chunks[key] for key in ids)
cases = [
("When is the standard deadline?", ["C1"], ["C1"]),
("Can I submit on Sunday?", ["C1"], ["C1", "C2"]),
("What grade penalty applies after Sunday?", ["C2"], ["C2"]),
]
for question, baseline, checked in cases:
print(question)
print("Baseline:", context(baseline))
print("Checked:", context(checked))
print()Answer each printed question from its shown context. Compare your answers with the checked examples below.
1. Find one fact
- User prompt
- "When is the standard deadline?"
- Retrieved chunks
- C1 in both runs.
Naive output
Friday [C1].
Verified output
Friday at 6:00 pm IST [C1].
Why it failed. The search found the right passage. The answer left out the time. Require the complete deadline and check it against Section 2.2.
2. Connect two passages
- User prompt
- "Can I submit on Sunday?"
- Retrieved chunks
- Baseline: C1. Checked: C1 and C2.
Naive output
Sunday submissions are closed [C1].
Verified output
Yes, with an approved extension, until Sunday at 11:59 pm IST [C2]. The standard deadline is Friday at 6:00 pm IST [C1].
Why it failed. The first search returned only the standard deadline. Increase top-k from one to two for this fixture. Top-k means how many results the search returns.
3. Spot a missing answer
- User prompt
- "What grade penalty applies after Sunday?"
- Retrieved chunks
- C2 in both runs.
Naive output
A 10% penalty applies after Sunday [C2].
Verified output
Section 4 gives the extension deadline [C2]. The retrieved text does not specify a grade penalty.
Why it failed. The citation points to a deadline, so it cannot support a percentage. Ask for evidence for each claim and allow an explicit missing answer.
Choose the next fix
| Symptom | Look first | Fix to try |
|---|---|---|
| A rule is cut off | Chunking | Keep the heading and its rule in the same chunk. |
| The exception is missing | Search results | Return both relevant sections and compare the answers. |
| A fact is incomplete | Answer instructions | Ask for the complete date, time and time zone. |
| A cited claim is invented | Evidence check | Match each claim to an exact passage. Mark missing facts as unspecified. |