An allow-list, trust levels and a conflict check
The "topic" field is set by ingestion here to keep the example short. In practice it comes from metadata, a classifier or a human tag.
Anyone who can add a document can change the answers. Decide who may add what, record where every passage came from and how far it is trusted, and check that stored vectors still match their text.
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 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write pick(hits) where each hit is (doc_id, trust) and trust is "reviewed" or "untrusted". Return the id of the first reviewed hit, or of the first hit if none is reviewed, or None for an empty list.
Write content_hash(text) using h = (h * 31 + ord(char)) % 1000003 starting from 7, and tampered(rows) where rows maps id to (text, stored_hash) and returns the ids whose stored hash differs.
Explain it without notes
What is data poisoning in a RAG system, and why does ranking not protect against it?
What do an allow-list, provenance and trust levels each contribute?
How can a vector in the store be wrong, and how do you detect it?
Two retrieved passages disagree. What does your system do?
Expected output
ingest D1: accepted as reviewed
ingest D8: accepted as reviewed
ingest U1: accepted as untrusted
ingest W1: rejected (web-crawl is not on the allow-list)
Q: Is a cancelled ride refunded?
topic refund: conflict, using D1 (reviewed), set aside U1 (untrusted)
topic pass: nothing retrieved