From 9e483c7492798cc1c8aef17b73b23b65a377c21d Mon Sep 17 00:00:00 2001 From: Davide Mauri Date: Thu, 4 Sep 2025 14:00:54 -0700 Subject: [PATCH 1/2] Fixed sorting for negative DOT product --- dotnet/src/VectorData/SqlServer/SqlServerCommandBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/VectorData/SqlServer/SqlServerCommandBuilder.cs b/dotnet/src/VectorData/SqlServer/SqlServerCommandBuilder.cs index c847bce286ac..ccf4ce62c4a4 100644 --- a/dotnet/src/VectorData/SqlServer/SqlServerCommandBuilder.cs +++ b/dotnet/src/VectorData/SqlServer/SqlServerCommandBuilder.cs @@ -657,8 +657,8 @@ private static string Map(PropertyModel property) DistanceFunction.CosineDistance => ("COSINE", "ASC"), // A value of 0 indicates that the vectors are identical, while larger values indicate greater dissimilarity. DistanceFunction.EuclideanDistance => ("EUCLIDEAN", "ASC"), - // A value closer to 0 indicates higher similarity, while more negative values indicate greater dissimilarity. - DistanceFunction.NegativeDotProductSimilarity => ("DOT", "DESC"), + // Smaller numbers indicate more similar vectors + DistanceFunction.NegativeDotProductSimilarity => ("DOT", "ASC"), _ => throw new NotSupportedException($"Distance function {name} is not supported.") }; } From 68f2735b7e96e2eb2a8cb354cf7179fa0f2dc510 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Wed, 10 Sep 2025 10:59:20 +0100 Subject: [PATCH 2/2] Also fix integration tests --- .../Support/SqlServerTestEnvironment.cs | 3 +-- ...VectorSearchDistanceFunctionComplianceTests.cs | 2 +- ...VectorSearchDistanceFunctionComplianceTests.cs | 15 --------------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/dotnet/test/VectorData/SqlServer.ConformanceTests/Support/SqlServerTestEnvironment.cs b/dotnet/test/VectorData/SqlServer.ConformanceTests/Support/SqlServerTestEnvironment.cs index 592a553209fa..6cf50a0d78cc 100644 --- a/dotnet/test/VectorData/SqlServer.ConformanceTests/Support/SqlServerTestEnvironment.cs +++ b/dotnet/test/VectorData/SqlServer.ConformanceTests/Support/SqlServerTestEnvironment.cs @@ -1,7 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. using Microsoft.Extensions.Configuration; -using Microsoft.SemanticKernel.Connectors.SqlServer; namespace SqlServer.ConformanceTests.Support; @@ -17,7 +16,7 @@ internal static class SqlServerTestEnvironment .AddJsonFile(path: "testsettings.json", optional: true) .AddJsonFile(path: "testsettings.development.json", optional: true) .AddEnvironmentVariables() - .AddUserSecrets() + .AddUserSecrets() .Build(); return configuration.GetSection("SqlServer")["ConnectionString"]; diff --git a/dotnet/test/VectorData/VectorData.ConformanceTests/VectorSearch/VectorSearchDistanceFunctionComplianceTests.cs b/dotnet/test/VectorData/VectorData.ConformanceTests/VectorSearch/VectorSearchDistanceFunctionComplianceTests.cs index 3b13b06d9bbb..cfad7e424152 100644 --- a/dotnet/test/VectorData/VectorData.ConformanceTests/VectorSearch/VectorSearchDistanceFunctionComplianceTests.cs +++ b/dotnet/test/VectorData/VectorData.ConformanceTests/VectorSearch/VectorSearchDistanceFunctionComplianceTests.cs @@ -24,7 +24,7 @@ public virtual Task DotProductSimilarity() [ConditionalFact] public virtual Task NegativeDotProductSimilarity() - => this.SimpleSearch(DistanceFunction.NegativeDotProductSimilarity, -1, 1, 0, [1, 2, 0]); + => this.SimpleSearch(DistanceFunction.NegativeDotProductSimilarity, -1, 1, 0, [0, 2, 1]); [ConditionalFact] public virtual Task EuclideanDistance() diff --git a/dotnet/test/VectorData/Weaviate.ConformanceTests/VectorSearch/WeaviateVectorSearchDistanceFunctionComplianceTests.cs b/dotnet/test/VectorData/Weaviate.ConformanceTests/VectorSearch/WeaviateVectorSearchDistanceFunctionComplianceTests.cs index c20cc0cc81d3..a00674bc7790 100644 --- a/dotnet/test/VectorData/Weaviate.ConformanceTests/VectorSearch/WeaviateVectorSearchDistanceFunctionComplianceTests.cs +++ b/dotnet/test/VectorData/Weaviate.ConformanceTests/VectorSearch/WeaviateVectorSearchDistanceFunctionComplianceTests.cs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All rights reserved. -using Microsoft.Extensions.VectorData; using VectorData.ConformanceTests.VectorSearch; using Weaviate.ConformanceTests.Support; using Xunit; @@ -15,13 +14,6 @@ public class WeaviateVectorSearchDistanceFunctionComplianceTests_NamedVectors(We public override Task DotProductSimilarity() => Assert.ThrowsAsync(base.DotProductSimilarity); public override Task EuclideanDistance() => Assert.ThrowsAsync(base.EuclideanDistance); - - /// - /// Tests vector search using , computing -(u · v) as a distance metric per Weaviate's convention. - /// Expects scores of -1 (exact match), 1 (opposite), and 0 (orthogonal), sorted ascending ([0, 2, 1]), with lower scores indicating closer matches. - /// . - /// - public override Task NegativeDotProductSimilarity() => this.SimpleSearch(DistanceFunction.NegativeDotProductSimilarity, -1, 1, 0, [0, 2, 1]); } public class WeaviateVectorSearchDistanceFunctionComplianceTests_UnnamedVector(WeaviateDynamicDataModelNamedVectorsFixture fixture) @@ -32,11 +24,4 @@ public class WeaviateVectorSearchDistanceFunctionComplianceTests_UnnamedVector(W public override Task DotProductSimilarity() => Assert.ThrowsAsync(base.DotProductSimilarity); public override Task EuclideanDistance() => Assert.ThrowsAsync(base.EuclideanDistance); - - /// - /// Tests vector search using , computing -(u · v) as a distance metric per Weaviate's convention. - /// Expects scores of -1 (exact match), 1 (opposite), and 0 (orthogonal), sorted ascending ([0, 2, 1]), with lower scores indicating closer matches. - /// . - /// - public override Task NegativeDotProductSimilarity() => this.SimpleSearch(DistanceFunction.NegativeDotProductSimilarity, -1, 1, 0, [0, 2, 1]); }