-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-1736: Add $scoreFusion stage
#1811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2.x
Are you sure you want to change the base?
Changes from 2 commits
eece40e
b503fa1
dc813d1
2439191
bef5a4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # yaml-language-server: $schema=../schema.json | ||
| name: $scoreFusion | ||
| link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/' | ||
| type: | ||
| - stage | ||
| encode: object | ||
| description: | | ||
| Combines multiple pipelines using relative score fusion to create hybrid search results. | ||
| arguments: | ||
| - | ||
| name: input | ||
| type: | ||
| - object | ||
| description: | | ||
| An object with the following required fields: | ||
| - input.pipelines: Map from name to input pipeline. Each pipeline must be operating on the same collection. Minimum of one pipeline. | ||
| - input.normalization: Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler. | ||
| - | ||
| name: combination | ||
| optional: true | ||
| type: | ||
| - object | ||
| description: | | ||
| An object with the following optional fields: | ||
| - combination.weights: Map from pipeline name to numbers (non-negative). If unspecified, default weight is 1 for each pipeline. | ||
| - combination.method: Specifies method for combining scores. Value can be avg or expression. Default is avg. | ||
| - combination.expression: This is the custom expression that is used when combination.method is set to expression. | ||
| - | ||
| name: scoreDetails | ||
| type: | ||
| - bool | ||
| default: false | ||
| description: Set to true to include detailed scoring information. | ||
| tests: | ||
| - | ||
| name: 'Example' | ||
| link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/#examples' | ||
| pipeline: | ||
| - | ||
| $scoreFusion: | ||
| input: | ||
| pipelines: | ||
| searchOne: | ||
| - | ||
| $vectorSearch: | ||
| index: 'vector_index' | ||
| path: 'plot_embedding' | ||
| queryVector: [-0.0016261312, -0.028070757, -0.011342932] | ||
| numCandidates: 150 | ||
| limit: 10 | ||
| searchTwo: | ||
| - | ||
| $search: | ||
| index: '<INDEX_NAME>' | ||
| text: | ||
| query: '<QUERY_TERM>' | ||
| path: '<FIELD_NAME>' | ||
| normalization: 'sigmoid' | ||
| combination: | ||
| method: 'expression' | ||
| expression: | ||
| $sum: | ||
| - | ||
| $multiply: | ||
| - '$$searchOne' | ||
| - 10 | ||
| - '$$searchTwo' | ||
| scoreDetails: true | ||
| - | ||
| $project: | ||
| _id: 1 | ||
| title: 1 | ||
| plot: 1 | ||
| scoreDetails: | ||
| $meta: 'scoreDetails' | ||
| - | ||
| $limit: 20 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace MongoDB\Tests\Builder\Stage; | ||
|
|
||
| use MongoDB\Builder\Pipeline; | ||
| use MongoDB\Tests\Builder\PipelineTestCase; | ||
|
|
||
| /** | ||
| * Test $scoreFusion stage | ||
| */ | ||
| class ScoreFusionStageTest extends PipelineTestCase | ||
| { | ||
| public function testExample(): void | ||
| { | ||
| $pipeline = new Pipeline(); | ||
|
|
||
| $this->assertSamePipeline(Pipelines::ScoreFusionExample, $pipeline); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll bet 20 Bonusly points that the Copilot agent can generate the PHP aggregation on the first try.
Thank you for contributing the PHP library.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a positive comment.
In fact, this file is generated, but it is a frame in which we have to write the code with the PHP aggregation builder. This allows us to validate the functioning of the aggregation builder and check the DX.
The tests/Builder/Stage has many examples of this.
The translation logic is very systematic, which means that an AI agent can easily guess what to write based on the expected extended JSON.
This is a suggestion that you complete this piece of code, but we can also take care of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit 🤞