Skip to content

Commit 9c4da4b

Browse files
committed
Updating documentation, removing experimental mentions, addressing comments
Signed-off-by: Joshua Palis <[email protected]>
1 parent 8aa1698 commit 9c4da4b

File tree

1 file changed

+14
-46
lines changed

1 file changed

+14
-46
lines changed

_ml-commons-plugin/agents-tools/tools/query-planning-tool.md

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,9 @@ Introduced in 3.2
1717
{: .label .label-purple }
1818
<!-- vale on -->
1919

20-
This is an experimental feature and is not recommended for use in a production environment. For updates on the progress of the feature or if you want to leave feedback, join the discussion on the [OpenSearch forum](https://forum.opensearch.org/).
21-
{: .warning}
22-
2320
The `QueryPlanningTool` generates an OpenSearch query domain-specific language (DSL) query from a natural language question.
2421

25-
## Step 1: Enable the agentic search feature flag
26-
27-
To use the `QueryPlanningTool`, you must first enable the `agentic_search_enabled` setting:
28-
29-
```json
30-
PUT _cluster/settings
31-
{
32-
"persistent" : {
33-
"plugins.ml_commons.agentic_search_enabled" : true
34-
}
35-
}
36-
```
37-
{% include copy-curl.html %}
38-
39-
OpenSearch responds with an acknowledgment:
40-
41-
```json
42-
{
43-
"acknowledged": true,
44-
"persistent": {
45-
"plugins": {
46-
"ml_commons": {
47-
"agentic_search_enabled": "true"
48-
}
49-
}
50-
},
51-
"transient": {}
52-
}
53-
```
54-
55-
## Step 2: Register and deploy a model
22+
## Step 1: Register and deploy a model
5623

5724
The following request registers a remote model from Amazon Bedrock and deploys it to your cluster. The API call creates the connector and model in one step.
5825

@@ -143,12 +110,13 @@ OpenSearch responds with the model ID:
143110
}
144111
```
145112

146-
## Step 3: Register an agent
113+
## Step 2: Register an agent
147114

148115
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.
149116

150117
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.
151118

119+
### LLM Generated
152120
```json
153121
POST /_plugins/_ml/agents/_register
154122
{
@@ -160,16 +128,17 @@ POST /_plugins/_ml/agents/_register
160128
"type": "QueryPlanningTool",
161129
"description": "A general tool to answer any question.",
162130
"parameters": {
163-
"model_id": "ANiSxJgBOh0h20Y9XYXl",
164-
"response_filter": "$.output.message.content[0].text"
131+
"model_id": "ANiSxJgBOh0h20Y9XYXl"
165132
}
166133
}
167134
]
168135
}
169136
```
170137
{% include copy-curl.html %}
171138

172-
You can also register an agent with a `user_templates` generation_type which provides an LLM with an array of [OpenSearch Search Templates](https://docs.opensearch.org/latest/api-reference/search-apis/search-template/index/). These templates are provided to the LLM as additional context to assist the LLM in OpenSearch DSL generation. The following example creates a few search templates and registers an agent with a `user_template` generation_type.
139+
### User Templates
140+
141+
You can also register an agent with a `user_templates` generation_type which provides an LLM with an array of [OpenSearch Search Templates]({{site.url}}{{site.baseurl}}/api-reference/search-apis/search-template/index/). These templates are provided to the LLM as additional context to assist the LLM in OpenSearch DSL generation. The following example creates a few search templates and registers an agent with a `user_template` generation_type.
173142

174143
Creating search templates :
175144
```json
@@ -221,7 +190,6 @@ POST /_plugins/_ml/agents/_register
221190
"description": "A general tool to answer any question",
222191
"parameters": {
223192
"model_id": "ANiSxJgBOh0h20Y9XYXl",
224-
"response_filter": "$.output.message.content[0].text",
225193
"generation_type": "user_templates",
226194
"search_templates": [
227195
{
@@ -240,7 +208,7 @@ POST /_plugins/_ml/agents/_register
240208
}
241209
```
242210

243-
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.
211+
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 `question`. If the LLM determines that the provided search templates are not applicable to the given `question`, 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.
244212

245213
For parameter descriptions, see [Register parameters](#register-parameters).
246214

@@ -252,16 +220,16 @@ OpenSearch responds with an agent ID:
252220
}
253221
```
254222

255-
## Step 4: Execute the agent
223+
## Step 3: Execute the agent
256224

257225
Execute the agent by sending the following request:
258226

259227
```json
260228
POST /_plugins/_ml/agents/RNjQi5gBOh0h20Y9-RX1/_execute
261229
{
262230
"parameters": {
263-
"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",
264-
"query_text": "How many iris flowers of type setosa are there?"
231+
"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.question}, 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",
232+
"question": "How many iris flowers of type setosa are there?"
265233
}
266234
}
267235
```
@@ -294,7 +262,7 @@ Parameter | Type | Required/Optional | Description
294262
`response_filter` | String | Optional | A JSONPath expression used to extract the generated query from the LLM's response.
295263
`generation_type` | String | Optional | The type of query generation. Currently, only `llmGenerated` and `user_templates` are supported. Defaults to `llmGenerated`.
296264
`query_planner_system_prompt` | String | Optional | A system prompt that provides high-level instructions to the LLM. Defaults to "You are an OpenSearch Query DSL generation assistant, translating natural language questions to OpenSeach DSL Queries".
297-
`query_planner_user_prompt` | String | Optional | A user prompt template for the LLM. It can contain placeholders for execution-time parameters like `${parameters.query_text}`.
265+
`query_planner_user_prompt` | String | Optional | A user prompt template for the LLM. It can contain placeholders for execution-time parameters like `${parameters.question}`.
298266
`search_templates` | Array | Optional | Applicable only for `user_templates` generation_type. A list of search template IDs and descriptions which an LLM will use as context to create an OpenSearch DSL query. Each entry within the `search_templates` array must include a `template_id` and a `template_description` which provides the LLM with additional context on the contents of the search template
299267

300268
## Execute parameters
@@ -307,7 +275,7 @@ There are three layers of parameters to consider:
307275

308276
2. **Tool parameters**: The `QueryPlanningTool` uses its own set of parameters, such as `query_planner_user_prompt` and `query_planner_system_prompt`, to construct the final string that will be passed to the connector. The tool takes the `query_planner_user_prompt` string and resolves any variables within it, and the resulting string is then used to fill the appropriate variable (for example, `${parameters.query_planner_user_prompt}`) in the connector's `request_body`.
309277

310-
3. **Prompt variables**: These are the variables inside the `query_planner_user_prompt`, which have the format `${parameters.your_variable_name}`. These must be provided in the `_execute` API call. For example, if your `user_prompt` is "Generate a query for: ${parameters.query_text}", then you must provide a `query_text` parameter when you run the agent.
278+
3. **Prompt variables**: These are the variables inside the `query_planner_user_prompt`, which have the format `${parameters.your_variable_name}`. These must be provided in the `_execute` API call. For example, if your `user_prompt` is "Generate a query for: ${parameters.question}", then you must provide a `question` parameter when you run the agent.
311279

312280
In summary, the required parameters for an `_execute` call are the **prompt variables**. The tool's own parameters (like `query_planner_user_prompt`) can be overridden at execution time to change how the final prompt is constructed.
313281

@@ -351,7 +319,7 @@ POST /_plugins/_ml/agents/your_agent_id/_execute
351319
352320
## Next steps
353321

354-
This is an experimental feature. See the following GitHub issues for information about future enhancements:
322+
See the following GitHub issues for information about future enhancements:
355323

356324
- [[RFC] Design for Agentic Search #1479](https://github.com/opensearch-project/neural-search/issues/1479)
357325
- [[RFC] Agentic Search in OpenSearch #4005](https://github.com/opensearch-project/ml-commons/issues/4005)

0 commit comments

Comments
 (0)