Skip to content

Keep each MMR candidate's similarity to the selection as a running maximum - #11

Merged
vlasky merged 1 commit into
vlasky:mainfrom
MayCXC:mmr-running-max-vlasky
Oct 28, 2026
Merged

vlasky merged 1 commit into
vlasky:mainfrom
MayCXC:mmr-running-max-vlasky

Conversation

@MayCXC

@MayCXC MayCXC commented Oct 7, 2026

Copy link
Copy Markdown

vec0_mmr_rerank recomputes, at every selection step, each remaining candidate's distance to every result already selected: about k²/2 times the candidate count, near 285,000 distance computations for k = 50 over the 250 candidates that mmr_lambda's overfetch gives. This keeps max_sim[i], candidate i's highest similarity to the selection so far, and raises it against each new selection alone, so a step measures each remaining candidate once (about 12,500 computations for the same query).

A maximum over the selected results is the same however it is accumulated, and the distances are computed with the same arguments in the same order, so the picks don't change. Over 5,000 cosine vectors of 768 dimensions, 20 queries with k from 20 to 100 and mmr_lambda from 0.3 to 0.7 return identical rowids before and after, in 443 ms against 10.8 s in total (each build measured in its own process). The MMR snapshot tests pass unchanged, and so does the full suite (143 passed, 4 skipped, 259 snapshots).

The same change is on asg017#267, the PR this MMR came from.

…ximum

vec0_mmr_rerank recomputed, at every selection step, each remaining
candidate's distance to every result already selected: about k^2/2 times the
candidate count, near 285,000 distance computations for k = 50 over the 250
candidates that lambda's overfetch gives. max_sim[i] now holds candidate i's
highest similarity to the selection and is raised against each new
selection alone, so a step measures each remaining candidate once.

A maximum over the selected results is the same however it is accumulated,
and the distances are computed with the same arguments in the same order,
so the picks are unchanged: 20 queries over 5,000 cosine vectors of 768
dimensions (k from 20 to 100, lambda from 0.3 to 0.7) return identical
rowids before and after, in 468 ms against 11.4 s in total. The MMR
snapshot tests pass unchanged.
mceachen added a commit to photostructure/sqlite-vec that referenced this pull request Oct 8, 2026
Each MMR step recomputed every candidate's similarity to all earlier
selections. Ported from the unmerged vlasky#11, without its
similarity update after the last selection, which nothing reads.
@vlasky
vlasky merged commit fcdef67 into vlasky:main Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants