fix(udf): validate query vector dimensions before computing distances#15
Merged
anoop-narang merged 1 commit intomainfrom Mar 26, 2026
Merged
fix(udf): validate query vector dimensions before computing distances#15anoop-narang merged 1 commit intomainfrom
anoop-narang merged 1 commit intomainfrom
Conversation
Distance UDFs (l2_distance, cosine_distance, negative_dot_product) used zip() to iterate over column and query vectors, silently truncating to the shorter length on dimension mismatch. This returned wrong results instead of an error — especially dangerous on the brute-force fallback path (SELECT *) where USearch dimension validation is bypassed. For FixedSizeList: single upfront check (zero per-row cost). For List/LargeList: per-row check (one branch, negligible vs kernel).
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
l2_distance,cosine_distance,negative_dot_product) usedzip()to pair column and query vectors, silently truncating to the shorter length on dimension mismatch — returning wrong results instead of an errorSELECT *with split providers), where USearch dimension validation is bypassed entirelyFixedSizeList, per-row for variable-lengthList/LargeListTest plan
udf_dimension_mismatch_select_star— key regression test: SELECT * with wrong-dim query on split providers (UDF path), now errors instead of silently truncatingudf_dimension_mismatch_fewer/udf_dimension_mismatch_more— fewer/more dims than column, caught by optimizer pathexec_split_provider_*— split-provider tests covering production topology (scan has vector, lookup doesn't)exec_split_provider_768dim_negative_dot_product— 768-dim IP-metric end-to-end with split providers