@parthpatel You can connect the AI Assistant to a particular index using the following:
POST /_plugins/_ml/connectors/_create
{
"name": "OpenAI gpt-4o-mini (search-aware)",
"version": 1,
"protocol": "http",
"parameters": {
"endpoint": "api.openai.com",
"model": "gpt-4o-mini",
"response_filter": "$.choices[0].message.content"
},
"credential": {
"openAI_key": "sk-proj-..."
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://${parameters.endpoint}/v1/chat/completions",
"headers": { "Authorization": "Bearer ${credential.openAI_key}" },
"request_body": "{ \"model\": \"${parameters.model}\", \"messages\": [{\"role\":\"system\",\"content\":\"${parameters.system_prompt}\\n\\nChat history:\\n${parameters.chat_history:-}\\n\\nSearch results from OpenSearch:\\n${parameters.SearchIndexTool.output:-}\"},{\"role\":\"user\",\"content\":\"${parameters.question}\"}] }"
}
]
}
POST /_plugins/_ml/models/_register?deploy=true
{
"name": "OpenAI gpt-4o-mini (search-aware)",
"function_name": "remote",
"connector_id": "<NEW_CONNECTOR_ID>"
}
POST /_plugins/_ml/agents/_register
{
"name": "Index-Aware Chat Agent",
"type": "conversational_flow",
"app_type": "os_chat",
"description": "Chat agent with natural language search over my_products",
"memory": { "type": "conversation_index" },
"tools": [
{
"type": "QueryPlanningTool",
"parameters": {
"model_id": "<NEW_MODEL_ID>",
"index_name": "my_products",
"question": "${parameters.question}"
},
"include_output_in_agent_response": false
},
{
"type": "SearchIndexTool",
"parameters": {
"input": "{\"index\": \"my_products\", \"query\": ${parameters.QueryPlanningTool.output}}"
},
"include_output_in_agent_response": false
},
{
"type": "MLModelTool",
"description": "Synthesize search results into a natural language answer",
"parameters": {
"model_id": "<NEW_MODEL_ID>",
"system_prompt": "You are a helpful product catalog assistant. Use the OpenSearch search results provided to answer the user's question about products. If results are empty, say so."
}
}
]
}
PUT /.plugins-ml-config/_doc/os_chat
{
"type": "os_chat_root_agent",
"configuration": {
"agent_id": "<NEW_AGENT_ID>"
}
}
You should be able to use AI Assistant to ask question based on the index name “my_products”. However, I was not able to get this working using multiple indices however.
Alternatively you can use the following to query indices via devtools:
POST /_plugins/_ml/connectors/_create
{
"name": "OpenAI Chat Connector",
"description": "Connector for OpenAI supporting query planning and search",
"version": 1,
"protocol": "http",
"parameters": {
"endpoint": "api.openai.com",
"model": "gpt-4o-mini",
"response_filter": "$.choices[0].message.content"
},
"credential": {
"openAI_key": "sk-proj-..."
},
"actions": [
{
"action_type": "predict",
"method": "POST",
"url": "https://${parameters.endpoint}/v1/chat/completions",
"headers": {
"Authorization": "Bearer ${credential.openAI_key}",
"Content-Type": "application/json"
},
"request_body": "{\"model\":\"${parameters.model}\",\"messages\":[{\"role\":\"system\",\"content\":\"${parameters.system_prompt}\"},{\"role\":\"user\",\"content\":\"${parameters.user_prompt}\"}]}"
}
]
}
POST /_plugins/_ml/models/_register
{
"name": "openai-gpt4o-mini",
"function_name": "remote",
"description": "GPT-4o-mini via OpenAI",
"connector_id": "<CONNECTOR_ID>"
}
POST /_plugins/_ml/agents/_register
{
"name": "NL Search Agent",
"type": "flow",
"description": "Natural language search - specify index_name and question",
"tools": [
{
"type": "QueryPlanningTool",
"parameters": {
"model_id": "<MODEL_ID>",
"index_name": "${parameters.index_name}",
"question": "${parameters.question}"
},
"include_output_in_agent_response": true
},
{
"type": "SearchIndexTool",
"parameters": {
"input": "{\"index\": \"${parameters.index_name}\", \"query\": ${parameters.QueryPlanningTool.output}}"
}
}
]
}
POST /_plugins/_ml/agents/<AGENT_ID>/_execute
{
"parameters": {
"question": "Show me all electronics",
"index_name": "my_products"
}
}