Retrieval often returns near-duplicate chunks. Maximal Marginal Relevance picks results that are relevant and different from what was already picked. Repeatedly select the unselected document d maximising
lam × sim(q, d) − (1 − lam) × max(sim(d, s) for s already selected) (the max term is 0 for the first pick)
where sim is cosine similarity. Break ties by id ascending. Return the ids of k documents in
selection order.
Implement mmr. Input: query: list[float], docs: dict[str, list[float]], k: int, lam: float. Returns: list[str].
b is almost identical to a, so the more different c wins the second slot.
def mmr(query, docs, k, lam):
return sorted(docs)[:k]
Run executes the public tests. Submit grades against public and hidden tests.
Retrieval often returns near-duplicate chunks. Maximal Marginal Relevance picks results that are relevant and different from what was already picked. Repeatedly select the unselected document d maximising
lam × sim(q, d) − (1 − lam) × max(sim(d, s) for s already selected) (the max term is 0 for the first pick)
where sim is cosine similarity. Break ties by id ascending. Return the ids of k documents in
selection order.
Implement mmr. Input: query: list[float], docs: dict[str, list[float]], k: int, lam: float. Returns: list[str].
b is almost identical to a, so the more different c wins the second slot.
def mmr(query, docs, k, lam):
return sorted(docs)[:k]
Run executes the public tests. Submit grades against public and hidden tests.