Skip to content

.Net: Fixed sorting for negative DOT product#13071

Merged
westey-m merged 3 commits into
microsoft:mainfrom
yorek:main
Sep 10, 2025
Merged

.Net: Fixed sorting for negative DOT product#13071
westey-m merged 3 commits into
microsoft:mainfrom
yorek:main

Conversation

@yorek

@yorek yorek commented Sep 4, 2025

Copy link
Copy Markdown

Motivation and Context

When using negative dot product scoring, the more negative the value, the closer the vector is to the query vector.

Description

Fixed the sorting used for negative dot product distance calculations

Contribution Checklist

@yorek yorek requested a review from a team as a code owner September 4, 2025 21:03
@moonbox3 moonbox3 added the .NET Issue or Pull requests regarding .NET code label Sep 4, 2025
@github-actions github-actions Bot changed the title Fixed sorting for negative DOT product .Net: Fixed sorting for negative DOT product Sep 4, 2025
@westey-m

westey-m commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

Hi @yorek, thanks for the contribution, it makes sense. Do you mind also updating the integration test? It is also incorrect.
See VectorSearchDistanceFunctionComplianceTests.NegativeDotProductSimilarity, which is has an expectation defined that results are returned with least similar first, but should be most similar first, i.e. Same, Orthogonal, Opposite, instead of Opposite, Orthogonal, Same.

It looks like the only other DB that uses this test is Weaviate, which has been overridden to correctly test the order.

// Incorrect order:
this.SimpleSearch(DistanceFunction.NegativeDotProductSimilarity, -1, 1, 0, [1, 2, 0]);

// Correct order:
this.SimpleSearch(DistanceFunction.NegativeDotProductSimilarity, -1, 1, 0, [0, 2, 1]);

@rogerbarreto rogerbarreto added the PR: feedback to address Waiting for PR owner to address comments/questions label Sep 10, 2025
@westey-m westey-m removed the PR: feedback to address Waiting for PR owner to address comments/questions label Sep 10, 2025
@westey-m westey-m enabled auto-merge September 10, 2025 10:33
@westey-m westey-m added this pull request to the merge queue Sep 10, 2025
Merged via the queue into microsoft:main with commit 27e8457 Sep 10, 2025
19 checks passed
@yorek

yorek commented Sep 10, 2025

Copy link
Copy Markdown
Author

Thanks everyone for the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants