Given a query embedding and a matrix of document embeddings, return the indices of the top-k documents by cosine similarity.
Signature: def topk_cosine(query: np.ndarray, docs: np.ndarray, k: int) -> list
query shape (d,), docs shape (n, d)(docs @ query) / (||query|| * ||docs_i||)Constraint: Use np.argsort (descending).
Math
Asked at
Test Results