From 494d9727ed775d8fcf6a55e52fb73ef3abbe056c Mon Sep 17 00:00:00 2001 From: Varun Jain Date: Wed, 10 Jan 2024 14:26:42 -0800 Subject: [PATCH] Fixing test Cases Signed-off-by: Varun Jain --- .../neuralsearch/bwc/NeuralSparseSearchIT.java | 10 ++++++---- .../processor/SparseIndexMappings.json | 2 +- .../UploadSparseEncodingModelRequestBody.json | 10 ++++++++++ .../neuralsearch/bwc/NeuralSparseSearchIT.java | 10 ++++++---- ...ForSparseEncodingProcessorConfiguration.json | 13 +++++++++++++ .../processor/SparseIndexMappings.json | 17 +++++++++++++++++ .../UploadSparseEncodingModelRequestBody.json | 10 ++++++++++ 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 qa/restart-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json create mode 100644 qa/rolling-upgrade/src/test/resources/processor/PipelineForSparseEncodingProcessorConfiguration.json create mode 100644 qa/rolling-upgrade/src/test/resources/processor/SparseIndexMappings.json create mode 100644 qa/rolling-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java index 5135306e1..210cca8e3 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java @@ -34,7 +34,7 @@ public class NeuralSparseSearchIT extends AbstractRestartUpgradeRestTestCase { public void testSparseEncodingProcessor_E2EFlow() throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = uploadSparseEncodingModel(); loadModel(modelId); createPipelineProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -84,13 +84,15 @@ private void validateTestIndex(String modelId) throws Exception { Map response = search(getIndexNameForTest(), boolQueryBuilder, 1); Map firstInnerHit = getFirstInnerHit(response); - assertEquals("1", firstInnerHit.get("_id")); + assertEquals("0", firstInnerHit.get("_id")); float minExpectedScore = computeExpectedScore(modelId, testRankFeaturesDoc1, TEXT_1); assertTrue(minExpectedScore < objectToFloat(firstInnerHit.get("_score"))); } - private String uploadTextEmbeddingModel() throws Exception { - String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); + private String uploadSparseEncodingModel() throws Exception { + String requestBody = Files.readString( + Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI()) + ); return registerModelGroupAndGetModelId(requestBody); } diff --git a/qa/restart-upgrade/src/test/resources/processor/SparseIndexMappings.json b/qa/restart-upgrade/src/test/resources/processor/SparseIndexMappings.json index 2628c6614..c3ec5951f 100644 --- a/qa/restart-upgrade/src/test/resources/processor/SparseIndexMappings.json +++ b/qa/restart-upgrade/src/test/resources/processor/SparseIndexMappings.json @@ -7,7 +7,7 @@ "mappings": { "properties": { "passage_embedding": { - "type": "knn_vector" + "type": "rank_features" }, "passage_text": { "type": "text" diff --git a/qa/restart-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json b/qa/restart-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json new file mode 100644 index 000000000..6ca51e50e --- /dev/null +++ b/qa/restart-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json @@ -0,0 +1,10 @@ +{ + "name": "tokenize-idf-0915", + "version": "1.0.0", + "function_name": "SPARSE_TOKENIZE", + "description": "test model", + "model_format": "TORCH_SCRIPT", + "model_group_id": "%s", + "model_content_hash_value": "b345e9e943b62c405a8dd227ef2c46c84c5ff0a0b71b584be9132b37bce91a9a", + "url": "https://github.com/opensearch-project/ml-commons/raw/main/ml-algorithms/src/test/resources/org/opensearch/ml/engine/algorithms/sparse_encoding/sparse_demo.zip" + } diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java index ef30fe7a7..f06e843b2 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseSearchIT.java @@ -40,7 +40,7 @@ public void testSparseEncodingProcessor_E2EFlow() throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); switch (getClusterType()) { case OLD: - String modelId = uploadTextEmbeddingModel(); + String modelId = uploadSparseEncodingModel(); loadModel(modelId); createPipelineProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -109,13 +109,15 @@ private void validateTestIndexOnUpgrade(int numberOfDocs, String modelId) throws Map response = search(getIndexNameForTest(), boolQueryBuilder, 1); Map firstInnerHit = getFirstInnerHit(response); - assertEquals("1", firstInnerHit.get("_id")); + assertEquals("0", firstInnerHit.get("_id")); float minExpectedScore = computeExpectedScore(modelId, testRankFeaturesDoc1, TEXT); assertTrue(minExpectedScore < objectToFloat(firstInnerHit.get("_score"))); } - private String uploadTextEmbeddingModel() throws Exception { - String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); + private String uploadSparseEncodingModel() throws Exception { + String requestBody = Files.readString( + Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI()) + ); return registerModelGroupAndGetModelId(requestBody); } diff --git a/qa/rolling-upgrade/src/test/resources/processor/PipelineForSparseEncodingProcessorConfiguration.json b/qa/rolling-upgrade/src/test/resources/processor/PipelineForSparseEncodingProcessorConfiguration.json new file mode 100644 index 000000000..d9a358c24 --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/PipelineForSparseEncodingProcessorConfiguration.json @@ -0,0 +1,13 @@ +{ + "description": "An sparse encoding ingest pipeline", + "processors": [ + { + "sparse_encoding": { + "model_id": "%s", + "field_map": { + "passage_text": "passage_embedding" + } + } + } + ] + } diff --git a/qa/rolling-upgrade/src/test/resources/processor/SparseIndexMappings.json b/qa/rolling-upgrade/src/test/resources/processor/SparseIndexMappings.json new file mode 100644 index 000000000..ffe2447c9 --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/SparseIndexMappings.json @@ -0,0 +1,17 @@ +{ + "settings": { + "default_pipeline": "%s", + "number_of_shards": 3, + "number_of_replicas": 1 + }, + "mappings": { + "properties": { + "passage_embedding": { + "type": "rank_features" + }, + "passage_text": { + "type": "text" + } + } + } +} diff --git a/qa/rolling-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json b/qa/rolling-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json new file mode 100644 index 000000000..f64439549 --- /dev/null +++ b/qa/rolling-upgrade/src/test/resources/processor/UploadSparseEncodingModelRequestBody.json @@ -0,0 +1,10 @@ +{ + "name": "tokenize-idf-0915", + "version": "1.0.0", + "function_name": "SPARSE_TOKENIZE", + "description": "test model", + "model_format": "TORCH_SCRIPT", + "model_group_id": "%s", + "model_content_hash_value": "b345e9e943b62c405a8dd227ef2c46c84c5ff0a0b71b584be9132b37bce91a9a", + "url": "https://github.com/opensearch-project/ml-commons/raw/main/ml-algorithms/src/test/resources/org/opensearch/ml/engine/algorithms/sparse_encoding/sparse_demo.zip" +}