You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/elasticsearch/rest-apis/retrievers/retrievers-examples.md
+51-1Lines changed: 51 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,9 @@ First, let’s examine how to combine two different types of queries: a `kNN` qu
113
113
While these queries may produce scores in different ranges, we can use Reciprocal Rank Fusion (`rrf`) to combine the results and generate a merged final result list.
114
114
115
115
To implement this in the retriever framework, we start with the top-level element: our `rrf` retriever.
116
-
This retriever operates on top of two other retrievers: a `knn` retriever and a `standard` retriever. Our query structure would look like this:
116
+
This retriever operates on top of two other retrievers: a `knn` retriever and a `standard` retriever.
117
+
We can specify weights to adjust the influence of each retriever on the final ranking.
118
+
In this example, we're giving the `standard` retriever twice the influence of the `knn` retriever:
117
119
118
120
```console
119
121
GET /retrievers_example/_search
@@ -195,6 +197,54 @@ This returns the following response based on the final rrf score for each result
195
197
::::
196
198
197
199
200
+
### Using the expanded format with weights {applies_to}`stack: ga 9.2`
201
+
202
+
The same query can be written using the expanded format, which allows you to specify custom weights to adjust the influence of each retriever on the final ranking.
203
+
In this example, we're giving the `standard` retriever twice the influence of the `knn` retriever:
204
+
205
+
```console
206
+
GET /retrievers_example/_search
207
+
{
208
+
"retriever": {
209
+
"rrf": {
210
+
"retrievers": [
211
+
{
212
+
"retriever": {
213
+
"standard": {
214
+
"query": {
215
+
"query_string": {
216
+
"query": "(information retrieval) OR (artificial intelligence)",
217
+
"default_field": "text"
218
+
}
219
+
}
220
+
}
221
+
},
222
+
"weight": 2.0
223
+
},
224
+
{
225
+
"retriever": {
226
+
"knn": {
227
+
"field": "vector",
228
+
"query_vector": [
229
+
0.23,
230
+
0.67,
231
+
0.89
232
+
],
233
+
"k": 3,
234
+
"num_candidates": 5
235
+
}
236
+
},
237
+
"weight": 1.0
238
+
}
239
+
],
240
+
"rank_window_size": 10,
241
+
"rank_constant": 1
242
+
}
243
+
},
244
+
"_source": false
245
+
}
246
+
```
247
+
198
248
199
249
## Example: Hybrid search with linear retriever [retrievers-examples-linear-retriever]
Copy file name to clipboardExpand all lines: docs/reference/elasticsearch/rest-apis/retrievers/rrf-retriever.md
+153-2Lines changed: 153 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ applies_to:
6
6
7
7
# RRF retriever [rrf-retriever]
8
8
9
-
An [RRF](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md) retriever returns top documents based on the RRF formula, equally weighting two or more child retrievers.
9
+
An [RRF](/reference/elasticsearch/rest-apis/reciprocal-rank-fusion.md) retriever returns top documents based on the RRF formula, combining two or more child retrievers.
10
10
Reciprocal rank fusion (RRF) is a method for combining multiple result sets with different relevance indicators into a single result set.
11
11
12
12
@@ -32,7 +32,13 @@ Combining `query` and `retrievers` is not supported.
32
32
: (Optional, array of retriever objects)
33
33
34
34
A list of child retrievers to specify which sets of returned top documents will have the RRF formula applied to them.
35
-
Each child retriever carries an equal weight as part of the RRF formula. Two or more child retrievers are required.
35
+
Each retriever can optionally include a weight to adjust its influence on the final ranking. {applies_to}`stack: ga 9.2`
36
+
37
+
When weights are specified, the final RRF score is calculated as:
where `rrf_score_i` is the RRF score for document from retriever `i`, and `weight_i` is the weight for that retriever.
36
42
37
43
`rank_constant`
38
44
: (Optional, integer)
@@ -53,6 +59,82 @@ Combining `query` and `retrievers` is not supported.
53
59
54
60
Applies the specified [boolean query filter](/reference/query-languages/query-dsl/query-dsl-bool-query.md) to all of the specified sub-retrievers, according to each retriever’s specifications.
55
61
62
+
Each entry in the `retrievers` array can be specified using the direct format or the wrapped format. {applies_to}`stack: ga 9.2`
63
+
64
+
**Direct format** (default weight of `1.0`):
65
+
```json
66
+
{
67
+
"rrf": {
68
+
"retrievers": [
69
+
{
70
+
"standard": {
71
+
"query": {
72
+
"multi_match": {
73
+
"query": "search text",
74
+
"fields": ["field1", "field2"]
75
+
}
76
+
}
77
+
}
78
+
},
79
+
{
80
+
"knn": {
81
+
"field": "vector",
82
+
"query_vector": [1, 2, 3],
83
+
"k": 10,
84
+
"num_candidates": 50
85
+
}
86
+
}
87
+
]
88
+
}
89
+
}
90
+
```
91
+
92
+
**Wrapped format with custom weights** {applies_to}`stack: ga 9.2`:
93
+
```json
94
+
{
95
+
"rrf": {
96
+
"retrievers": [
97
+
{
98
+
"retriever": {
99
+
"standard": {
100
+
"query": {
101
+
"multi_match": {
102
+
"query": "search text",
103
+
"fields": ["field1", "field2"]
104
+
}
105
+
}
106
+
}
107
+
},
108
+
"weight": 2.0
109
+
},
110
+
{
111
+
"retriever": {
112
+
"knn": {
113
+
"field": "vector",
114
+
"query_vector": [1, 2, 3],
115
+
"k": 10,
116
+
"num_candidates": 50
117
+
}
118
+
},
119
+
"weight": 1.0
120
+
}
121
+
]
122
+
}
123
+
}
124
+
```
125
+
126
+
In the wrapped format:
127
+
128
+
`retriever`
129
+
: (Required, a retriever object)
130
+
131
+
Specifies a child retriever. Any valid retriever type can be used (e.g., `standard`, `knn`, `text_similarity_reranker`, etc.).
132
+
133
+
`weight` {applies_to}`stack: ga 9.2`
134
+
: (Optional, float)
135
+
136
+
The weight that each score of this retriever's top docs will be multiplied in the RRF formula. Higher values increase this retriever's influence on the final ranking. Must be non-negative. Defaults to `1.0`.
0 commit comments