Skip to content

Commit 69bb980

Browse files
committed
Better comments.
1 parent cb0a701 commit 69bb980

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/inference/CompletionFunction.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,25 @@
2727

2828
/**
2929
* COMPLETION function generates text completions from a prompt using an inference endpoint.
30-
* This function is not registered in the function registry.
30+
* <p>
31+
* This function is an internal optimization primitive used exclusively for constant folding of
32+
* {@code COMPLETION} commands during the analysis phase. It should never be registered in the
33+
* function registry or exposed to users, as ESQL does not currently support async functions
34+
* in the function registry.
35+
* <p>
36+
* When a {@code COMPLETION} command has a foldable prompt (e.g., a literal or foldable expression),
37+
* the analyzer transforms it into an {@code EVAL} node with a {@code CompletionFunction} expression:
38+
* <pre>{@code
39+
* FROM books
40+
* | COMPLETION "Translate this text" WITH { "inference_id": "my-model" }
41+
* }</pre>
42+
* is internally rewritten into:
43+
* <pre>{@code
44+
* FROM books
45+
* | EVAL completion = COMPLETION("Translate this text", "my-model")
46+
* }</pre>
47+
* The pre-optimizer then evaluates this function using {@code InferenceFunctionEvaluator} and
48+
* replaces it with a literal result.
3149
*/
3250
public class CompletionFunction extends InferenceFunction<CompletionFunction> {
3351

0 commit comments

Comments
 (0)