Repository navigation
fix(retrieval): make TurbopufferVectorStore score metric-aware - #1042
Merged
Merged
Conversation
Fixes #1014. Turbopuffer returns a raw distance (lower is better) while every other store returns a cosine similarity (higher is better) -- a cross-store score comparison or score>threshold filter silently inverted. Convert via 1 - dist for the default cosine_distance metric; leave other metrics (e.g. euclidean_squared, no 1:1 similarity mapping) as a raw distance. Result ordering was always correct, so this only affects score semantics. Co-authored-by: Dhruv Garg <[email protected]>
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.
Summary
TurbopufferVectorStore._search_syncreturned the raw Turbopufferdistvalue asscore. Turbopuffer distance is lower-is-better; every other SynapseKit store returns a cosine similarity (higher-is-better).score > thresholdfilter or a cross-store score comparison silently inverted.distance_metricis configurable (cosine_distancedefault,euclidean_squared), so the fix is metric-aware:1 - distforcosine_distance; other metrics (no well-defined 1:1 similarity mapping) are left as a raw distance, documented in a code comment.Test plan
test_turbopuffer_score_is_metric_awarecovering bothcosine_distanceandeuclidean_squared— confirmed it fails on the pre-fix code and passes after the fix.ruff check,ruff format --check,mypyclean on touched files.Closes #1014