Command Palette

Search for a command to run...

Hectal
Phase 4: Ingestion: From Files to Searchable Chunks
RAG and Vector Search · Exercise 4 of 6 PreviousNext
Intermediate

Plan a sync and prove it is idempotent

stored and wanted are dictionaries from chunk id to section name. Write plan_sync(stored, wanted) returning a dictionary with three sorted lists: add (ids only in wanted), update (ids in both whose section differs) and delete (ids only in stored).

Write apply_plan(stored, wanted, plan) that returns the new stored dictionary after the plan is applied. Applying a plan and then planning again must give three empty lists.

What Check tests

  1. New ids are added
  2. Missing ids are deleted
  3. A changed section is an update, not an add
  4. Equal dictionaries need no work
  5. Applying the plan makes the store equal to wanted
  6. Planning again after applying gives an empty plan

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.