Command Palette

Search for a command to run...

Hectal
Phase 13: Interviews and Capstone
RAG and Vector Search · Exercise 3 of 5 PreviousNext
Advanced

Apply the access filter before ranking

Write visible(docs, role) returning the docs this role may see. Each doc is a dict with keys id, text and access. Docs with access "public" are visible to everyone and "staff" docs only to the role "staff".

Write search(docs, role, question, k) that first filters with visible, then scores each doc as the number of different lower-cased words shared with the question (letters and digits only), and returns the ids of the top k docs with a score above 0, best first, ties in list order.

What Check tests

  1. Public sees only public docs
  2. Staff sees everything
  3. A restricted doc never appears for the public
  4. Staff gets the restricted doc first
  5. No overlap means no results

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.