diff --git a/docs/changelog/136103.yaml b/docs/changelog/136103.yaml new file mode 100644 index 0000000000000..a01e08ee086f8 --- /dev/null +++ b/docs/changelog/136103.yaml @@ -0,0 +1,5 @@ +pr: 136103 +summary: Enable the TEXT_EMBEDDING function in non-snapshot build +area: ES|QL +type: feature +issues: [] diff --git a/docs/reference/query-languages/esql/_snippets/functions/description/text_embedding.md b/docs/reference/query-languages/esql/_snippets/functions/description/text_embedding.md index 70ebddbdb7c0a..a737cd10bded8 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/description/text_embedding.md +++ b/docs/reference/query-languages/esql/_snippets/functions/description/text_embedding.md @@ -2,5 +2,5 @@ **Description** -Generates dense vector embeddings for text using a specified inference endpoint. +Generates dense vector embeddings from text input using a specified [inference endpoint](docs-content://explore-analyze/elastic-inference/inference-api.md). Use this function to generate query vectors for KNN searches against your vectorized data or others dense vector based operations. diff --git a/docs/reference/query-languages/esql/_snippets/functions/examples/text_embedding.md b/docs/reference/query-languages/esql/_snippets/functions/examples/text_embedding.md index 71d05c9524350..a6384e1222891 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/examples/text_embedding.md +++ b/docs/reference/query-languages/esql/_snippets/functions/examples/text_embedding.md @@ -1,13 +1,27 @@ % This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it. -**Example** +**Examples** -Generate text embeddings using the 'test_dense_inference' inference endpoint. +Basic text embedding generation from a text string using an inference endpoint. ```esql ROW input="Who is Victor Hugo?" | EVAL embedding = TEXT_EMBEDDING("Who is Victor Hugo?", "test_dense_inference") -; +``` + +Generate text embeddings and store them in a variable for reuse in KNN vector search queries. + +```esql +FROM semantic_text METADATA _score +| EVAL query_embedding = TEXT_EMBEDDING("be excellent to each other", "test_dense_inference") +| WHERE KNN(semantic_text_dense_field, query_embedding) +``` + +Directly embed text within a KNN query for streamlined vector search without intermediate variables. + +```esql +FROM semantic_text METADATA _score +| WHERE KNN(semantic_text_dense_field, TEXT_EMBEDDING("be excellent to each other", "test_dense_inference")) ``` diff --git a/docs/reference/query-languages/esql/_snippets/functions/layout/text_embedding.md b/docs/reference/query-languages/esql/_snippets/functions/layout/text_embedding.md index a120fff2d7a22..b7d87984e6ad6 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/layout/text_embedding.md +++ b/docs/reference/query-languages/esql/_snippets/functions/layout/text_embedding.md @@ -2,7 +2,7 @@ ## `TEXT_EMBEDDING` [esql-text_embedding] ```{applies_to} -stack: development +stack: preview 9.3 serverless: preview ``` diff --git a/docs/reference/query-languages/esql/_snippets/functions/parameters/text_embedding.md b/docs/reference/query-languages/esql/_snippets/functions/parameters/text_embedding.md index 80175caaf09dd..9b7802b0f0db8 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/parameters/text_embedding.md +++ b/docs/reference/query-languages/esql/_snippets/functions/parameters/text_embedding.md @@ -3,8 +3,8 @@ **Parameters** `text` -: Text to generate embeddings from +: Text string to generate embeddings from. Must be a non-null literal string value. `inference_id` -: Identifier of the inference endpoint +: Identifier of an existing inference endpoint the that will generate the embeddings. The inference endpoint must have the `text_embedding` task type and should use the same model that was used to embed your indexed data. diff --git a/docs/reference/query-languages/esql/_snippets/lists/dense-vector-functions.md b/docs/reference/query-languages/esql/_snippets/lists/dense-vector-functions.md index 3b54078e40bf2..2268dd649bba5 100644 --- a/docs/reference/query-languages/esql/_snippets/lists/dense-vector-functions.md +++ b/docs/reference/query-languages/esql/_snippets/lists/dense-vector-functions.md @@ -1,4 +1,5 @@ * {applies_to}`stack: preview 9.2` {applies_to}`serverless: preview` [`KNN`](../../functions-operators/dense-vector-functions.md#esql-knn) +* {applies_to}`stack: preview 9.3` {applies_to}`serverless: preview` [`TEXT_EMBEDDING`](../../functions-operators/dense-vector-functions.md#esql-text_embedding) % * {applies_to}`stack: preview 9.3` {applies_to}`serverless: preview` [`V_COSINE`](../../functions-operators/dense-vector-functions.md#esql-v_cosine) % * {applies_to}`stack: preview 9.3` {applies_to}`serverless: preview` [`V_DOT_PRODUCT`](../../functions-operators/dense-vector-functions.md#esql-v_dot_product) diff --git a/docs/reference/query-languages/esql/functions-operators/dense-vector-functions.md b/docs/reference/query-languages/esql/functions-operators/dense-vector-functions.md index d384eacc63a0d..da56b64ee8ff5 100644 --- a/docs/reference/query-languages/esql/functions-operators/dense-vector-functions.md +++ b/docs/reference/query-languages/esql/functions-operators/dense-vector-functions.md @@ -23,6 +23,9 @@ and require appropriate field mappings. :::{include} ../_snippets/functions/layout/knn.md ::: +:::{include} ../_snippets/functions/layout/text_embedding.md +::: + % V_COSINE is currently a hidden feature % To make it visible again, uncomment this and the line in % lists/dense-vector-functions.md diff --git a/docs/reference/query-languages/esql/kibana/definition/functions/text_embedding.json b/docs/reference/query-languages/esql/kibana/definition/functions/text_embedding.json index 343cf597a0a53..f2c186a90cda7 100644 --- a/docs/reference/query-languages/esql/kibana/definition/functions/text_embedding.json +++ b/docs/reference/query-languages/esql/kibana/definition/functions/text_embedding.json @@ -2,7 +2,7 @@ "comment" : "This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it.", "type" : "scalar", "name" : "text_embedding", - "description" : "Generates dense vector embeddings for text using a specified inference endpoint.", + "description" : "Generates dense vector embeddings from text input using a specified inference endpoint. Use this function to generate query vectors for KNN searches against your vectorized data or others dense vector based operations.", "signatures" : [ { "params" : [ @@ -10,13 +10,13 @@ "name" : "text", "type" : "keyword", "optional" : false, - "description" : "Text to generate embeddings from" + "description" : "Text string to generate embeddings from. Must be a non-null literal string value." }, { "name" : "inference_id", "type" : "keyword", "optional" : false, - "description" : "Identifier of the inference endpoint" + "description" : "Identifier of an existing inference endpoint the that will generate the embeddings. The inference endpoint must have the `text_embedding` task type and should use the same model that was used to embed your indexed data." } ], "variadic" : false, @@ -24,8 +24,10 @@ } ], "examples" : [ - "ROW input=\"Who is Victor Hugo?\"\n| EVAL embedding = TEXT_EMBEDDING(\"Who is Victor Hugo?\", \"test_dense_inference\")\n;" + "ROW input=\"Who is Victor Hugo?\"\n| EVAL embedding = TEXT_EMBEDDING(\"Who is Victor Hugo?\", \"test_dense_inference\")", + "FROM semantic_text METADATA _score\n| EVAL query_embedding = TEXT_EMBEDDING(\"be excellent to each other\", \"test_dense_inference\")\n| WHERE KNN(semantic_text_dense_field, query_embedding)", + "FROM semantic_text METADATA _score\n| WHERE KNN(semantic_text_dense_field, TEXT_EMBEDDING(\"be excellent to each other\", \"test_dense_inference\"))" ], "preview" : true, - "snapshot_only" : true + "snapshot_only" : false } diff --git a/docs/reference/query-languages/esql/kibana/docs/functions/text_embedding.md b/docs/reference/query-languages/esql/kibana/docs/functions/text_embedding.md index f8981fb3be66a..a8ab12217608c 100644 --- a/docs/reference/query-languages/esql/kibana/docs/functions/text_embedding.md +++ b/docs/reference/query-languages/esql/kibana/docs/functions/text_embedding.md @@ -1,10 +1,9 @@ % This is generated by ESQL's AbstractFunctionTestCase. Do not edit it. See ../README.md for how to regenerate it. ### TEXT EMBEDDING -Generates dense vector embeddings for text using a specified inference endpoint. +Generates dense vector embeddings from text input using a specified [inference endpoint](docs-content://explore-analyze/elastic-inference/inference-api.md). Use this function to generate query vectors for KNN searches against your vectorized data or others dense vector based operations. ```esql ROW input="Who is Victor Hugo?" | EVAL embedding = TEXT_EMBEDDING("Who is Victor Hugo?", "test_dense_inference") -; ``` diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/text-embedding.csv-spec b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/text-embedding.csv-spec index 86e0fcd0eb6a4..002d39f767f85 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/resources/text-embedding.csv-spec +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/resources/text-embedding.csv-spec @@ -2,11 +2,11 @@ text_embedding using a row source operator required_capability: text_embedding_function required_capability: dense_vector_field_type_released -// tag::embedding-eval[] +// tag::text-embedding-eval[] ROW input="Who is Victor Hugo?" | EVAL embedding = TEXT_EMBEDDING("Who is Victor Hugo?", "test_dense_inference") +// end::text-embedding-eval[] ; -// end::embedding-eval[] input:keyword | embedding:dense_vector Who is Victor Hugo? | [56.0, 50.0, 48.0] @@ -32,9 +32,11 @@ required_capability: dense_vector_field_type_released required_capability: knn_function_v5 required_capability: semantic_text_field_caps +// tag::text-embedding-knn[] FROM semantic_text METADATA _score | EVAL query_embedding = TEXT_EMBEDDING("be excellent to each other", "test_dense_inference") | WHERE KNN(semantic_text_dense_field, query_embedding) +// end::text-embedding-knn[] | SORT _score DESC | LIMIT 10 | KEEP semantic_text_field, query_embedding @@ -52,8 +54,10 @@ required_capability: dense_vector_field_type_released required_capability: knn_function_v5 required_capability: semantic_text_field_caps +// tag::text-embedding-knn-inline[] FROM semantic_text METADATA _score | WHERE KNN(semantic_text_dense_field, TEXT_EMBEDDING("be excellent to each other", "test_dense_inference")) +// end::text-embedding-knn-inline[] | SORT _score DESC | LIMIT 10 | KEEP semantic_text_field diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java index d701d69652751..e80ebee86ffc6 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java @@ -1243,7 +1243,7 @@ public enum Cap { /** * Support for the {@code TEXT_EMBEDDING} function for generating dense vector embeddings. */ - TEXT_EMBEDDING_FUNCTION(Build.current().isSnapshot()), + TEXT_EMBEDDING_FUNCTION, /** * Support for the LIKE operator with a list of wildcards. diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java index 8553b3f587372..3c8ffb45585db 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java @@ -526,7 +526,9 @@ private static FunctionDefinition[][] functions() { def(AbsentOverTime.class, uni(AbsentOverTime::new), "absent_over_time"), def(AvgOverTime.class, uni(AvgOverTime::new), "avg_over_time"), def(LastOverTime.class, uni(LastOverTime::new), "last_over_time"), - def(FirstOverTime.class, uni(FirstOverTime::new), "first_over_time") } }; + def(FirstOverTime.class, uni(FirstOverTime::new), "first_over_time"), + // dense vector function + def(TextEmbedding.class, bi(TextEmbedding::new), "text_embedding") } }; } @@ -545,8 +547,7 @@ private static FunctionDefinition[][] snapshotFunctions() { def(L1Norm.class, L1Norm::new, "v_l1_norm"), def(L2Norm.class, L2Norm::new, "v_l2_norm"), def(Magnitude.class, Magnitude::new, "v_magnitude"), - def(Hamming.class, Hamming::new, "v_hamming"), - def(TextEmbedding.class, bi(TextEmbedding::new), "text_embedding") } }; + def(Hamming.class, Hamming::new, "v_hamming") } }; } public EsqlFunctionRegistry snapshotRegistry() { diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbedding.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbedding.java index ab8b8c8c3f3c9..65de2baf72a53 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbedding.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbedding.java @@ -40,23 +40,42 @@ public class TextEmbedding extends InferenceFunction { @FunctionInfo( returnType = "dense_vector", - description = "Generates dense vector embeddings for text using a specified inference endpoint.", - appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.DEVELOPMENT) }, + description = "Generates dense vector embeddings from text input using a specified " + + "[inference endpoint](docs-content://explore-analyze/elastic-inference/inference-api.md). " + + "Use this function to generate query vectors for KNN searches against your vectorized data " + + "or others dense vector based operations.", + appliesTo = { @FunctionAppliesTo(version = "9.3", lifeCycle = FunctionAppliesToLifecycle.PREVIEW) }, preview = true, examples = { @Example( - description = "Generate text embeddings using the 'test_dense_inference' inference endpoint.", + description = "Basic text embedding generation from a text string using an inference endpoint.", file = "text-embedding", - tag = "embedding-eval" + tag = "text-embedding-eval" + ), + @Example( + description = "Generate text embeddings and store them in a variable for reuse in KNN vector search queries.", + file = "text-embedding", + tag = "text-embedding-knn" + ), + @Example( + description = "Directly embed text within a KNN query for streamlined vector search without intermediate variables.", + file = "text-embedding", + tag = "text-embedding-knn-inline" ) } ) public TextEmbedding( Source source, - @Param(name = "text", type = { "keyword" }, description = "Text to generate embeddings from") Expression inputText, + @Param( + name = "text", + type = { "keyword" }, + description = "Text string to generate embeddings from. Must be a non-null literal string value." + ) Expression inputText, @Param( name = InferenceFunction.INFERENCE_ID_PARAMETER_NAME, type = { "keyword" }, - description = "Identifier of the inference endpoint" + description = "Identifier of an existing inference endpoint the that will generate the embeddings. " + + "The inference endpoint must have the `text_embedding` task type and should use the same model " + + "that was used to embed your indexed data." ) Expression inferenceId ) { super(source, List.of(inputText, inferenceId)); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java index 096b2a1f5c3fe..1a096df1b0648 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java @@ -3814,8 +3814,6 @@ private void assertEmptyEsRelation(LogicalPlan plan) { } public void testTextEmbeddingResolveInferenceId() { - assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - LogicalPlan plan = analyze( String.format(Locale.ROOT, """ FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING("italian food recipe", "%s")""", TEXT_EMBEDDING_INFERENCE_ID), @@ -3833,8 +3831,6 @@ public void testTextEmbeddingResolveInferenceId() { } public void testTextEmbeddingFunctionResolveType() { - assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - LogicalPlan plan = analyze( String.format(Locale.ROOT, """ FROM books METADATA _score| EVAL embedding = TEXT_EMBEDDING("italian food recipe", "%s")""", TEXT_EMBEDDING_INFERENCE_ID), @@ -3853,8 +3849,6 @@ public void testTextEmbeddingFunctionResolveType() { } public void testTextEmbeddingFunctionMissingInferenceIdError() { - assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - VerificationException ve = expectThrows( VerificationException.class, () -> analyze( @@ -3868,8 +3862,6 @@ public void testTextEmbeddingFunctionMissingInferenceIdError() { } public void testTextEmbeddingFunctionInvalidInferenceIdError() { - assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - String inferenceId = randomInferenceIdOtherThan(TEXT_EMBEDDING_INFERENCE_ID); VerificationException ve = expectThrows( VerificationException.class, @@ -3887,8 +3879,6 @@ public void testTextEmbeddingFunctionInvalidInferenceIdError() { } public void testTextEmbeddingFunctionWithoutModel() { - assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - ParsingException ve = expectThrows(ParsingException.class, () -> analyze(""" FROM books METADATA _score| EVAL embedding = TEXT_EMBEDDING("italian food recipe")""", "mapping-books.json")); @@ -3899,8 +3889,6 @@ public void testTextEmbeddingFunctionWithoutModel() { } public void testKnnFunctionWithTextEmbedding() { - assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - LogicalPlan plan = analyze( String.format(Locale.ROOT, """ from test | where KNN(float_vector, TEXT_EMBEDDING("italian food recipe", "%s"))""", TEXT_EMBEDDING_INFERENCE_ID), diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java index 4aeeb693779d7..389fadfed1693 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java @@ -2735,7 +2735,6 @@ public void testSortInTimeSeries() { } public void testTextEmbeddingFunctionInvalidQuery() { - assumeTrue("TEXT_EMBEDDING is not enabled", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); assertThat( error("from test | EVAL embedding = TEXT_EMBEDDING(null, ?)", defaultAnalyzer, TEXT_EMBEDDING_INFERENCE_ID), equalTo("1:30: first argument of [TEXT_EMBEDDING(null, ?)] cannot be null, received [null]") @@ -2753,7 +2752,6 @@ public void testTextEmbeddingFunctionInvalidQuery() { } public void testTextEmbeddingFunctionInvalidInferenceId() { - assumeTrue("TEXT_EMBEDDING is not enabled", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); assertThat( error("from test | EVAL embedding = TEXT_EMBEDDING(?, null)", defaultAnalyzer, "query text"), equalTo("1:30: second argument of [TEXT_EMBEDDING(?, null)] cannot be null, received [null]") diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingErrorTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingErrorTests.java index 3864c8ccc8685..63f3bf350db91 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingErrorTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingErrorTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.esql.expression.function.inference; -import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.expression.TypeResolutions; import org.elasticsearch.xpack.esql.core.tree.Source; @@ -16,7 +15,6 @@ import org.elasticsearch.xpack.esql.expression.function.ErrorsForCasesWithoutExamplesTestCase; import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; import org.hamcrest.Matcher; -import org.junit.Before; import java.util.List; import java.util.Locale; @@ -28,12 +26,6 @@ * Tests error conditions and type validation for TEXT_EMBEDDING function. */ public class TextEmbeddingErrorTests extends ErrorsForCasesWithoutExamplesTestCase { - - @Before - public void checkCapability() { - assumeTrue("TEXT_EMBEDDING is not enabled", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - } - @Override protected List cases() { return paramsToSuppliers(TextEmbeddingTests.parameters()); diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingTests.java index f7a1ed4cf2025..4389afd60bde1 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/inference/TextEmbeddingTests.java @@ -10,14 +10,12 @@ import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; -import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.expression.function.AbstractFunctionTestCase; import org.elasticsearch.xpack.esql.expression.function.FunctionName; import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; import org.hamcrest.Matchers; -import org.junit.Before; import java.util.List; import java.util.function.Supplier; @@ -28,11 +26,6 @@ @FunctionName("text_embedding") public class TextEmbeddingTests extends AbstractFunctionTestCase { - @Before - public void checkCapability() { - assumeTrue("TEXT_EMBEDDING is not enabled", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()); - } - public TextEmbeddingTests(@Name("TestCase") Supplier testCaseSupplier) { this.testCase = testCaseSupplier.get(); } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/inference/InferenceResolverTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/inference/InferenceResolverTests.java index 8ccda8a7010d1..30a711541f831 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/inference/InferenceResolverTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/inference/InferenceResolverTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.inference.action.GetInferenceModelAction; -import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry; import org.elasticsearch.xpack.esql.parser.EsqlParser; import org.junit.After; @@ -84,25 +83,23 @@ public void testCollectInferenceIds() { List.of("completion-inference-id") ); - if (EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled()) { - // Text embedding inference plan - assertCollectInferenceIds( - "FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING(\"description\", \"text-embedding-inference-id\")", - List.of("text-embedding-inference-id") - ); + // Text embedding function + assertCollectInferenceIds( + "FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING(\"description\", \"text-embedding-inference-id\")", + List.of("text-embedding-inference-id") + ); - // Test inference ID collection from an inference function - assertCollectInferenceIds( - "FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING(\"description\", \"text-embedding-inference-id\")", - List.of("text-embedding-inference-id") - ); + // Test inference ID collection from an inference function + assertCollectInferenceIds( + "FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING(\"description\", \"text-embedding-inference-id\")", + List.of("text-embedding-inference-id") + ); - // Test inference ID collection with nested functions - assertCollectInferenceIds( - "FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING(TEXT_EMBEDDING(\"nested\", \"nested-id\"), \"outer-id\")", - List.of("nested-id", "outer-id") - ); - } + // Test inference ID collection with nested functions + assertCollectInferenceIds( + "FROM books METADATA _score | EVAL embedding = TEXT_EMBEDDING(TEXT_EMBEDDING(\"nested\", \"nested-id\"), \"outer-id\")", + List.of("nested-id", "outer-id") + ); // Multiple inference plans assertCollectInferenceIds(""" diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml index 57d5bb7adb0df..7ae01e1dd807d 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml @@ -259,6 +259,7 @@ setup: - set: { esql.functions.to_long: functions_to_long } - set: { esql.functions.coalesce: functions_coalesce } - set: { esql.functions.categorize: functions_categorize } + - set: {esql.functions.text_embedding: functions_text_embedding} - do: esql.query: @@ -302,6 +303,7 @@ setup: - gt: { esql.functions.to_long: $functions_to_long } - match: { esql.functions.coalesce: $functions_coalesce } - gt: { esql.functions.categorize: $functions_categorize } + - match: {esql.functions.text_embedding: $functions_text_embedding} - set: { esql.features.limit: limit_counter } - set: { esql.features.sort: sort_counter }