Build Top-K Semantic Search
Implement top_k_search(query, documents, k): a list of (index, score) pairs for the k most similar documents, best first. cosine_similarity from the previous problem is already defined for you.
- Sort by score descending, ties broken by the lower index.
- If
kexceeds the number of documents, return all of them. Don't pad, don't raise. k <= 0returns an empty list.- Scores are plain floats.