Link Search Menu Expand Document Documentation Menu

Agentic query

Introduced 3.2

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.

Prerequisite

Before using an agentic query, you must fulfill the following prerequisites:

  1. Configure an agent with the QueryPlanningTool. The QueryPlanningTool is required for generating query domain-specific language (DSL) queries from natural language questions. Optionally, you can configure the agent with additional tools for enhanced functionality.
  2. Create a search pipeline with an agentic_query_translator search request processor.

For detailed setup instructions, see Agentic search.

Request body fields

The agentic query accepts the following fields.

Field Data type Required/Optional Description
query_text String Required The natural language question to be answered by the agent.
query_fields Array Optional A list of index fields that the agent should consider when generating the search query. If omitted, the agent infers the applicable fields based on the index mappings and content.
memory_id String Optional Applicable for conversational agents only. Provides a memory ID from a previous response to continue the conversation with prior context. See Using conversational agents for agentic search.

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:

GET /iris-index/_search?search_pipeline=agentic-pipeline
{
  "query": {
    "agentic": {
      "query_text": "List all the flowers present",
      "query_fields": ["species", "petal_length_in_cm"]
    }
  }
}

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

  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.

Next steps

350 characters left

Have a question? .

Want to contribute? or .