-
Notifications
You must be signed in to change notification settings - Fork 616
Updating QueryPlanningTool documentation #11133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting your PR. The PR states are In progress (or Draft) -> Tech review -> Doc review -> Editorial review -> Merged. Before you submit your PR for doc review, make sure the content is technically accurate. If you need help finding a tech reviewer, tag a maintainer. When you're ready for doc review, tag the assignee of this PR. The doc reviewer may push edits to the PR directly or leave comments and editorial suggestions for you to address (let us know in a comment if you have a preference). The doc reviewer will arrange for an editorial review. |
} | ||
``` | ||
|
||
Each `search_templates` array entry must have a `template_id` and `template_description`. The LLM will use the description as additional context to help it choose the best template to use when generating an OpenSearch DSL query based on the uses provided `query_text`. If the LLM determines that the provided search templates are not applicable to the given `query_text`, then the LLM will use a default match all query search template. It is important to note that the LLM will not directly render the final Opensearch DSL query with the chosen template, but rather use the template source as additional context to help it form the query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each `search_templates` array entry must have a `template_id` and `template_description`. The LLM will use the description as additional context to help it choose the best template to use when generating an OpenSearch DSL query based on the uses provided `query_text`. If the LLM determines that the provided search templates are not applicable to the given `query_text`, then the LLM will use a default match all query search template. It is important to note that the LLM will not directly render the final Opensearch DSL query with the chosen template, but rather use the template source as additional context to help it form the query. | |
Each `search_templates` list entry must have a `template_id` and `template_description`. The LLM will use the description as additional context to help it choose the best template to use when generating an OpenSearch DSL query based on the uses provided `query_text`. If the LLM determines that the provided search templates are not applicable to the given `query_text`, then the LLM will use a default match all query search template. It is important to note that the LLM will not directly render the final Opensearch DSL query with the chosen template, but rather use the template source as additional context to help it form the query. |
} | ||
``` | ||
|
||
Each `search_templates` array entry must have a `template_id` and `template_description`. The LLM will use the description as additional context to help it choose the best template to use when generating an OpenSearch DSL query based on the uses provided `query_text`. If the LLM determines that the provided search templates are not applicable to the given `query_text`, then the LLM will use a default match all query search template. It is important to note that the LLM will not directly render the final Opensearch DSL query with the chosen template, but rather use the template source as additional context to help it form the query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just default query, right? We don't have a default template for match all query
Each `search_templates` array entry must have a `template_id` and `template_description`. The LLM will use the description as additional context to help it choose the best template to use when generating an OpenSearch DSL query based on the uses provided `query_text`. If the LLM determines that the provided search templates are not applicable to the given `query_text`, then the LLM will use a default match all query search template. It is important to note that the LLM will not directly render the final Opensearch DSL query with the chosen template, but rather use the template source as additional context to help it form the query. | |
Each `search_templates` array entry must have a `template_id` and `template_description`. The LLM will use the description as additional context to help it choose the best template to use when generating an OpenSearch DSL query based on the uses provided `query_text`. If the LLM determines that the provided search templates are not applicable to the given `query_text`, then the LLM will use a default match all query. It is important to note that the LLM will not directly render the final Opensearch DSL query with the chosen template, but rather use the template source as additional context to help it form the query. |
You can use any [OpenSearch agent type](https://opensearch.org/docs/latest/ml-commons-plugin/agents-tools/agents/) to run the `QueryPlanningTool`. The following example uses a `flow` agent, which runs a sequence of tools in order and returns the last tool's output. | ||
|
||
When registering the agent, you can override parameters set during model registration, such as `system_prompt`. | ||
When registering the agent, you can override parameters set during model registration, such as `query_planner_system_prompt` and `query_planner_user_prompt`. The following example registers an agent with a default `llmGenerated` generation_type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a heading with 1. LLM Generated and then 2. User Defined Templates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshpalis Normally, parameters are in snake_case. Since this was an experimental feature, is there time to make this llm_generated
instead of llmGenerated
so it follows this convention?
"query_planner_user_prompt": "You are an OpenSearch Query DSL generation expert. Use the following index mapping to inform your query: ${parameters.index_mapping}. Based on this mapping, generate a query for the user's question: ${parameters.question}. Only use fields mentioned in the mapping.", | ||
"question": "Find all movies directed by John Doe", | ||
"index_mapping": "{\"properties\":{\"title\":{\"type\":\"text\"},\"director\":{\"type\":\"keyword\"},\"year\":{\"type\":\"integer\"}}}" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also remove the experimental
tag from next steps and update the neural search issue with opensearch-project/neural-search#1525
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointed out some minor concerns, we can correct these later as well.
Creating search templates : | ||
```json | ||
POST /_scripts/flower_species_search_template | ||
{ | ||
"script": { | ||
"lang": "mustache", | ||
"source": { | ||
"from": "{{from}}{{^from}}0{{/from}}", | ||
"size": "{{size}}{{^size}}10{{/size}}", | ||
"query": { | ||
"match": { | ||
"species": "{{species}}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
```json | ||
POST /_scripts/flower_species_search_template_2 | ||
{ | ||
"script": { | ||
"lang": "mustache", | ||
"source": { | ||
"from": "{{from}}{{^from}}0{{/from}}", | ||
"size": "{{size}}{{^size}}10{{/size}}", | ||
"query": { | ||
"term": { | ||
"species": "{{species}}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have more complicated examples? We might want to showcase 2 things
- the LLM is capable to choosing the template based on the description
- The Templates can be used when we have a really complicated use case that the LLM cannot generate the query itself or when we want determinism in the LLM response.
I can perhaps showcases a complicated use case in Agentic Search documentation, but we should at least show the LLM choosing between 2 different templates effectively. Here looks like both the templates are same with same description as well. Perhaps we can go with a little more complicated use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can add a more complicated scenario, perhaps its better to utilize the same example you intend to use for Agentic Search documentation
"description": "A general tool to answer any question", | ||
"parameters": { | ||
"model_id": "ANiSxJgBOh0h20Y9XYXl", | ||
"response_filter": "$.output.message.content[0].text", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding response filter here totally works, we might want to add this in the model registration body under parameters (same effect, just cleaner approach when considering the Conversational Agent)
{ | ||
"parameters": { | ||
"user_prompt": "You are an OpenSearch Query DSL generation assistant, generate an OpenSearch Query DSL to retrieve the most relevant documents for the user provided natural language question: ${parameters.query_text}, please return the query dsl only, no other texts. Please don't use size:0, because that would limit the query to return no result. please return a query to find the most relevant documents related to users question. For example: {\"query\":{\"match\":{\"species\":\"setosa\"}}} \n", | ||
"query_planner_user_prompt": "You are an OpenSearch Query DSL generation assistant, generate an OpenSearch Query DSL to retrieve the most relevant documents for the user provided natural language question: ${parameters.query_text}, please return the query dsl only, no other texts. Please don't use size:0, because that would limit the query to return no result. please return a query to find the most relevant documents related to users question. For example: {\"query\":{\"match\":{\"species\":\"setosa\"}}} \n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we mention that we have a default system and user prompt? And perhaps remove this from the execute operation to make it less confusing? From 3.3 the user_prompt is meant to provide the information about question etc not the guidance about DSL generation like in this example. So maybe remove it altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What execute example should we use here instead?
"parameters": { | ||
"user_prompt": "You are an OpenSearch Query DSL generation assistant, generate an OpenSearch Query DSL to retrieve the most relevant documents for the user provided natural language question: ${parameters.query_text}, please return the query dsl only, no other texts. Please don't use size:0, because that would limit the query to return no result. please return a query to find the most relevant documents related to users question. For example: {\"query\":{\"match\":{\"species\":\"setosa\"}}} \n", | ||
"query_planner_user_prompt": "You are an OpenSearch Query DSL generation assistant, generate an OpenSearch Query DSL to retrieve the most relevant documents for the user provided natural language question: ${parameters.query_text}, please return the query dsl only, no other texts. Please don't use size:0, because that would limit the query to return no result. please return a query to find the most relevant documents related to users question. For example: {\"query\":{\"match\":{\"species\":\"setosa\"}}} \n", | ||
"query_text": "How many iris flowers of type setosa are there?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query_text
will be called question
from 3.3
Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: Joshua Palis <[email protected]>
…mments Signed-off-by: Joshua Palis <[email protected]>
Signed-off-by: Fanit Kolchina <[email protected]>
{: .label .label-purple } | ||
|
||
Introduced in 3.2 | ||
Introduced 3.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We normally list the version when the feature is GA in the "introduced" label.
Signed-off-by: kolchfa-aws <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Editorial review
Signed-off-by: Nathan Bower <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Update documentation for
QueryPlanningTool
QueryPlanningTool
QueryPlanningTool
registration parameters documentationQueryPlanningTool
search_templatesIssues Resolved
Part of #11026
Version
3.3
Frontend features
If you're submitting documentation for an OpenSearch Dashboards feature, add a video that shows how a user will interact with the UI step by step. A voiceover is optional.
Checklist
For more information on following Developer Certificate of Origin and signing off your commits, please check here.