Skip to content

CSHARP-5931: Add builder support for $scoreFusion stage#1976

Open
adelinowona wants to merge 3 commits intomongodb:mainfrom
adelinowona:csharp5931
Open

CSHARP-5931: Add builder support for $scoreFusion stage#1976
adelinowona wants to merge 3 commits intomongodb:mainfrom
adelinowona:csharp5931

Conversation

@adelinowona
Copy link
Copy Markdown
Contributor

No description provided.

@adelinowona adelinowona requested a review from a team as a code owner April 28, 2026 18:16
Copilot AI review requested due to automatic review settings April 28, 2026 18:16
@adelinowona adelinowona added the feature Adds new user-facing functionality. label Apr 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds C# driver support for building and executing the $scoreFusion aggregation stage, including options/metadata types and test coverage.

Changes:

  • Introduces PipelineStageDefinitionBuilder.ScoreFusion (named, auto-named, and weighted tuple overloads) plus shared helpers.
  • Adds public API surface for fluent aggregation and pipeline builders (IAggregateFluentExtensions, PipelineDefinitionBuilder) and new options/metadata types.
  • Adds unit and integration tests and gates integration coverage behind a new server Feature.ScoreFusionStage.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/MongoDB.Driver.Tests/PipelineStageDefinitionBuilderTests.cs Adds rendering/validation unit tests for $scoreFusion stage builder.
tests/MongoDB.Driver.Tests/PipelineDefinitionBuilderTests.cs Adds null-guard tests for pipeline extension methods (pipeline.ScoreFusion(...)).
tests/MongoDB.Driver.Tests/AggregateScoreFusionTests.cs Adds integration tests for $scoreFusion end-to-end behavior and metadata projection.
src/MongoDB.Driver/ScoreFusionScoreDetails.cs Adds POCO for scoreDetails metadata returned by $scoreFusion.
src/MongoDB.Driver/ScoreFusionOptions.cs Adds normalization/combination enums and ScoreFusionOptions<T> configuration object.
src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs Implements $scoreFusion stage builder and refactors shared named/auto-named pipeline helpers.
src/MongoDB.Driver/PipelineDefinitionBuilder.cs Adds pipeline extension methods to append $scoreFusion.
src/MongoDB.Driver/IAggregateFluentExtensions.cs Adds IAggregateFluent extensions for $scoreFusion.
src/MongoDB.Driver/Core/Misc/Feature.cs Adds Feature.ScoreFusionStage to gate integration tests by server wire version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/MongoDB.Driver.Tests/AggregateScoreFusionTests.cs
Comment thread src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs
Comment thread src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs Outdated
Comment thread src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs
Comment thread src/MongoDB.Driver/ScoreFusionScoreDetails.cs
Comment thread tests/MongoDB.Driver.Tests/AggregateScoreFusionTests.cs
@adelinowona adelinowona changed the title CSHARP: Add builder support for $scoreFusion stage CSHARP-5931: Add builder support for $scoreFusion stage Apr 28, 2026
Copy link
Copy Markdown
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Looks good overall.
Please change the Jira ticket title to match the PR title.

Comment thread src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs
Comment thread src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs Outdated
throw new ArgumentException("Value cannot be an empty collection.", nameof(pipelines));
}

if (pipelines.Any(pipeline => pipeline == null))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe validate once in BuildAutoNamedPipelineMap ?

Copy link
Copy Markdown
Contributor Author

@adelinowona adelinowona May 4, 2026

Choose a reason for hiding this comment

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

Done. Moved the null-pipeline check into BuildAutoNamedPipelineMap and BuildAutoNamedPipelineMapWithWeights as a pre-check before building the map. This also benefits the RankFusion overloads that share these helpers.

Note: it'll be behavioral breaking change for RankFusion as the error checking is now done client-side instead of being deferred to the server.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's fine to fail earlier in this case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just found Ensure.IsNotNullAndDoesNotContainAnyNulls

Comment thread src/MongoDB.Driver/ScoreFusionOptions.cs
Comment thread src/MongoDB.Driver/ScoreFusionOptions.cs
Comment thread tests/MongoDB.Driver.Tests/PipelineDefinitionBuilderTests.cs
Comment thread src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs
Copy link
Copy Markdown
Contributor

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

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

LGTM

/// <returns>The fluent aggregate interface.</returns>
public static IAggregateFluent<TNewResult> ScoreFusion<TResult, TNewResult>(
this IAggregateFluent<TResult> aggregate,
Dictionary<string, PipelineDefinition<TResult, TNewResult>> pipelines,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we use IReadOnlyDictionary<> in public API instead of Dictionary<>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably but changing this would require updating RankFusion too for consistency, which would be a breaking change there. We could defer this to a major release where both can be updated together? WDYT @BorisDog @ajcvickers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good idea, and major release sgtm.

@adelinowona adelinowona requested review from BorisDog and sanych-sun May 4, 2026 18:55
Copy link
Copy Markdown
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

LGTM + minor comment about Ensure.IsNotNullAndDoesNotContainAnyNulls

/// <returns>The fluent aggregate interface.</returns>
public static IAggregateFluent<TNewResult> ScoreFusion<TResult, TNewResult>(
this IAggregateFluent<TResult> aggregate,
Dictionary<string, PipelineDefinition<TResult, TNewResult>> pipelines,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good idea, and major release sgtm.

throw new ArgumentException("Value cannot be an empty collection.", nameof(pipelines));
}

if (pipelines.Any(pipeline => pipeline == null))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's fine to fail earlier in this case.

throw new ArgumentException("Value cannot be an empty collection.", nameof(pipelines));
}

if (pipelines.Any(pipeline => pipeline == null))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just found Ensure.IsNotNullAndDoesNotContainAnyNulls

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

Labels

feature Adds new user-facing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants