RAG and Vector Search · Exercise 6 of 6 Previous
Advanced
Quarantine passages that give orders
Write split_hits(hits, phrases). hits is a list of (doc_id, text) pairs and phrases a list of lower-case phrases. A hit is suspicious when any phrase appears in its lower-cased text.
Return a pair (clean_ids, quarantined_ids): two lists of ids, each in the original order. Then write output_ok(answer, sent_ids) that returns True only when the answer contains a citation like [D2] for at least one id in sent_ids.
What Check tests
- Separates the planted passage
- Keeps the original order in both lists
- Nothing suspicious means nothing quarantined
- A cited answer passes the output check
- A bare answer is blocked
- A citation to a source that was not sent is blocked
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.