Command Palette

Search for a command to run...

Hectal
Phase 11: RAG in Production
RAG and Vector Search · Exercise 2 of 5 PreviousNext
Intermediate

A cache with invalidation by document

Complete the class AnswerCache. put(key, answer, doc_ids) stores the answer and remembers that each document in doc_ids was used. get(key) returns the answer or None.

invalidate(doc_id) removes every answer that used that document, forgets the document's record, and returns how many answers were removed (0 for an unknown document).

What Check tests

  1. Stores and returns an answer
  2. Unknown key gives None
  3. Invalidate removes the answers that used the document
  4. Other answers survive
  5. Unknown document removes nothing
  6. A second invalidate finds nothing

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.