Skip to content

Conversation

joshpalis
Copy link
Member

@joshpalis joshpalis commented Sep 29, 2025

Description

Update documentation for QueryPlanningTool

  • Updates agent tools list with QueryPlanningTool
  • Updates QueryPlanningTool registration parameters documentation
  • Adds examples for QueryPlanningTool search_templates
  • Adds examples for Claud-4 and GPT-5 model registration

Issues 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

  • By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and subject to the Developers Certificate of Origin.
    For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Member

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

Suggested change
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.
Copy link
Member

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?

Copy link
Collaborator

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\"}}}"
}
Copy link
Member

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

Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws left a 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.

Comment on lines 174 to 209
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}}"
}
}
}
}
}
```
Copy link
Contributor

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?

Copy link
Member Author

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",
Copy link
Contributor

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",
Copy link
Contributor

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?

Copy link
Member Author

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?"
Copy link
Contributor

@rithin-pullela-aws rithin-pullela-aws Sep 29, 2025

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

@kolchfa-aws kolchfa-aws added Tech review PR: Tech review in progress release-notes PR: Include this PR in the automated release notes v3.3.0 labels Sep 29, 2025
@kolchfa-aws kolchfa-aws added Doc review PR: Doc review in progress and removed Tech review PR: Tech review in progress labels Oct 1, 2025
Signed-off-by: Fanit Kolchina <[email protected]>
{: .label .label-purple }

Introduced in 3.2
Introduced 3.3
Copy link
Collaborator

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.

@kolchfa-aws kolchfa-aws added Editorial review PR: Editorial review in progress and removed Doc review PR: Doc review in progress labels Oct 1, 2025
@kolchfa-aws kolchfa-aws assigned natebower and unassigned kolchfa-aws Oct 1, 2025
Copy link
Collaborator

@natebower natebower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editorial review

Copy link
Collaborator

@natebower natebower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@natebower natebower removed the Editorial review PR: Editorial review in progress label Oct 1, 2025
@natebower natebower merged commit b89023d into opensearch-project:main Oct 1, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes PR: Include this PR in the automated release notes v3.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants