Skip to content

Add $rankFusion stage and $sigmoid expression - #32

Merged
GromNaN merged 1 commit into
mongodb:mainfrom
GromNaN:phplib-1624-rank-fusion-sigmoid
Apr 29, 2026
Merged

GromNaN merged 1 commit into
mongodb:mainfrom
GromNaN:phplib-1624-rank-fusion-sigmoid

Conversation

@GromNaN

@GromNaN GromNaN commented Apr 29, 2026

Copy link
Copy Markdown
Member

Summary

  • Add $rankFusion aggregation stage definition (MongoDB 8.1+, featureFlagRankFusionBasic)
  • Add $sigmoid expression definition (MongoDB 8.1+, featureFlagRankFusionBasic)

Both operators are introduced as part of the Vector Search Hybrid Scoring milestone (SERVER-97919 / featureFlagRankFusionBasic).

$rankFusion

Combines multiple pipelines using rank-based fusion to create hybrid search results. Accepts:

  • input.pipelines: Map from name to ranked input pipeline
  • combination.weights (optional): Map from pipeline name to weight values
  • scoreDetails (optional, default false): Include detailed scoring information

$sigmoid

Returns the sigmoid of a numeric value: 1 / (1 + e^(-x)). Maps any numeric input to a value between 0 and 1.

References

Copilot AI review requested due to automatic review settings April 29, 2026 12:22

Copilot AI left a comment

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.

Pull request overview

Adds new MongoDB 8.1 operator definitions to the repository’s YAML-based operator catalog to support Vector Search Hybrid Scoring (featureFlagRankFusionBasic).

Changes:

  • Added $rankFusion aggregation stage definition, including an example pipeline test.
  • Added $sigmoid aggregation expression definition, including an example pipeline test + schema.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
definitions/stage/rankFusion.yaml Introduces the $rankFusion stage spec (v8.1+) with arguments and an example usage.
definitions/expression/sigmoid.yaml Introduces the $sigmoid expression spec (v8.1+) with argument typing and an example usage.

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

Copilot AI review requested due to automatic review settings April 29, 2026 12:57
These operators are introduced in MongoDB 8.1 as part of the
featureFlagRankFusionBasic milestone (SERVER-97919).

- $rankFusion: Aggregation stage that combines multiple pipelines
  using rank-based fusion to create hybrid search results.
- $sigmoid: Expression that returns 1 / (1 + e^(-x)), mapping
  any numeric input to a value between 0 and 1.

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


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

scoreDetails: true
- $addFields:
scoreDetails:
$meta: searchScoreDetails

Copilot AI Apr 29, 2026

Copy link

Choose a reason for hiding this comment

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

In the example pipeline, the $meta keyword is set to searchScoreDetails, but in this repo $scoreFusion uses $meta: scoreDetails when scoreDetails: true is enabled. If $rankFusion also exposes its details via the scoreDetails meta keyword (as the option name suggests), this example will be incorrect/misleading—please confirm against the server behavior/docs and align the meta keyword (and/or field name) accordingly.

Suggested change
$meta: searchScoreDetails
$meta: scoreDetails

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copied from https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/#examples

const pipeline = [
  {
    $rankFusion: { 
      input: {
        pipelines: {
          searchPlot: [
            {
              $search: {
                index: "default",
                text: { query: "space", path: "plot"}
              }
            }
          ],
          searchGenre: [
            {
              $search: {
                index: "default",
                text: { query: "adventure", path: "genres" }
              }
            }
          ] 
        }
      },
      combination: { weights: {searchPlot: 0.6, searchGenre: 0.4} },
      scoreDetails: true                  
    }
  },
  { $addFields: { scoreDetails: { $meta: "searchScoreDetails" } } }
];
          
const cursor = collection.aggregate(pipeline);  
return cursor;

arguments:
- name: input
type:
- object

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This should be expressed with a more advanced type system.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

#33

@GromNaN
GromNaN merged commit b614057 into mongodb:main Apr 29, 2026
3 checks passed
@GromNaN
GromNaN deleted the phplib-1624-rank-fusion-sigmoid branch April 29, 2026 13:39
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.

3 participants