2026-10-01
Daily Tech Challenge
A RAG pipeline keeps returning five near-duplicate chunks from the same paragraph, so the team re-ranks the top candidates with Maximal Marginal Relevance (MMR) as below. What does the parameter lam control?
def mmr(query_vec, cand_vecs, k, lam=0.7):
selected, remaining = [], list(range(len(cand_vecs)))
while remaining and len(selected) < k:
def score(i):
rel = cos(query_vec, cand_vecs[i])
red = max((cos(cand_vecs[i], cand_vecs[j]) for j in selected),
default=0.0)
return lam * rel - (1 - lam) * red
best = max(remaining, key=score)
selected.append(best)
remaining.remove(best)
return selectedThursday, October 1, 2026 · A new challenge drops every day