mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
Updates the SQL Server vector store connector to support the latest Azure SQL VECTOR_SEARCH() features, matching what was done in EF Core (dotnet/efcore#38075). ## Changes ### VECTOR_SEARCH syntax update - Replace deprecated `TOP_N` parameter with `SELECT TOP(N) WITH APPROXIMATE` - Enable iterative WHERE predicates are now applied during the vector search process, not after retrievalfiltering - Support `skip` via subquery wrapping (`TOP` and `OFFSET/FETCH` cannot coexist in the same SELECT) ### Hybrid search - Same VECTOR_SEARCH syntax changes in the semantic search CTE - Filter support added in the vector search CTE (iterative filtering) ### Azure SQL runtime detection - DiskAnn vector indexes and VECTOR_SEARCH require Azure SQL Database or SQL database in Microsoft Fabric - Added runtime check via `SERVERPROPERTY('EngineEdition')` at table creation and query time - Throws informative `NotSupportedException` when used against on-prem SQL Server - Result is cached per collection instance ### Test infrastructure - Deleted `SqlServerDiskAnnVectorSearchTests.cs` (read-only table workaround no longer tables with latest vector indexes now support full DML)needed - Created `SqlServerConnectionStringRequiredAttribute` to gate DiskAnn tests on Azure SQL connection string availability - Rewrote DiskAnn conformance test to handle 100-row minimum requirement for vector index creation - Updated all command builder unit tests for new SQL syntax ### Kept - `PREVIEW_FEATURES` command in `CreateTable` (needed for future on-prem SQL Server support) --------- Co-authored-by: Copilot <[email protected]>
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using Microsoft.Data.SqlClient;
|
|
using VectorData.ConformanceTests.Xunit;
|
|
|
|
namespace SqlServer.ConformanceTests.Support;
|
|
|
|
/// <summary>
|
|
/// Skips the test(s) when the database is not Azure SQL Database or SQL database in Microsoft Fabric.
|
|
/// This is used for tests that require Azure SQL features not available in on-prem SQL Server (e.g. DiskAnn vector indexes).
|
|
/// </summary>
|
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
|
|
public sealed class AzureSqlRequiredAttribute : Attribute, ITestCondition
|
|
{
|
|
private static bool? s_isAzureSql;
|
|
|
|
public async ValueTask<bool> IsMetAsync()
|
|
{
|
|
if (s_isAzureSql is not null)
|
|
{
|
|
return s_isAzureSql.Value;
|
|
}
|
|
|
|
var connectionString = SqlServerTestStore.Instance.ConnectionString;
|
|
|
|
using var connection = new SqlConnection(connectionString);
|
|
await connection.OpenAsync();
|
|
|
|
using var command = connection.CreateCommand();
|
|
command.CommandText = "SELECT SERVERPROPERTY('EngineEdition')";
|
|
var result = await command.ExecuteScalarAsync();
|
|
var engineEdition = Convert.ToInt32(result);
|
|
|
|
// 5 = Azure SQL Database, 11 = SQL database in Microsoft Fabric
|
|
s_isAzureSql = engineEdition is 5 or 11;
|
|
return s_isAzureSql.Value;
|
|
}
|
|
|
|
public string SkipReason
|
|
=> "This test requires Azure SQL Database or SQL database in Microsoft Fabric.";
|
|
}
|