Command Palette

Search for a command to run...

Hectal
Phase 5: Vector Databases
RAG and Vector Search · Exercise 3 of 5 PreviousNext
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

  1. An update leaves one dead row
  2. Search ignores dead rows
  3. The updated vector is the one searched
  4. Deleting an unknown id changes nothing
  5. 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.