Intermediate
A store with tombstones and compaction
Write a class Store with upsert(item_id, vector), delete(item_id), search(query, k), stats() and compact().
Rows are only ever appended. upsert of an existing id marks its old row dead and appends a new live row. delete marks the live row dead (and does nothing for an unknown id). search ranks only live rows by dot product and returns up to k ids, best first.
stats() returns the string rows=<all> live=<alive> dead=<dead>. compact() drops the dead rows.
What Check tests
- An update leaves one dead row
- Search ignores dead rows
- The updated vector is the one searched
- Deleting an unknown id changes nothing
- Compaction drops dead rows and keeps 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.