Top-k by similarity has a failure mode that looks like success. Your corpus contains the same policy paragraph in five documents, the query matches it, and all five slots go to near-identical text. The model gets one fact stated five ways and the answer is confidently incomplete.
Write mmr_select(query_vec, doc_vecs, k, lambda_=0.5) returning a list of k document indices, most valuable first.
Maximal Marginal Relevance picks greedily. Having already chosen a set S, the next document maximises:
$$\lambda \cdot \text{sim}(q, d) \; - \; (1 - \lambda) \cdot \max_{s \in S} \text{sim}(d, s)$$
All similarities are cosine. With lambda_ = 1 this is plain top-k. With a lower lambda it will pass over a near-duplicate in favour of something that adds information.
The first pick has an empty S, so its penalty is 0.
Build the architecture on a canvas: place the components, configure them, connect them into a data flow, and write a short reason for each one. The AI reviewer grades your design against a rubric written specifically for this problem.
Minimum 5 components · needs a wide desktop screen