Top-K Retrieval by Dot Product

~10 mincode completion

Implement top_k_items(query, items, k) returning the list of the 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
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.