Repository navigation
Keep each MMR candidate's similarity to the selection as a running maximum - #11
Merged
Merged
Conversation
…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.
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vec0_mmr_rerankrecomputes, 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 fork = 50over the 250 candidates thatmmr_lambda's overfetch gives. This keepsmax_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
kfrom 20 to 100 andmmr_lambdafrom 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.