Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky IT test on range query in RestMLInferenceSearchRequestProcessorIT #3598

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,27 @@ public void setup() throws Exception {
+ " \"properties\": {\n"
+ " \"diary_embedding_size\": {\n"
+ " \"type\": \"keyword\"\n"
+ " },\n"
+ " \"diary_embedding_size_int\": {\n"
+ " \"type\": \"integer\"\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}";

String uploadDocumentRequestBodyDoc1 = "{\n"
+ " \"id\": 1,\n"
+ " \"diary\": [\"happy\",\"first day at school\"],\n"
+ " \"diary_embedding_size\": \"1536\",\n" // embedding size for ada model
+ " \"diary_embedding_size_int\": 1536,\n"
+ " \"weather\": \"rainy\"\n"
+ " }";

String uploadDocumentRequestBodyDoc2 = "{\n"
+ " \"id\": 2,\n"
+ " \"diary\": [\"bored\",\"at home\"],\n"
+ " \"diary_embedding_size\": \"768\",\n" // embedding size for local text embedding model
+ " \"diary_embedding_size_int\": 768,\n"
+ " \"weather\": \"sunny\"\n"
+ " }";

Expand Down Expand Up @@ -389,7 +395,7 @@ public void testMLInferenceProcessorRemoteModelOptionalInputs() throws Exception
+ " \"model_id\": \""
+ this.bedrockMultiModalEmbeddingModelId
+ "\",\n"
+ " \"query_template\": \"{\\\"size\\\": 2,\\\"query\\\": {\\\"range\\\": {\\\"diary_embedding_size\\\": {\\\"gte\\\": ${modelPrediction}}}}}\",\n"
+ " \"query_template\": \"{\\\"size\\\": 2,\\\"query\\\": {\\\"range\\\": {\\\"diary_embedding_size_int\\\": {\\\"gte\\\": ${modelPrediction}}}}}\",\n"
+ " \"optional_input_map\": [\n"
+ " {\n"
+ " \"inputText\": \"query.term.diary.value\",\n"
Expand All @@ -415,9 +421,8 @@ public void testMLInferenceProcessorRemoteModelOptionalInputs() throws Exception
createSearchPipelineProcessor(createPipelineRequestBody, pipelineName);

Map response = searchWithPipeline(client(), index_name, pipelineName, query);

assertEquals((int) JsonPath.parse(response).read("$.hits.hits.length()"), 1);
Assert.assertEquals(JsonPath.parse(response).read("$.hits.hits[0]._source.diary_embedding_size"), "1536");
assertEquals((double) JsonPath.parse(response).read("$.hits.hits[0]._source.diary_embedding_size_int"), 1536.0, 0.0001);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package org.opensearch.ml.rest;

import static org.junit.Assert.assertEquals;
import static org.opensearch.ml.common.MLModel.MODEL_ID_FIELD;
import static org.opensearch.ml.utils.TestData.SENTENCE_TRANSFORMER_MODEL_URL;
import static org.opensearch.ml.utils.TestHelper.makeRequest;
Expand Down Expand Up @@ -439,7 +438,7 @@ public void testMLInferenceProcessorRemoteModelOptionalInputs() throws Exception
return;
}
String createPipelineRequestBody = "{\n"
+ " \"response\": [\n"
+ " \"response_processors\": [\n"
+ " {\n"
+ " \"ml_inference\": {\n"
+ " \"tag\": \"ml_inference\",\n"
Expand All @@ -449,7 +448,7 @@ public void testMLInferenceProcessorRemoteModelOptionalInputs() throws Exception
+ "\",\n"
+ " \"optional_input_map\": [\n"
+ " {\n"
+ " \"inputText\": \"diary\",\n"
+ " \"inputText\": \"diary[0]\",\n"
+ " \"inputImage\": \"diary_image\"\n"
+ " }\n"
+ " ],\n"
Expand All @@ -474,7 +473,7 @@ public void testMLInferenceProcessorRemoteModelOptionalInputs() throws Exception
Map response = searchWithPipeline(client(), index_name, pipelineName, query);

assertEquals((int) JsonPath.parse(response).read("$.hits.hits.length()"), 1);
Assert.assertEquals(JsonPath.parse(response).read("$.hits.hits[0]._source.multi_modal_embedding.length()"), "1024");
assertEquals((int) JsonPath.parse(response).read("$.hits.hits[0]._source.multi_modal_embedding.length()"), 1024);
}

/**
Expand Down
Loading