Command Palette

Search for a command to run...

Hectal
Phase 5: Vector Databases
RAG and Vector Search · Exercise 2 of 5 PreviousNext
Beginner

Search with a payload filter

points is a list of (id, vector, payload). Write search(points, query, k, where) that returns the ids of the best k points by dot product, **only among points whose payload matches every key and value of where**, best first.

where can be None or {} (no filter). Filter first, then rank. Equal scores keep the original order.

What Check tests

  1. The filter removes the best match
  2. No filter keeps everything, ties in original order
  3. An empty filter works like no filter
  4. A filter that matches nothing returns an empty list
  5. All keys must match

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.