Skip to content

Commit 4813302

Browse files
authored
ES|QL - KNN function in release builds (#135709)
1 parent 1bf50c9 commit 4813302

File tree

14 files changed

+29
-123
lines changed

14 files changed

+29
-123
lines changed

docs/changelog/135709.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 135709
2+
summary: ES|QL - KNN function
3+
area: ES|QL
4+
type: feature
5+
issues: []

docs/reference/query-languages/esql/_snippets/functions/layout/knn.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/query-languages/esql/kibana/definition/functions/knn.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/KnnSemanticTextTestCase.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.test.rest.ESRestTestCase;
1313
import org.elasticsearch.xpack.esql.AssertWarnings;
1414
import org.elasticsearch.xpack.esql.CsvTestsDataLoader;
15-
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
1615
import org.junit.After;
1716
import org.junit.Before;
1817
import org.junit.Rule;
@@ -43,7 +42,6 @@ public void checkCapability() {
4342

4443
@SuppressWarnings("unchecked")
4544
public void testKnnQueryWithSemanticText() throws IOException {
46-
assumeTrue("knn with semantic text not available", EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled());
4745
String knnQuery = """
4846
FROM semantic-test METADATA _score
4947
| WHERE knn(dense_semantic, [0, 1, 2])
@@ -65,7 +63,6 @@ public void testKnnQueryWithSemanticText() throws IOException {
6563
}
6664

6765
public void testKnnQueryOnTextField() throws IOException {
68-
assumeTrue("knn with semantic text not available", EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled());
6966
String knnQuery = """
7067
FROM semantic-test METADATA _score
7168
| WHERE knn(text, [0, 1, 2])
@@ -80,7 +77,6 @@ public void testKnnQueryOnTextField() throws IOException {
8077
}
8178

8279
public void testKnnQueryOnSparseSemanticTextField() throws IOException {
83-
assumeTrue("knn with semantic text not available", EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled());
8480
String knnQuery = """
8581
FROM semantic-test METADATA _score
8682
| WHERE knn(sparse_semantic, [0, 1, 2])

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/KnnFunctionIT.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.elasticsearch.xpack.esql.EsqlTestUtils;
2222
import org.elasticsearch.xpack.esql.VerificationException;
2323
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
24-
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
2524
import org.elasticsearch.xpack.esql.action.EsqlQueryRequest;
2625
import org.elasticsearch.xpack.esql.core.type.DataType;
2726
import org.elasticsearch.xpack.esql.parser.ParserUtils;
@@ -231,8 +230,6 @@ public void testKnnWithLookupJoin() {
231230

232231
@Before
233232
public void setup() throws IOException {
234-
assumeTrue("Needs KNN support", EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled());
235-
236233
var indexName = "test";
237234
var client = client().admin().indices();
238235
XContentBuilder mapping = XContentFactory.jsonBuilder()

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ public enum Cap {
13211321
/**
13221322
* Support knn function
13231323
*/
1324-
KNN_FUNCTION_V5(Build.current().isSnapshot()),
1324+
KNN_FUNCTION_V5,
13251325

13261326
/**
13271327
* Support for the {@code TEXT_EMBEDDING} function for generating dense vector embeddings.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ private static FunctionDefinition[][] functions() {
506506
new FunctionDefinition[] {
507507
def(Decay.class, quad(Decay::new), "decay"),
508508
def(Kql.class, uni(Kql::new), "kql"),
509+
def(Knn.class, tri(Knn::new), "knn"),
509510
def(Match.class, tri(Match::new), "match"),
510511
def(MultiMatch.class, MultiMatch::new, "multi_match"),
511512
def(QueryString.class, bi(QueryString::new), "qstr"),
@@ -540,7 +541,6 @@ private static FunctionDefinition[][] snapshotFunctions() {
540541
def(Last.class, bi(Last::new), "last"),
541542
def(Score.class, uni(Score::new), Score.NAME),
542543
def(Term.class, bi(Term::new), "term"),
543-
def(Knn.class, tri(Knn::new), "knn"),
544544
def(CosineSimilarity.class, CosineSimilarity::new, "v_cosine"),
545545
def(DotProduct.class, DotProduct::new, "v_dot_product"),
546546
def(L1Norm.class, L1Norm::new, "v_l1_norm"),

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/vector/Knn.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class Knn extends FullTextFunction
103103
description = "Finds the k nearest vectors to a query vector, as measured by a similarity metric. "
104104
+ "knn function finds nearest vectors through approximate search on indexed dense_vectors or semantic_text fields.",
105105
examples = { @Example(file = "knn-function", tag = "knn-function") },
106-
appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.DEVELOPMENT) }
106+
appliesTo = { @FunctionAppliesTo(lifeCycle = FunctionAppliesToLifecycle.PREVIEW) }
107107
)
108108
public Knn(
109109
Source source,

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/vector/VectorWritables.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ private VectorWritables() {
2727
public static List<NamedWriteableRegistry.Entry> getNamedWritables() {
2828
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
2929

30-
if (EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled()) {
31-
entries.add(Knn.ENTRY);
32-
}
30+
entries.add(Knn.ENTRY);
3331
if (EsqlCapabilities.Cap.COSINE_VECTOR_SIMILARITY_FUNCTION.isEnabled()) {
3432
entries.add(CosineSimilarity.ENTRY);
3533
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/AnalyzerTests.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,22 +2356,14 @@ public void testImplicitCasting() {
23562356
}
23572357

23582358
public void testDenseVectorImplicitCastingKnn() {
2359-
assumeTrue("dense_vector capability not available", EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled());
2360-
2361-
if (EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled()) {
2362-
checkDenseVectorCastingHexKnn("float_vector");
2363-
checkDenseVectorCastingKnn("float_vector");
2364-
}
2365-
if (EsqlCapabilities.Cap.DENSE_VECTOR_FIELD_TYPE_BYTE_ELEMENTS.isEnabled()) {
2366-
checkDenseVectorCastingKnn("byte_vector");
2367-
checkDenseVectorCastingHexKnn("byte_vector");
2368-
checkDenseVectorEvalCastingKnn("byte_vector");
2369-
}
2370-
if (EsqlCapabilities.Cap.DENSE_VECTOR_FIELD_TYPE_BIT_ELEMENTS.isEnabled()) {
2371-
checkDenseVectorCastingKnn("bit_vector");
2372-
checkDenseVectorCastingHexKnn("bit_vector");
2373-
checkDenseVectorEvalCastingKnn("bit_vector");
2374-
}
2359+
checkDenseVectorCastingHexKnn("float_vector");
2360+
checkDenseVectorCastingKnn("float_vector");
2361+
checkDenseVectorCastingKnn("byte_vector");
2362+
checkDenseVectorCastingHexKnn("byte_vector");
2363+
checkDenseVectorEvalCastingKnn("byte_vector");
2364+
checkDenseVectorCastingKnn("bit_vector");
2365+
checkDenseVectorCastingHexKnn("bit_vector");
2366+
checkDenseVectorEvalCastingKnn("bit_vector");
23752367
}
23762368

23772369
private static void checkDenseVectorCastingKnn(String fieldName) {
@@ -2535,9 +2527,7 @@ private void checkDenseVectorEvalCastingSimilarityFunction(String similarityFunc
25352527
}
25362528

25372529
public void testVectorFunctionHexImplicitCastingError() {
2538-
if (EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled()) {
2539-
checkVectorFunctionHexImplicitCastingError("where knn(float_vector, \"notcorrect\")");
2540-
}
2530+
checkVectorFunctionHexImplicitCastingError("where knn(float_vector, \"notcorrect\")");
25412531
if (EsqlCapabilities.Cap.DOT_PRODUCT_VECTOR_SIMILARITY_FUNCTION.isEnabled()) {
25422532
checkVectorFunctionHexImplicitCastingError("eval s = v_dot_product(\"notcorrect\", 0.342)");
25432533
}
@@ -3920,7 +3910,6 @@ public void testTextEmbeddingFunctionWithoutModel() {
39203910
}
39213911

39223912
public void testKnnFunctionWithTextEmbedding() {
3923-
assumeTrue("KNN function capability required", EsqlCapabilities.Cap.KNN_FUNCTION_V5.isEnabled());
39243913
assumeTrue("TEXT_EMBEDDING function required", EsqlCapabilities.Cap.TEXT_EMBEDDING_FUNCTION.isEnabled());
39253914

39263915
LogicalPlan plan = analyze(

0 commit comments

Comments
 (0)