All Implemented Interfaces:
NamedWriteable, Writeable, Resolvable

public class CompletionFunction extends InferenceFunction<CompletionFunction>
COMPLETION function generates text completions from a prompt using an inference endpoint.

This function is an internal optimization primitive used exclusively for constant folding of COMPLETION commands during the analysis phase. It should never be registered in the function registry or exposed to users, as ESQL does not currently support async functions in the function registry.

When a COMPLETION command has a foldable prompt (e.g., a literal or foldable expression), the analyzer transforms it into an EVAL node with a CompletionFunction expression:


 FROM books
 | COMPLETION "Translate this text" WITH { "inference_id": "my-model" }
 
is internally rewritten into:

 FROM books
 | EVAL completion = COMPLETION("Translate this text", "my-model")
 
The pre-optimizer then evaluates this function using InferenceFunctionEvaluator and replaces it with a literal result.