Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Jul 27, 2025

  • Replace the 3rd parameter to EF.Functions.VectorDistance() to accept a new VectorDistanceOptions type with various options, rather than the previous DistanceFunction only.
  • Collapse EF.Functions.VectorDistance() overloads together using optional parameters, with the new C# support for optional parameters in expression tree method invocations.
  • Reorganize and cleanup tests

Closes #36447

/cc @artl93

@roji roji mentioned this pull request Jul 27, 2025
24 tasks
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore.Cosmos.Extensions;
namespace Microsoft.EntityFrameworkCore;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this namespace change, which aligns our extensions class with the other providers - users shouldn't need to use a special namespace to get these extensions. While technically a breaking change, there were almost no methods here before 10 anyway (and none before 9), and it's quite unlikely to actually affect anyone...

if (options is not null)
{
if (arguments[4] is not SqlConstantExpression { Value: DistanceFunction distanceFunction })
// If the options are provided but not useBruteForce, we need to explicitly specify the default for the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat unfortunate - we have to explicitly provide the default (false) when the options are specified and the user explicitly passes null to useBruteForce. But seems fine.

@roji roji force-pushed the CosmosVectorDistance branch from 0baea29 to 77a388e Compare July 27, 2025 18:18
@roji roji marked this pull request as ready for review July 27, 2025 20:34
@roji roji requested a review from a team as a code owner July 27, 2025 20:34
@roji roji force-pushed the CosmosVectorDistance branch from 77a388e to fb76bde Compare July 28, 2025 21:07
@roji roji enabled auto-merge (squash) July 28, 2025 21:07
@roji
Copy link
Member Author

roji commented Jul 28, 2025

Test failures are SQL Server flakiness, merging.

@roji roji disabled auto-merge July 28, 2025 22:28
@roji roji merged commit b53641e into dotnet:main Jul 28, 2025
5 of 7 checks passed
@roji roji deleted the CosmosVectorDistance branch July 28, 2025 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cosmos: support extra options to VectorDistance()

2 participants