Handshake Search represents profiles or opportunities as fixed-length numeric vectors. Given a query vector and a large collection of candidate vectors, return the indices of the k most similar candidates using cosine similarity.
Use a bounded min-heap so the algorithm does not sort every candidate. Return indices in descending similarity order. If two candidates have equal similarity, return the smaller index first.
Implement top_k_similar(vectors, query, k).
vectors is a list of n vectors, where each vector is a list of d numbers.query is a length-d vector.k is an integer between 1 and n.k integer indices.dot(a, b) / (||a|| * ||b||).query, have nonzero magnitude.def top_k_similar(vectors, query, k):