Command Palette

Search for a command to run...

Hectal
Phase 3: Vector Search: Exact, IVF, HNSW and Smaller Vectors
RAG and Vector Search · Exercise 1 of 6Next
Beginner

Exact top-k search

Write dot(a, b) that returns the dot product of two equal-length lists of numbers.

Write top_k(query, vectors, k) that returns the ids (positions in vectors) of the k vectors with the highest dot product with query, best first. Ties go to the lower id. If k is larger than the number of vectors, return them all.

What Check tests

  1. dot multiplies and adds
  2. The best vectors come first
  3. Ties keep the lower id
  4. k larger than the collection returns everything
  5. An empty collection gives an empty list

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.