NumPy allowed · plain Python earns 10 bonus points
Cosine-like similarity scores ranked before context assembly
Implement one selection step of Maximal Marginal Relevance, the real re-ranking algorithm that balances relevance against redundancy when building a diverse retrieved set.
Implement mmr_select_next(query_sims, selected, doc_sims, lambda_param). Among candidate doc ids NOT already in selected, each candidate d's MMR score is lambda_param * query_sims[d] - (1-lambda_param) * max(pairwise_sim(d,s) for s in selected) (if selected is empty, the second term is 0). Pairwise similarity between two ids is looked up in doc_sims under the key f'{a},{b}' OR f'{b},{a}' (whichever exists). Return the id of the candidate with the HIGHEST MMR score; ties broken by id ascending.
mmr_select_next(query_sims: dict[str, float], selected: list[str], doc_sims: dict[str, float], lambda_param: float) -> str