Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions _query-dsl/specialized/agentic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: default
title: Agentic
parent: Specialized queries
nav_order: 2
---

# Agentic query

Check failure on line 8 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 8, "column": 3}}}, "severity": "ERROR"}
**Introduced 3.2**
{: .label .label-purple }

Use the `agentic` query to ask questions in natural language and have OpenSearch automatically plan and execute the retrieval. The `agentic` query works in conjunction with a preconfigured agent that reads the question, plans the search, and returns relevant results. For more information about agentic search, see [Agentic search]({{site.url}}{{site.baseurl}}/vector-search/ai-search/agentic-search/).

Check failure on line 12 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 12, "column": 317}}}, "severity": "ERROR"}

Check failure on line 12 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 12, "column": 10}}}, "severity": "ERROR"}

**Prerequisite**<br>
Before using an `agentic` query, you must configure an agent with the [`QueryPlanningTool`]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/tools/query-planning-tool/) and create a search pipeline with an `agentic_query_translator` search request processor.
{: .note}

## Request body fields

The `agentic` query accepts the following fields.

Field | Data type | Required/Optional | Description
:--- | :--- | :--- | :---
`query_text` | String | Required | The natural language question or request.
`query_fields` | Array | Optional | A list of fields that the agent should consider when generating the search query. If not provided, the agent considers all available fields in the index mapping.

## Example

The following example uses an `agentic` query that asks a natural language question about flowers in an `iris` dataset. In this example, `query_text` contains the natural language question, `query_fields` specifies the fields to use when generating the query, and the `search-pipeline` query parameter specifies the search pipeline containing the agentic query translator processor:

Check failure on line 29 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 29, "column": 32}}}, "severity": "ERROR"}

```json
GET /iris-index/_search?search_pipeline=agentic-pipeline
{
"query": {
"agentic": {
"query_text": "List all the flowers present",
"query_fields": ["species", "petal_length_in_cm"]
}
}
}
```
{% include copy-curl.html %}

When executed, the agentic search request performs the following steps:

Check failure on line 44 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 44, "column": 20}}}, "severity": "ERROR"}

1. Sends the natural language question, along with the index mapping and a default prompt, to a large language model (LLM).
2. The LLM generates a query domain-specific language (DSL) query based on the input.
3. The generated DSL query is executed as a search request in OpenSearch.
4. Returns the search results based on the generated query.

For a complete example, see [Agentic search]({{site.url}}{{site.baseurl}}/vector-search/ai-search/agentic-search/).

Check failure on line 51 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 51, "column": 30}}}, "severity": "ERROR"}

## Next steps

- Learn how to set up agentic search in [Agentic search]({{site.url}}{{site.baseurl}}/vector-search/ai-search/agentic-search/).

Check failure on line 55 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 55, "column": 42}}}, "severity": "ERROR"}

Check failure on line 55 in _query-dsl/specialized/agentic.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_query-dsl/specialized/agentic.md", "range": {"start": {"line": 55, "column": 23}}}, "severity": "ERROR"}
- Learn about configuring agents in [Agents]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/agents/).
- Learn about the [QueryPlanningTool]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/tools/query-planning-tool/).
8 changes: 6 additions & 2 deletions _query-dsl/specialized/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ redirect_from:

OpenSearch supports the following specialized queries:

- `distance_feature`: Calculates document scores based on the dynamically calculated distance between the origin and a document's `date`, `date_nanos`, or `geo_point` fields. This query can skip non-competitive hits.
- [`agentic`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/agentic/): Uses natural language questions that are automatically planned and executed by an agent with a large language model.

- [`more_like_this`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/more-like-this/): Finds documents similar to the provided text, document, or collection of documents.
- [`distance_feature`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/distance-feature/): Calculates document scores based on the dynamically calculated distance between the origin and a document's `date`, `date_nanos`, or `geo_point` fields. This query can skip non-competitive hits.

- [`knn`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/k-nn/): Used for searching raw vectors during [vector search]({{site.url}}{{site.baseurl}}/vector-search/).

- [`more_like_this`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/more-like-this/): Finds documents similar to the provided text, document, or collection of documents.

- [`neural`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/neural/): Used for searching by text or image in [vector search]({{site.url}}{{site.baseurl}}/search-plugins/neural-search/).

- [`neural_sparse`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/neural-sparse/): Used for vector field search in [sparse neural search]({{site.url}}{{site.baseurl}}/search-plugins/neural-sparse-search/).
Expand All @@ -30,4 +32,6 @@ OpenSearch supports the following specialized queries:

- [`script_score`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/script-score/): Calculates a custom score for matching documents using a script.

- [`template`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/template/): Allows you to use Mustache templating in queries.

- [`wrapper`]({{site.url}}{{site.baseurl}}/query-dsl/specialized/wrapper/): Accepts other queries as JSON or YAML strings.
2 changes: 1 addition & 1 deletion _query-dsl/specialized/k-nn/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: default
title: k-NN
parent: Specialized queries
has_children: true
nav_order: 10
nav_order: 15
redirect_from:
- /query-dsl/specialized/k-nn/
---
Expand Down
103 changes: 103 additions & 0 deletions _search-plugins/search-pipelines/agentic-context-processor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
layout: default
title: Agentic context
nav_order: 2
has_children: false
parent: Search processors
grand_parent: Search pipelines
---

# Agentic context processor

Check failure on line 10 in _search-plugins/search-pipelines/agentic-context-processor.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: Agentic. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_search-plugins/search-pipelines/agentic-context-processor.md", "range": {"start": {"line": 10, "column": 3}}}, "severity": "ERROR"}
**Introduced 3.3**
{: .label .label-purple }

The `agentic_context` search response processor adds agent execution context information to search response extensions. This processor works in conjunction with the [agentic query translator]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/agentic-query-translator-processor/) to expose the agent's query translation process and maintain conversation continuity:

1. The processor retrieves agent context information from the pipeline processing context.
2. Based on the processor configuration, it selectively includes the agent steps summary and the query domain-specific language (DSL) query in the response.
3. The memory ID is always included, when available, for conversation continuity.
4. The context information is added to the search response extensions.
5. Type validation ensures that all context attributes are strings.

## Request body fields

The following table lists all available request fields.

Field | Data type | Description
:--- | :--- | :---
`agent_steps_summary` | Boolean | Whether to include the agent's execution steps summary in the response. Default is `false`. Optional.
`dsl_query` | Boolean | Whether to include the generated DSL query in the response. Default is `false`. Optional.

Comment on lines +27 to +30
Copy link
Contributor

Choose a reason for hiding this comment

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

How is memory ID provided? Do we need to mention that memory ID will always be provided as long as this response processor is added?

Copy link
Member Author

Choose a reason for hiding this comment

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

Memory id is not provided in the processor but in the query side. Can be taken care in the agentic search doc PR. I can add about the response that memory id would be present always

## Response fields

When enabled, the processor adds the following fields to the search response extensions.

Field | Description
:--- | :---
`agent_steps_summary` | A summary of the steps that the agent took to translate the natural language query (included when `agent_steps_summary` is `true`).
`memory_id` | The conversation memory ID for maintaining context across queries. Only provide this in the `agentic` query if you want to continue the previous conversation.
`dsl_query` | The generated DSL query that was executed (included when `dsl_query` is `true`).

## Example

The following example request creates a search pipeline with an `agentic_context` response processor:

```json
PUT /_search/pipeline/agentic_pipeline
{
"request_processors": [
{
"agentic_query_translator": {
"agent_id": "your-agent-id"
}
}
],
"response_processors": [
{
"agentic_context": {
"agent_steps_summary": true,
"dsl_query": true
}
}
]
}
```
{% include copy-curl.html %}

Perform a search using the configured pipeline:

```json
POST /your-index/_search?search_pipeline=agentic_search_pipeline
{
"query": {
"agentic": {
"query_text": "Show me shoes in white color",
"memory_id": "your memory id"
}
}
}
```
{% include copy-curl.html %}

The response contains the steps taken by the agent to translate the query, the memory ID, and the rewritten DSL query:

```json
{
"took": 15,
"hits": {
"_shards": {...},
"hits": [...]
},
"ext": {
"agent_steps_summary": "I have these tools available: [ListIndexTool, IndexMappingTool, query_planner_tool]\\nFirst I used: ListIndexTool — input: \"\"; context gained: \"Discovered products-index which seems relevant for products and pricing context\"\\nSecond I used: IndexMappingTool — input: \"products-index\"; context gained: \"Confirmed presence of category and price fields in products-index\"\\nThird I used: query_planner_tool — qpt.question: \"Show me shoes that cost exactly 100 dollars.\"; index_name_provided: \"products-index\"\\nValidation: qpt output is valid and accurately reflects the request for shoes priced at 100 dollars.",
"memory_id": "WVhHiJkBnqovov2plcDH",
"dsl_query": "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"category\":\"shoes\"}},{\"term\":{\"price\":100.0}}]}}}"
}
}
```

## Related pages

- [Agentic search queries]({{site.url}}{{site.baseurl}}/vector-search/ai-search/agentic-search)
- [Agents]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/agents/index/)
- [Agentic query translator processor]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/agentic-query-translator-processor/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
layout: default
title: Agentic query translator
nav_order: 5
has_children: false
parent: Search processors
grand_parent: Search pipelines
---

# Agentic query translator processor
**Introduced 3.2**
{: .label .label-purple }

The `agentic_query_translator` search request processor enables natural language search by translating user queries into OpenSearch query domain-specific language (DSL) queries using machine learning (ML) agents. It works with [agentic search queries]({{site.url}}{{site.baseurl}}/vector-search/ai-search/agentic-search) to provide conversational search capabilities:

1. The processor sends the user's natural language query to the specified ML agent.
2. The agent translates the query into OpenSearch DSL.
3. The original query is replaced with the generated DSL query.

This processor only works with the `agentic` query type as the top-level query.
{: .note}

## Prerequisites

Before using the `agentic_query_translator` processor, you must have either a conversational or flow agent configured. For more information, see [Agents]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/agents/index/).

## Request body fields

The following table lists all available request fields.

Field | Data type | Description
:--- | :--- | :---
`agent_id` | String | The ID of the ML agent that will translate natural language queries into DSL queries. Required.


## Example

The following example request creates a search pipeline with an `agentic_query_translator` processor:

```json
PUT /_search/pipeline/agentic_search_pipeline
{
"request_processors": [
{
"agentic_query_translator": {
"agent_id": "your-agent-id-here"
}
}
]
}
```
{% include copy-curl.html %}

## Usage

To use the processor, run an `agentic` query:

```json
POST /your-index/_search?search_pipeline=agentic_search_pipeline
{
"query": {
"agentic": {
"query_text": "Show me shoes in white color"
}
}
}
```
{% include copy-curl.html %}

The response contains the matching documents:

```json
{
"took": 6031,
"timed_out": false,
"_shards": {
"total": 8,
"successful": 8,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 8,
"relation": "eq"
},
"max_score": 0.0,
"hits": [
{
"_index": "products-index",
"_id": "43",
"_score": 0.0,
"_source": {
"product_name": "Nike Air Max white",
"description": "Red cushioned sneakers",
"price": 140.0,
"currency": "USD",
"in_stock": true,
"color": "white",
"size": "10",
"product_id": "P6001",
"category": "shoes",
"brand": "Nike"
}
},
{
"_index": "products-index",
"_id": "45",
"_score": 0.0,
"_source": {
"product_name": "Adidas Superstar white",
"description": "Classic black sneakers",
"price": 100.0,
"currency": "USD",
"in_stock": true,
"color": "white",
"size": "8",
"product_id": "P6003",
"category": "shoes",
"brand": "Adidas"
}
}
]
}
}
```

## Related pages

- [Agentic search queries]({{site.url}}{{site.baseurl}}/vector-search/ai-search/agentic-search)
- [Agents]({{site.url}}{{site.baseurl}}/ml-commons-plugin/agents-tools/agents/index/)
- [Agentic context processor]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/agentic-context-processor/)
3 changes: 2 additions & 1 deletion _search-plugins/search-pipelines/search-processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following table lists all supported search request processors.

Processor | Description | Earliest available version
:--- | :--- | :---
[`agentic_query_translator`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/agentic-query-translator-processor/) | Translates `agentic` queries into OpenSearch query domain-specific language (DSL) and executes an agent to process the query. | 3.2
[`filter_query`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/filter-query-processor/) | Adds a filtering query that is used to filter requests. | 2.8
[`ml_inference`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/ml-inference-search-request/) | Invokes registered machine learning (ML) models in order to rewrite queries. | 2.16
[`neural_query_enricher`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/neural-query-enricher/) | Sets a default model for neural search and neural sparse search at the index or field level. | 2.11 (neural), 2.13 (neural sparse)
Expand All @@ -37,6 +38,7 @@ The following table lists all supported search response processors.

Processor | Description | Earliest available version
:--- | :--- | :---
[`agentic_context`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/agentic-context-processor/)| Returns the agent summary, generated query, and memory ID for an `agentic` query. | 3.3
[`collapse`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/collapse-processor/)| Deduplicates search hits based on a field value, similarly to `collapse` in a search request. | 2.12
[`hybrid_score_explanation`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/explanation-processor/)| Adds detailed scoring information to search results when the `explain` parameter is enabled, providing information about score normalization, combination techniques, and individual score calculations in hybrid queries. | 2.19
[`ml_inference`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/ml-inference-search-response/) | Invokes registered machine learning (ML) models in order to incorporate model output as additional search response fields. | 2.16
Expand All @@ -48,7 +50,6 @@ Processor | Description | Earliest available version
[`split`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/split-processor/)| Splits a string field into an array of substrings based on a specified delimiter. | 2.17
[`truncate_hits`]({{site.url}}{{site.baseurl}}/search-plugins/search-pipelines/truncate-hits-processor/)| Discards search hits after a specified target count is reached. Can undo the effect of the `oversample` request processor. | 2.12


## Search phase results processors

A search phase results processor runs between search phases at the coordinating node level. It intercepts the results retrieved from one search phase and transforms them before passing them to the next search phase.
Expand Down
3 changes: 2 additions & 1 deletion _vector-search/ai-search/agentic-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ has_children: false
---

# Agentic search

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/).
{: .warning}

Introduced 3.2
**Introduced 3.2**
{: .label .label-purple }

Agentic search lets users ask questions in natural language and have OpenSearch plan and execute the retrieval automatically. A preconfigured **agent** reads the question, plans the search, and returns relevant results.
Expand Down
2 changes: 1 addition & 1 deletion _vector-search/api/neural.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ By default, the Neural Search Stats API is disabled through a cluster setting. T
PUT /_cluster/settings
{
"persistent": {
"plugins.neural_search.stats_enabled": "true"
"plugins.neural_search.stats_enabled": true
}
}
```
Expand Down
Loading