-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cluster-apis
- Loading branch information
Showing
14 changed files
with
380 additions
and
7 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
.github/vale/styles/OpenSearch/SubstitutionErroCaseSensitive.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
extends: substitution | ||
message: "Use '%s' instead of '%s'. Note the correct capitalization." | ||
ignorecase: false | ||
level: error | ||
action: | ||
name: replace | ||
swap: | ||
'Retrieval-Augmented Generation': retrieval-augmented generation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
layout: default | ||
title: Template | ||
parent: Specialized queries | ||
nav_order: 70 | ||
--- | ||
|
||
# Template query | ||
Introduced 2.19 | ||
{: .label .label-purple } | ||
|
||
Use a `template` query to create search queries that contain placeholder variables. Placeholders are specified using the `"${variable_name}"` syntax (note that the variables must be enclosed in quotation marks). When you submit a search request, these placeholders remain unresolved until they are processed by search request processors. This approach is particularly useful when your initial search request contains data that needs to be transformed or generated at runtime. | ||
|
||
For example, you might use a template query when working with the [ml_inference search request processor]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/ml-inference-search-request/), which converts text input into vector embeddings during the search process. The processor will replace the placeholders with the generated values before the final query is executed. | ||
|
||
For a complete example, see [Query rewriting using template queries]({{site.url}}{{site.baseurl}}/search-plugins/search-relevance/template-query/). | ||
|
||
## Example | ||
|
||
The following example shows a template k-NN query with a `"vector": "${text_embedding}"` placeholder. The placeholder `"${text_embedding}"` will be replaced with embeddings generated by the `ml_inference` search request processor from the `text` input field: | ||
|
||
```json | ||
GET /template-knn-index/_search?search_pipeline=my_knn_pipeline | ||
{ | ||
"query": { | ||
"template": { | ||
"knn": { | ||
"text_embedding": { | ||
"vector": "${text_embedding}", // Placeholder for the vector field | ||
"k": 2 | ||
} | ||
} | ||
} | ||
}, | ||
"ext": { | ||
"ml_inference": { | ||
"text": "sneakers" // Input text for the ml_inference processor | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
To use a template query with a search request processor, you need to configure a search pipeline. The following is an example configuration for the `ml_inference` search request processor. The `input_map` maps document fields to model inputs. In this example, the `ext.ml_inference.text` source field in a document is mapped to the `inputText` field---the expected input field for the model. The `output_map` maps model outputs to document fields. In this example, the `embedding` output field from the model is mapped to the `text_embedding` destination field in your document: | ||
|
||
```json | ||
PUT /_search/pipeline/my_knn_pipeline | ||
{ | ||
"request_processors": [ | ||
{ | ||
"ml_inference": { | ||
"model_id": "Sz-wFZQBUpPSu0bsJTBG", | ||
"input_map": [ | ||
{ | ||
"inputText": "ext.ml_inference.text" // Map input text from the request | ||
} | ||
], | ||
"output_map": [ | ||
{ | ||
"text_embedding": "embedding" // Map output to the placeholder | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
After the `ml_inference` search request processor runs, the search request is rewritten. The `vector` field contains the embeddings generated by the processor, and the `text_embedding` field contains the processor output: | ||
|
||
```json | ||
GET /template-knn-1/_search | ||
{ | ||
"query": { | ||
"template": { | ||
"knn": { | ||
"text_embedding": { | ||
"vector": [0.6328125, 0.26953125, ...], | ||
"k": 2 | ||
} | ||
} | ||
} | ||
}, | ||
"ext": { | ||
"ml_inference": { | ||
"text": "sneakers", | ||
"text_embedding": [0.6328125, 0.26953125, ...] | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
## Limitations | ||
|
||
Template queries require at least one search request processor in order to resolve placeholders. Search request processors must be configured to produce the variables expected in the pipeline. | ||
|
||
## Next steps | ||
|
||
- For a complete example, see [Template queries]({{site.url}}{{site.baseurl}}/search-plugins/search-relevance/template-query/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
layout: default | ||
title: Query rewriting | ||
parent: Search relevance | ||
has_children: true | ||
nav_order: 70 | ||
has_toc: false | ||
--- | ||
|
||
# Query rewriting | ||
|
||
Query rewriting is the process of transforming or modifying a user query before it is executed. The goal of query rewriting is to improve search accuracy, relevance, or performance by addressing issues such as misspellings, synonyms, ambiguous terms, or inefficient query structure. Query rewriting is commonly used in search systems to enhance the quality of search results. | ||
|
||
You can perform query rewriting in OpenSearch using the following features: | ||
|
||
- [Template queries]({{site.url}}{{site.baseurl}}/search-plugins/search-relevance/template-query/) | ||
|
||
- [Querqy]({{site.url}}{{site.baseurl}}/search-plugins/querqy/) |
Oops, something went wrong.