Skip to content

Commit 5c0f006

Browse files
committed
Worked on Michael comments
1 parent 976d9e8 commit 5c0f006

File tree

4 files changed

+17
-52
lines changed

4 files changed

+17
-52
lines changed

docs/reference/elasticsearch/rest-apis/retrievers/linear-retriever.md

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ Combining `query` and `retrievers` is not supported.
3131
`normalizer` {applies_to}`stack: ga 9.1`
3232
: (Optional, String)
3333

34-
The normalizer to use when using the [multi-field query format](../retrievers.md#multi-field-query-format).
34+
The normalizer to use when combining results.
3535
See [normalizers](#linear-retriever-normalizers) for supported values.
3636
Required when `query` is specified.
37-
38-
When used with `retrievers`, the top-level `normalizer` serves as a default for any sub-retriever that doesn't specify its own normalizer. Per-retriever normalizers always take precedence over the top-level normalizer when both are specified.
37+
38+
When used with the [multi-field query format](../retrievers.md#multi-field-query-format) (`query` parameter), normalizes scores per [field grouping](../retrievers.md#multi-field-field-grouping).
39+
When used with `retrievers`, serves as the default normalizer for any sub-retriever that doesn't specify its own normalizer. Per-retriever normalizers always take precedence over the top-level normalizer.
3940

4041
::::{warning}
4142
Avoid using `none` as that will disable normalization and may bias the result set towards lexical matches.
@@ -76,9 +77,9 @@ Each entry in the `retrievers` array specifies the following parameters:
7677
`normalizer`
7778
: (Optional, String)
7879

79-
Specifies how the retrievers score will be normalized before applying the specified `weight`.
80+
Specifies how the retriever's score will be normalized before applying the specified `weight`.
8081
See [normalizers](#linear-retriever-normalizers) for supported values.
81-
Defaults to `none`.
82+
If not specified, uses the top-level `normalizer` or defaults to `none` if no top-level normalizer is set.
8283

8384
See also [this hybrid search example](retrievers-examples.md#retrievers-examples-linear-retriever) using a linear retriever on how to independently configure and apply normalizers to retrievers.
8485

@@ -96,7 +97,7 @@ The `linear` retriever supports the following normalizers:
9697
9798
## Example
9899
99-
This example of a hybrid search weights KNN results five times more heavily than BM25 results in the final ranking.
100+
This example of a hybrid search weights KNN results five times more heavily than BM25 results in the final ranking, with a top-level normalizer applied to all retrievers.
100101
101102
```console
102103
GET my_index/_search
@@ -107,35 +108,14 @@ GET my_index/_search
107108
{
108109
"retriever": {
109110
"knn": {
110-
...
111+
"field": "title_vector",
112+
"query_vector": [0.1, 0.2, 0.3],
113+
"k": 10,
114+
"num_candidates": 100
111115
}
112116
},
113117
"weight": 5 # KNN query weighted 5x
114118
},
115-
{
116-
"retriever": {
117-
"standard": {
118-
...
119-
}
120-
},
121-
"weight": 1.5 # BM25 query weighted 1.5x
122-
}
123-
]
124-
}
125-
}
126-
}
127-
```
128-
129-
### Using top-level normalizer
130-
131-
This example shows how to use a top-level normalizer that applies to all sub-retrievers:
132-
133-
```console
134-
GET my_index/_search
135-
{
136-
"retriever": {
137-
"linear": {
138-
"retrievers": [
139119
{
140120
"retriever": {
141121
"standard": {
@@ -146,18 +126,7 @@ GET my_index/_search
146126
}
147127
}
148128
},
149-
"weight": 1.0
150-
},
151-
{
152-
"retriever": {
153-
"knn": {
154-
"field": "title_vector",
155-
"query_vector": [0.1, 0.2, 0.3],
156-
"k": 10,
157-
"num_candidates": 100
158-
}
159-
},
160-
"weight": 2.0
129+
"weight": 1.5 # BM25 query weighted 1.5x
161130
}
162131
],
163132
"normalizer": "minmax"
@@ -166,6 +135,6 @@ GET my_index/_search
166135
}
167136
```
168137

169-
In this example, the `minmax` normalizer is applied to both the standard retriever and the kNN retriever. The top-level normalizer serves as a default that can be overridden by individual sub-retrievers. When using the multi-field query format, the top-level normalizer is applied to all generated inner retrievers.
138+
In this example, the `minmax` normalizer is applied to both the kNN retriever and the standard retriever. The top-level normalizer serves as a default that can be overridden by individual sub-retrievers. When using the multi-field query format, the top-level normalizer is applied to all generated inner retrievers.
170139

171140
See also [this hybrid search example](retrievers-examples.md#retrievers-examples-linear-retriever).

docs/reference/elasticsearch/rest-apis/retrievers/retrievers-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ GET /retrievers_example/_search
247247
}
248248
},
249249
"weight": 1.5,
250-
"normalizer": "minmax"
250+
"normalizer": "l2_norm"
251251
}
252252
],
253253
"rank_window_size": 10

x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ public LinearRetrieverBuilder(
178178
this.query = query;
179179
this.normalizer = normalizer;
180180
this.weights = weights;
181-
182-
// Initialize normalizers array
183181
this.normalizers = new ScoreNormalizer[normalizers.length];
184182
for (int i = 0; i < normalizers.length; i++) {
185183
this.normalizers[i] = resolveNormalizer(normalizers[i], normalizer);

x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/linear/LinearRetrieverBuilderParsingTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ protected LinearRetrieverBuilder createTestInstance() {
6969
new CompoundRetrieverBuilder.RetrieverSource(TestRetrieverBuilder.createRandomTestRetrieverBuilder(), null)
7070
);
7171
weights[i] = randomFloat();
72-
if (randomBoolean()) {
73-
normalizers[i] = randomScoreNormalizer();
74-
} else {
75-
normalizers[i] = null;
76-
}
72+
normalizers[i] = randomFrom(
73+
new ScoreNormalizer[] { null, MinMaxScoreNormalizer.INSTANCE, L2ScoreNormalizer.INSTANCE, IdentityScoreNormalizer.INSTANCE }
74+
);
7775
}
7876

7977
return new LinearRetrieverBuilder(innerRetrievers, fields, query, normalizer, rankWindowSize, weights, normalizers);

0 commit comments

Comments
 (0)