You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.Net: Python: Bug: SqlServerCollection search fails with the default distance function and orders dot results farthest-first #14713
SQL Server vector searches are ordered through the shared DISTANCE_FUNCTION_DIRECTION_HELPER, which treats dot product as a similarity. Two user-visible failures follow:
A vector field left at its default distance function (VectorStoreField("vector", dimensions=...) → DistanceFunction.DEFAULT) is accepted by DISTANCE_FUNCTION_MAP (mapped to cosine) but has no entry in the direction helper, so every SQL Server search fails at runtime with KeyError: <DistanceFunction.DEFAULT: 'DEFAULT'>.
A field using DistanceFunction.DOT_PROD builds ORDER BY ... DESC, returning the least similar rows first.
VECTOR_DISTANCE is a distance for every metric SQL Server supports; the dot metric is the negative dot product and Microsoft documents that smaller values are more similar.
To Reproduce
No database or model call is needed to construct the query:
The same failure is reachable through SqlServerCollection.search(vector=...) when the model's vector field omits distance_function. With distance_function=DistanceFunction.DOT_PROD, the generated query ends with ORDER BY _vector_distance_value DESC.
Expected behavior
The default search should return results ordered by cosine distance, nearest first. Dot-product results should also be ordered ascending: SQL Server's VECTOR_DISTANCE('dot', ...) is the negative dot product, and smaller values indicate more similar vectors.
Screenshots
Not applicable.
Platform
Language: Python
Source: main at d41312f
AI model: Not applicable (query construction only)
IDE: Not applicable
OS: Windows 11
Additional context
InMemoryCollection already resolves DEFAULT to COSINE_DISTANCE. The .NET SQL Server connector made the same dot-product ordering fix in #13071 (NegativeDotProductSimilarity from DESC to ASC). I have a fix and regression tests ready and will open a PR linking this issue.
changed the title [-]Python: Bug: SqlServerCollection search fails with the default distance function and orders dot results farthest-first[/-][+].Net: Python: Bug: SqlServerCollection search fails with the default distance function and orders dot results farthest-first[/+]on Nov 3, 2026
Activity
[-]Python: Bug: SqlServerCollection search fails with the default distance function and orders dot results farthest-first[/-][+].Net: Python: Bug: SqlServerCollection search fails with the default distance function and orders dot results farthest-first[/+]