Retrieval-Augmented Generation (RAG) starts by finding the documents whose embeddings are closest to the query embedding.
Implement top_k_similar(query, docs, k):
query: shape (d,)docs: shape (n, d)k document indices with the highest cosine similarity, ordered from most to least similar.Vectorise it — no Python loops over documents.