serverless: preview
stack: preview 9.1.0
The COMPLETION
command allows you to send prompts and context to a Large Language Model (LLM) directly within your ES|QL queries, to perform text generation tasks.
Syntax
::::{tab-set}
:::{tab-item} 9.2.0+
COMPLETION [column =] prompt WITH { "inference_id" : "my_inference_endpoint" }
:::
:::{tab-item} 9.1.x only
COMPLETION [column =] prompt WITH my_inference_endpoint
:::
::::
Parameters
column
: (Optional) The name of the output column containing the LLM's response.
If not specified, the results will be stored in a column named `completion`.
If the specified column already exists, it will be overwritten with the new results.
prompt
: The input text or expression used to prompt the LLM.
This can be a string literal or a reference to a column containing text.
my_inference_endpoint
: The ID of the inference endpoint to use for the task.
The inference endpoint must be configured with the `completion` task type.
Description
The COMPLETION
command provides a general-purpose interface for
text generation tasks using a Large Language Model (LLM) in ES|QL.
COMPLETION
supports a wide range of text generation tasks. Depending on your
prompt and the model you use, you can perform arbitrary text generation tasks
including:
Requirements
To use this command, you must deploy your LLM model in Elasticsearch as
an inference endpoint with the
task type completion
.
COMPLETION
commands may time out when processing large datasets or complex prompts. The default timeout is 10 minutes, but you can increase this limit if necessary.
How you increase the timeout depends on your deployment type:
::::{tab-set} :::{tab-item} {{ech}}
search.default_search_timeout
cluster setting using Kibana's Advanced settings
::::::{tab-item} Self-managed
search.default_search_timeout
in elasticsearch.yml
or updating via Cluster Settings APIsearch:timeout
setting using Kibana's Advanced settings:::{tab-item} {{serverless-full}}
If you don't want to increase the timeout limit, try the following:
LIMIT
or more selective filters before the COMPLETION
commandExamples
Use the default column name (results stored in completion
column):
ROW question = "What is Elasticsearch?"
| COMPLETION question WITH { "inference_id" : "my_inference_endpoint" }
| KEEP question, completion
question:keyword | completion:keyword |
---|---|
What is Elasticsearch? | A distributed search and analytics engine |
Specify the output column (results stored in answer
column):
ROW question = "What is Elasticsearch?"
| COMPLETION answer = question WITH { "inference_id" : "my_inference_endpoint" }
| KEEP question, answer
question:keyword | answer:keyword |
---|---|
What is Elasticsearch? | A distributed search and analytics engine |
Summarize the top 10 highest-rated movies using a prompt:
FROM movies
| SORT rating DESC
| LIMIT 10
| EVAL prompt = CONCAT(
"Summarize this movie using the following information: \n",
"Title: ", title, "\n",
"Synopsis: ", synopsis, "\n",
"Actors: ", MV_CONCAT(actors, ", "), "\n",
)
| COMPLETION summary = prompt WITH { "inference_id" : "my_inference_endpoint" }
| KEEP title, summary, rating
title:keyword | summary:keyword | rating:double |
---|---|---|
The Shawshank Redemption | A tale of hope and redemption in prison. | 9.3 |
The Godfather | A mafia family's rise and fall. | 9.2 |
The Dark Knight | Batman battles the Joker in Gotham. | 9.0 |
Pulp Fiction | Interconnected crime stories with dark humor. | 8.9 |
Fight Club | A man starts an underground fight club. | 8.8 |
Inception | A thief steals secrets through dreams. | 8.8 |
The Matrix | A hacker discovers reality is a simulation. | 8.7 |
Parasite | Class conflict between two families. | 8.6 |
Interstellar | A team explores space to save humanity. | 8.6 |
The Prestige | Rival magicians engage in dangerous competition. | 8.5 |