Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/136103.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 136103
summary: Enable the TEXT_EMBEDDING function in non-snapshot build
area: ES|QL
type: feature
issues: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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::embedding-eval[]
// end::text-embedding-eval[]

input:keyword | embedding:dense_vector
Who is Victor Hugo? | [56.0, 50.0, 48.0]
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") } };

}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
import org.elasticsearch.xpack.esql.expression.function.Param;

import java.io.IOException;
import java.util.List;
import java.util.Objects;

Expand All @@ -40,14 +39,24 @@ public class TextEmbedding extends InferenceFunction<TextEmbedding> {

@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 a text using a specified inference endpoint.",
appliesTo = { @FunctionAppliesTo(version = "9.3", lifeCycle = FunctionAppliesToLifecycle.PREVIEW) },
preview = true,
examples = {
@Example(
description = "Generate text embeddings using the 'test_dense_inference' inference endpoint.",
file = "text-embedding",
tag = "embedding-eval"
tag = "text-embedding-eval"
),
@Example(
description = "Generate text embeddings for use within a KNN search.",
file = "text-embedding",
tag = "text-embedding-knn"
),
@Example(
description = "Generate text embeddings inline within a KNN search.",
file = "text-embedding",
tag = "text-embedding-knn-inline"
) }
)
public TextEmbedding(
Expand All @@ -56,7 +65,7 @@ public TextEmbedding(
@Param(
name = InferenceFunction.INFERENCE_ID_PARAMETER_NAME,
type = { "keyword" },
description = "Identifier of the inference endpoint"
description = "Identifier of the inference endpoint. The inference endpoint must have the `text_embedding` task type."
) Expression inferenceId
) {
super(source, List.of(inputText, inferenceId));
Expand All @@ -65,7 +74,7 @@ public TextEmbedding(
}

@Override
public void writeTo(StreamOutput out) throws IOException {
public void writeTo(StreamOutput out) {
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method signature was changed to remove the throws IOException declaration, but StreamOutput.write* methods can throw IOException. This could cause compilation errors if the method implementation actually tries to write to the stream.

Suggested change
public void writeTo(StreamOutput out) {
public void writeTo(StreamOutput out) throws java.io.IOException {

Copilot uses AI. Check for mistakes.

throw new UnsupportedOperationException("doesn't escape the node");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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"));

Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand All @@ -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]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<TestCaseSupplier> cases() {
return paramsToSuppliers(TextEmbeddingTests.parameters());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.TestCase> testCaseSupplier) {
this.testCase = testCaseSupplier.get();
}
Expand Down
Loading
Loading