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
dotmultiplies and adds- The best vectors come first
- Ties keep the lower id
- k larger than the collection returns everything
- 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.