Implement latest SQL Server approximate vector search feature#38075
Implement latest SQL Server approximate vector search feature#38075
Conversation
There was a problem hiding this comment.
Pull request overview
Updates EF Core’s SQL Server vector search support to match the latest VECTOR_SEARCH() syntax/requirements (Azure SQL-only at the moment), shifting result limiting to LINQ composition and emitting the WITH APPROXIMATE modifier.
Changes:
- Removed the
topNargument fromSqlServerQueryableExtensions.VectorSearch()and updated translation/SQL generation accordingly. - Updated SQL generation to append
WITH APPROXIMATEwhenTOP(...)is used over aVECTOR_SEARCH()source. - Updated functional tests to run only on Azure SQL, seed enough rows for vector index creation, and assert the new SQL shape.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.SqlServer.FunctionalTests/Query/Translations/VectorTranslationsSqlServerTest.cs | Adjusts vector-search tests for Azure-only execution, new query shape (OrderBy/Take), and updated seeding/index creation. |
| test/EFCore.SqlServer.FunctionalTests/EFCore.SqlServer.FunctionalTests.csproj | Adds Azure SqlClient extensions package to support Azure SQL connectivity scenarios in tests. |
| src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs | Updates VECTOR_SEARCH() TVF SQL and adds WITH APPROXIMATE emission for TOP(...). |
| src/EFCore.SqlServer/Query/Internal/SqlServerQueryableMethodTranslatingExpressionVisitor.cs | Updates translation for VectorSearch to drop the topN argument. |
| src/EFCore.SqlServer/Extensions/VectorSearchResult.cs | Updates XML doc reference to the new VectorSearch signature. |
| src/EFCore.SqlServer/Extensions/SqlServerQueryableExtensions.cs | Removes topN from the public API and updates the expression construction. |
| Directory.Packages.props | Adds centrally-managed version for Microsoft.Data.SqlClient.Extensions.Azure. |
| .gitignore | Ignores language server cache files (*.lscache). |
src/EFCore.SqlServer/Query/Internal/SqlServerQuerySqlGenerator.cs
Outdated
Show resolved
Hide resolved
6755e3f to
7244a28
Compare
7244a28 to
0e2e40a
Compare
0e2e40a to
d970878
Compare
d970878 to
65b1032
Compare
.gitignore
Outdated
|
|
||
| # Language Server cache | ||
| *.lscache |
There was a problem hiding this comment.
Any reason to though? These starting appearing for me, seems right to ignore them no?
There was a problem hiding this comment.
No reason to add duplicates: https://github.com/dotnet/efcore/blob/main/.gitignore#L222
There was a problem hiding this comment.
Ah, you didn't say that it was already done.
Directory.Packages.props
Outdated
| <PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.58.0" /> | ||
| <!-- SQL Server dependencies --> | ||
| <PackageVersion Include="Microsoft.Data.SqlClient" Version="7.0.0" /> | ||
| <PackageVersion Include="Microsoft.Data.SqlClient.Extensions.Azure" Version="1.0.0" /> |
There was a problem hiding this comment.
We should only use this in tests
There was a problem hiding this comment.
We are... But the version is managed centrally here. Any issue?
There was a problem hiding this comment.
Add it here to make sure that it's not used in shipped code: https://github.com/dotnet/efcore/blob/main/test/Directory.Packages.props
There was a problem hiding this comment.
I see, seems overly defensive given one has to actually add a <PackageReference> (these are just version nodes). But will do.
There was a problem hiding this comment.
The primary reason for this file is to allow to use different versions (higher) in tests, but I think the above is a nice side-effect.
See https://learn.microsoft.com/en-us/sql/t-sql/functions/vector-search-transact-sql, https://learn.microsoft.com/en-us/sql/t-sql/statements/create-vector-index-transact-sql?view=sql-server-ver17.
Part of #36384