forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Semantic search with query builder rewrite (elastic#118676) (elastic#…
…118945) * Semantic search with query builder rewrite * Address review feedback * Add feature behind snapshot * Use after/before instead of afterClass/beforeClass * Call onFailure instead of throwing exception * Fix KqlFunctionIT by requiring KqlPlugin * Update scoring tests now that they are enabled * Drop the score column for now
- Loading branch information
Showing
18 changed files
with
629 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...ode/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/multi_node/SemanticMatchIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.qa.multi_node; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; | ||
|
||
import org.elasticsearch.test.TestClustersThreadFilter; | ||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.elasticsearch.xpack.esql.qa.rest.SemanticMatchTestCase; | ||
import org.junit.ClassRule; | ||
|
||
@ThreadLeakFilters(filters = TestClustersThreadFilter.class) | ||
public class SemanticMatchIT extends SemanticMatchTestCase { | ||
@ClassRule | ||
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test")); | ||
|
||
@Override | ||
protected String getTestRestCluster() { | ||
return cluster.getHttpAddresses(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...de/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/SemanticMatchIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.qa.single_node; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters; | ||
|
||
import org.elasticsearch.test.TestClustersThreadFilter; | ||
import org.elasticsearch.test.cluster.ElasticsearchCluster; | ||
import org.elasticsearch.xpack.esql.qa.rest.SemanticMatchTestCase; | ||
import org.junit.ClassRule; | ||
|
||
@ThreadLeakFilters(filters = TestClustersThreadFilter.class) | ||
public class SemanticMatchIT extends SemanticMatchTestCase { | ||
@ClassRule | ||
public static ElasticsearchCluster cluster = Clusters.testCluster(spec -> spec.plugin("inference-service-test")); | ||
|
||
@Override | ||
protected String getTestRestCluster() { | ||
return cluster.getHttpAddresses(); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
...l/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/SemanticMatchTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.qa.rest; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.test.rest.ESRestTestCase; | ||
import org.elasticsearch.xpack.esql.action.EsqlCapabilities; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import static org.hamcrest.core.StringContains.containsString; | ||
|
||
public abstract class SemanticMatchTestCase extends ESRestTestCase { | ||
public void testWithMultipleInferenceIds() throws IOException { | ||
String query = """ | ||
from test-semantic1,test-semantic2 | ||
| where match(semantic_text_field, "something") | ||
"""; | ||
ResponseException re = expectThrows(ResponseException.class, () -> runEsqlQuery(query)); | ||
|
||
assertThat(re.getMessage(), containsString("Field [semantic_text_field] has multiple inference IDs associated with it")); | ||
|
||
assertEquals(400, re.getResponse().getStatusLine().getStatusCode()); | ||
} | ||
|
||
public void testWithInferenceNotConfigured() { | ||
String query = """ | ||
from test-semantic3 | ||
| where match(semantic_text_field, "something") | ||
"""; | ||
ResponseException re = expectThrows(ResponseException.class, () -> runEsqlQuery(query)); | ||
|
||
assertThat(re.getMessage(), containsString("Inference endpoint not found")); | ||
assertEquals(404, re.getResponse().getStatusLine().getStatusCode()); | ||
} | ||
|
||
@Before | ||
public void setUpIndices() throws IOException { | ||
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_TYPE.isEnabled()); | ||
|
||
var settings = Settings.builder().build(); | ||
|
||
String mapping1 = """ | ||
"properties": { | ||
"semantic_text_field": { | ||
"type": "semantic_text", | ||
"inference_id": "test_sparse_inference" | ||
} | ||
} | ||
"""; | ||
createIndex(adminClient(), "test-semantic1", settings, mapping1); | ||
|
||
String mapping2 = """ | ||
"properties": { | ||
"semantic_text_field": { | ||
"type": "semantic_text", | ||
"inference_id": "test_dense_inference" | ||
} | ||
} | ||
"""; | ||
createIndex(adminClient(), "test-semantic2", settings, mapping2); | ||
|
||
String mapping3 = """ | ||
"properties": { | ||
"semantic_text_field": { | ||
"type": "semantic_text", | ||
"inference_id": "inexistent" | ||
} | ||
} | ||
"""; | ||
createIndex(adminClient(), "test-semantic3", settings, mapping3); | ||
} | ||
|
||
@Before | ||
public void setUpTextEmbeddingInferenceEndpoint() throws IOException { | ||
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_TYPE.isEnabled()); | ||
Request request = new Request("PUT", "_inference/text_embedding/test_dense_inference"); | ||
request.setJsonEntity(""" | ||
{ | ||
"service": "test_service", | ||
"service_settings": { | ||
"model": "my_model", | ||
"api_key": "abc64" | ||
}, | ||
"task_settings": { | ||
} | ||
} | ||
"""); | ||
adminClient().performRequest(request); | ||
} | ||
|
||
@After | ||
public void wipeData() throws IOException { | ||
assumeTrue("semantic text capability not available", EsqlCapabilities.Cap.SEMANTIC_TEXT_TYPE.isEnabled()); | ||
adminClient().performRequest(new Request("DELETE", "*")); | ||
|
||
try { | ||
adminClient().performRequest(new Request("DELETE", "_inference/test_dense_inference")); | ||
} catch (ResponseException e) { | ||
// 404 here means the endpoint was not created | ||
if (e.getResponse().getStatusLine().getStatusCode() != 404) { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
private Map<String, Object> runEsqlQuery(String query) throws IOException { | ||
RestEsqlTestCase.RequestObjectBuilder builder = RestEsqlTestCase.requestObjectBuilder().query(query); | ||
return RestEsqlTestCase.runEsqlSync(builder); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/MockQueryBuilderResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
import org.elasticsearch.xpack.esql.session.QueryBuilderResolver; | ||
import org.elasticsearch.xpack.esql.session.Result; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
public class MockQueryBuilderResolver extends QueryBuilderResolver { | ||
public MockQueryBuilderResolver() { | ||
super(null, null, null, null); | ||
} | ||
|
||
@Override | ||
public void resolveQueryBuilders( | ||
LogicalPlan plan, | ||
ActionListener<Result> listener, | ||
BiConsumer<LogicalPlan, ActionListener<Result>> callback | ||
) { | ||
callback.accept(plan, listener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.