Top-K Retrieval by Dot Product
~10 mincode completion
Implement top_k_items(query, items, k) returning the list of the k best item ids (row indices).
Where this shows up
~10 min
••••••••••••••••
8 employers weight this skill
4 quant funds, 2 defense companies, 2 autonomy companies. Top match scores 93.
Python
import numpy as np
def top_k_items(query, items, k):
"""
Ids of the k items with the largest dot product with the query.
Args:
query: (d,) query or user vector
items: (N, d) item embeddings, row j is item j
k: number of items to return, 1 <= k <= N
Returns:
list of k item ids, best first, ties broken by lower id
"""
# YOUR CODE HERE
pass