Implement support for SQL Server VECTOR_DISTANCE() #36383
Merged
roji merged 2 commits intodotnet:mainfrom Jul 19, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements SQL Server vector search support for Entity Framework Core, adding the ability to work with SQL Server's VECTOR data type and related functions. The implementation provides type mapping, query translation, and validation for vector operations.
Key changes include:
- Added
SqlServerVectorTypeMappingfor SQL Server'sVECTORtype with proper dimensions support - Implemented query translation for vector distance functions and vector properties
- Added model validation to ensure vector properties are properly configured and not used in unsupported scenarios
Reviewed Changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
SqlServerVectorTypeMapping.cs |
New type mapping class for SQL Server vector type with custom comparer and literal generation |
SqlServerVectorTranslator.cs |
Query translator for vector functions (VectorDistance) and vector member access (Length) |
SqlServerTypeMappingSource.cs |
Updated to register vector type mapping and handle SqlVector<float> CLR type |
SqlServerModelValidator.cs |
Added validation for vector properties requiring dimensions and preventing use in JSON |
SqlServerDbFunctionsExtensions.cs |
Added VectorDistance function extension for calculating distances between vectors |
SqlServerDatabaseModelFactory.cs |
Updated scaffolding to properly handle vector columns and dimensions |
| Test files | Comprehensive test coverage for vector functionality, type mapping, and query translation |
Files not reviewed (1)
- src/EFCore.SqlServer/Properties/SqlServerStrings.Designer.cs: Language not supported
test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Extensions/SqlServerDbFunctionsExtensions.cs
Outdated
Show resolved
Hide resolved
cincuranet
approved these changes
Jul 18, 2025
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.
Note: this does not include
VECTOR_SEARCH[]translation support (as opposed toVECTOR_DISTANCE()which is included); this is tracked by #36384.Closes #34659