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: solutions/search/retrievers-examples.md
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -418,18 +418,25 @@ stack: ga 9.1
418
418
419
419
There's an even simpler way to execute a hybrid search though: We can use the [multi-field query format](elasticsearch://reference/elasticsearch/rest-apis/retrievers.md#multi-field-query-format), which allows us to query multiple fields without explicitly specifying inner retrievers.
420
420
421
-
The following example uses the multi-field query format to query the `text` and `text_semantic` fields.
421
+
One of the major challenges with hybrid search is normalizing the scores across matches on all field types.
422
422
Scores from [`text`](elasticsearch://reference/elasticsearch/mapping-reference/text.md) and [`semantic_text`](elasticsearch://reference/elasticsearch/mapping-reference/semantic-text.md) fields don't always fall in the same range, so we need to normalize the ranks across matches on these fields to generate a result set.
423
423
For example, BM25 scores from `text` fields are unbounded, while vector similarity scores from `text_embedding` models are bounded between [0, 1].
424
424
The multi-field query format [handles this normalization for us automatically](elasticsearch://reference/elasticsearch/rest-apis/retrievers.md#multi-field-field-grouping).
425
425
426
+
The following example uses the multi-field query format to query every field specified in the `index.query.default_field` index setting, which is set to `*` by default.
427
+
This default value will cause the retriever to query every field that either:
428
+
429
+
- Supports term queries, such as `keyword` and `text` fields
430
+
- Is a `semantic_text` field
431
+
432
+
In this example, that would translate to the `text`, `text_semantic`, `year`, `topic`, and `timestamp` fields.
433
+
426
434
```console
427
435
GET /retrievers_example/_search
428
436
{
429
437
"retriever": {
430
438
"rrf": {
431
-
"query": "artificial intelligence",
432
-
"fields": ["text", "text_semantic"]
439
+
"query": "artificial intelligence"
433
440
}
434
441
}
435
442
}
@@ -477,26 +484,25 @@ This returns the following response based on the final rrf score for each result
477
484
478
485
::::
479
486
480
-
We don't even need to specify the `fields` parameter when using the multi-field query format.
481
-
If we omit it, the retriever will automatically query fields specified in the `index.query.default_field` index setting, which is set to `*` by default.
482
-
This default value will cause the retriever to query every field that either:
483
-
484
-
- Supports term queries, such as `keyword` and `text` fields
485
-
- Is a `semantic_text` field
486
-
487
-
In this example, that would translate to the `text`, `text_semantic`, `year`, `topic`, and `timestamp` fields.
487
+
We can also use the `fields` parameter to explicitly specify the fields to query.
488
+
The following example uses the multi-field query format to query the `text` and `text_semantic` fields.
488
489
489
490
```console
490
491
GET /retrievers_example/_search
491
492
{
492
493
"retriever": {
493
494
"rrf": {
494
-
"query": "artificial intelligence"
495
+
"query": "artificial intelligence",
496
+
"fields": ["text", "text_semantic"]
495
497
}
496
498
}
497
499
}
498
500
```
499
501
502
+
::::{note}
503
+
The `fields` parameter also accepts [wildcard field patterns](elasticsearch://reference/elasticsearch/rest-apis/retrievers.md#multi-field-wildcard-field-patterns).
504
+
::::
505
+
500
506
This returns the following response based on the final rrf score for each result.
501
507
502
508
::::{dropdown} Example response
@@ -539,8 +545,6 @@ This returns the following response based on the final rrf score for each result
539
545
540
546
::::
541
547
542
-
See [wildcard field patterns](elasticsearch://reference/elasticsearch/rest-apis/retrievers.md#multi-field-wildcard-field-patterns) for more information about wildcard resolution.
543
-
544
548
545
549
## Example: Linear retriever with the multi-field query format [retrievers-examples-linear-multi-field-query-format]
0 commit comments