Skip to content

Commit b5a3e17

Browse files
authored
ESQL - Add semantic_text support for knn function (#133806)
1 parent 3eefef7 commit b5a3e17

File tree

26 files changed

+432
-72
lines changed

26 files changed

+432
-72
lines changed

docs/reference/query-languages/esql/_snippets/functions/description/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/_snippets/functions/parameters/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/images/functions/knn.svg

Lines changed: 1 addition & 1 deletion
Loading

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.

docs/reference/query-languages/esql/kibana/docs/functions/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.

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/expression/Expression.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public TypeResolution and(TypeResolution other) {
5555
return failed ? this : other;
5656
}
5757

58+
public TypeResolution or(TypeResolution other) {
59+
return failed ? other : this;
60+
}
61+
5862
public TypeResolution and(Supplier<TypeResolution> other) {
5963
return failed ? this : other.get();
6064
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ public enum DataType {
395395
// ES calls this 'point', but ESQL calls it 'cartesian_point'
396396
map.put("point", DataType.CARTESIAN_POINT);
397397
map.put("shape", DataType.CARTESIAN_SHAPE);
398+
// semantic_text is returned as text by field_caps, but unit tests will retrieve it from the mapping
399+
// so we need to map it here as well
400+
map.put("semantic_text", DataType.TEXT);
398401
ES_TO_TYPE = Collections.unmodifiableMap(map);
399402
// DATETIME has different esType and typeName, add an entry in NAME_TO_TYPE with date as key
400403
map = TYPES.stream().collect(toMap(DataType::typeName, t -> t));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.qa.multi_node;
9+
10+
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
11+
12+
import org.elasticsearch.test.TestClustersThreadFilter;
13+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
14+
import org.elasticsearch.xpack.esql.qa.rest.KnnSemanticTextTestCase;
15+
import org.junit.ClassRule;
16+
17+
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
18+
public class KnnSemanticTextIT extends KnnSemanticTextTestCase {
19+
@ClassRule
20+
public static ElasticsearchCluster cluster = Clusters.testCluster(
21+
spec -> spec.module("x-pack-inference").plugin("inference-service-test")
22+
);
23+
24+
@Override
25+
protected String getTestRestCluster() {
26+
return cluster.getHttpAddresses();
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.qa.single_node;
9+
10+
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
11+
12+
import org.elasticsearch.test.TestClustersThreadFilter;
13+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
14+
import org.elasticsearch.xpack.esql.qa.rest.KnnSemanticTextTestCase;
15+
import org.junit.ClassRule;
16+
17+
@ThreadLeakFilters(filters = TestClustersThreadFilter.class)
18+
public class KnnSemanticTextIT extends KnnSemanticTextTestCase {
19+
20+
@ClassRule
21+
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test"));
22+
23+
@Override
24+
protected String getTestRestCluster() {
25+
return cluster.getHttpAddresses();
26+
}
27+
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.loadDataSetIntoEs;
7474
import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
7575
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.COMPLETION;
76+
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.KNN_FUNCTION_V5;
7677
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METRICS_COMMAND;
7778
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.RERANK;
7879
import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS;
@@ -211,8 +212,12 @@ protected boolean supportsInferenceTestService() {
211212
}
212213

213214
protected boolean requiresInferenceEndpoint() {
214-
return Stream.of(SEMANTIC_TEXT_FIELD_CAPS.capabilityName(), RERANK.capabilityName(), COMPLETION.capabilityName())
215-
.anyMatch(testCase.requiredCapabilities::contains);
215+
return Stream.of(
216+
SEMANTIC_TEXT_FIELD_CAPS.capabilityName(),
217+
RERANK.capabilityName(),
218+
COMPLETION.capabilityName(),
219+
KNN_FUNCTION_V5.capabilityName()
220+
).anyMatch(testCase.requiredCapabilities::contains);
216221
}
217222

218223
protected boolean supportsIndexModeLookup() throws IOException {

0 commit comments

Comments
 (0)