Class CompletionFunction
java.lang.Object
org.elasticsearch.xpack.esql.core.tree.Node<Expression>
org.elasticsearch.xpack.esql.core.expression.Expression
org.elasticsearch.xpack.esql.core.expression.function.Function
org.elasticsearch.xpack.esql.expression.function.inference.InferenceFunction<CompletionFunction>
org.elasticsearch.xpack.esql.expression.function.inference.CompletionFunction
- All Implemented Interfaces:
NamedWriteable,Writeable,Resolvable
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.-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
Expression.TypeResolutionNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
Fields inherited from class org.elasticsearch.xpack.esql.expression.function.inference.InferenceFunction
INFERENCE_ID_PARAMETER_NAMEFields inherited from class org.elasticsearch.xpack.esql.core.tree.Node
TO_STRING_MAX_WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCompletionFunction(Source source, Expression prompt, Expression inferenceId) -
Method Summary
Modifier and TypeMethodDescriptiondataType()booleanbooleanfoldable()inthashCode()The inference endpoint identifier expression.protected NodeInfo<? extends Expression> info()prompt()replaceChildren(List<Expression> newChildren) protected Expression.TypeResolutiontaskType()The task type required by this function (e.g., TEXT_EMBEDDING).toString()withInferenceResolutionError(String inferenceId, String error) Returns a copy with inference resolution error for display to user.voidwriteTo(StreamOutput out) Methods inherited from class org.elasticsearch.xpack.esql.expression.function.inference.InferenceFunction
hasNestedInferenceFunctionMethods inherited from class org.elasticsearch.xpack.esql.core.expression.function.Function
arguments, functionName, nodeString, nullableMethods inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
canonical, canonicalize, childrenResolved, fold, propertiesToString, references, resolved, semanticEquals, semanticHash, typeResolvedMethods inherited from class org.elasticsearch.xpack.esql.core.tree.Node
anyMatch, children, collect, collectFirstChildren, collectLeaves, doCollectFirst, forEachDown, forEachDown, forEachDownMayReturnEarly, forEachProperty, forEachPropertyDown, forEachPropertyOnly, forEachPropertyUp, forEachUp, forEachUp, nodeName, nodeProperties, replaceChildrenSameSize, source, sourceLocation, sourceText, transformChildren, transformDown, transformDown, transformDown, transformNodeProps, transformPropertiesDown, transformPropertiesOnly, transformPropertiesUp, transformUp, transformUp, transformUp
-
Constructor Details
-
CompletionFunction
-
-
Method Details
-
writeTo
- Throws:
IOException
-
getWriteableName
-
prompt
-
inferenceId
Description copied from class:InferenceFunctionThe inference endpoint identifier expression.- Specified by:
inferenceIdin classInferenceFunction<CompletionFunction>
-
foldable
public boolean foldable()- Overrides:
foldablein classExpression
-
dataType
- Specified by:
dataTypein classExpression
-
resolveType
- Overrides:
resolveTypein classExpression
-
taskType
Description copied from class:InferenceFunctionThe task type required by this function (e.g., TEXT_EMBEDDING).- Specified by:
taskTypein classInferenceFunction<CompletionFunction>
-
withInferenceResolutionError
Description copied from class:InferenceFunctionReturns a copy with inference resolution error for display to user.- Specified by:
withInferenceResolutionErrorin classInferenceFunction<CompletionFunction>
-
replaceChildren
- Specified by:
replaceChildrenin classNode<Expression>
-
info
- Specified by:
infoin classNode<Expression>
-
toString
- Overrides:
toStringin classExpression
-
equals
-
hashCode
public int hashCode()
-