Skip to content

Commit 5ec46b9

Browse files
alcaeusKræn HansenkraenhansenGromNaN
authored
PHPLIB-1736: Add $scoreFusion stage (#1822)
* Add generator config for scoreFusion stage * Ran generate * Update builder test * Update tests/Builder/Stage/ScoreFusionStageTest.php Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net> * Fix missing use * Add test for scoreFusion in fluent factory --------- Co-authored-by: Kræn Hansen <kraen.hansen@mongodb.com> Co-authored-by: Kræn Hansen <mail@kraenhansen.dk> Co-authored-by: Jérôme Tamarelle <jerome@tamarelle.net>
1 parent d6b36f8 commit 5ec46b9

File tree

6 files changed

+406
-0
lines changed

6 files changed

+406
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# yaml-language-server: $schema=../schema.json
2+
name: $scoreFusion
3+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/'
4+
type:
5+
- stage
6+
encode: object
7+
description: |
8+
Combines multiple pipelines using relative score fusion to create hybrid search results.
9+
arguments:
10+
-
11+
name: input
12+
type:
13+
- object
14+
description: |
15+
An object with the following required fields:
16+
- input.pipelines: Map from name to input pipeline. Each pipeline must be operating on the same collection. Minimum of one pipeline.
17+
- input.normalization: Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler.
18+
-
19+
name: combination
20+
optional: true
21+
type:
22+
- object
23+
description: |
24+
An object with the following optional fields:
25+
- combination.weights: Map from pipeline name to numbers (non-negative). If unspecified, default weight is 1 for each pipeline.
26+
- combination.method: Specifies method for combining scores. Value can be avg or expression. Default is avg.
27+
- combination.expression: This is the custom expression that is used when combination.method is set to expression.
28+
-
29+
name: scoreDetails
30+
type:
31+
- bool
32+
default: false
33+
description: Set to true to include detailed scoring information.
34+
tests:
35+
-
36+
name: 'Example'
37+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/#examples'
38+
pipeline:
39+
-
40+
$scoreFusion:
41+
input:
42+
pipelines:
43+
searchOne:
44+
-
45+
$vectorSearch:
46+
index: 'vector_index'
47+
path: 'plot_embedding'
48+
queryVector: [-0.0016261312, -0.028070757, -0.011342932]
49+
numCandidates: 150
50+
limit: 10
51+
searchTwo:
52+
-
53+
$search:
54+
index: '<INDEX_NAME>'
55+
text:
56+
query: '<QUERY_TERM>'
57+
path: '<FIELD_NAME>'
58+
normalization: 'sigmoid'
59+
combination:
60+
method: 'expression'
61+
expression:
62+
$sum:
63+
-
64+
$multiply:
65+
- '$$searchOne'
66+
- 10
67+
- '$$searchTwo'
68+
scoreDetails: true
69+
-
70+
$project:
71+
_id: 1
72+
title: 1
73+
plot: 1
74+
scoreDetails:
75+
$meta: 'scoreDetails'
76+
-
77+
$limit: 20

src/Builder/Stage/FactoryTrait.php

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Stage/FluentFactoryTrait.php

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Builder/Stage/ScoreFusionStage.php

Lines changed: 68 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Builder/Stage/Pipelines.php

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)