Command Palette

Search for a command to run...

Hectal
Phase 10: Security and Privacy (Defensive)
RAG and Vector Search · Exercise 4 of 6 PreviousNext
Intermediate

Delete everywhere, then audit

stores is a dict with three entries: "chunks" and "vectors" map chunk ids such as "D5#1" to values, and "cache" maps a question to a pair (answer, [chunk ids]).

Write delete_doc(stores, doc_id) that removes every chunk, vector and cache entry that belongs to the document: ids start with doc_id + "#", and a cache entry belongs to it when any of its chunk ids does. Write audit(stores, doc_id) that returns the names of the stores (in the order chunks, vectors, cache) that still hold something from the document.

What Check tests

  1. The audit finds all three stores before deleting
  2. After deleting, the audit finds nothing
  3. Other documents are untouched
  4. The cache entry that cites D5 is gone
  5. A document that is not stored is a no-op

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.