diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/AbstractRestartUpgradeRestTestCase.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/AbstractRestartUpgradeRestTestCase.java index ca5a3e34e..0ada43f77 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/AbstractRestartUpgradeRestTestCase.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/AbstractRestartUpgradeRestTestCase.java @@ -8,6 +8,7 @@ import java.nio.file.Path; import java.util.Locale; import java.util.Optional; + import org.junit.Before; import org.opensearch.common.settings.Settings; import org.opensearch.neuralsearch.BaseNeuralSearchIT; @@ -16,6 +17,9 @@ import static org.opensearch.neuralsearch.util.TestUtils.RESTART_UPGRADE_OLD_CLUSTER; import static org.opensearch.neuralsearch.util.TestUtils.BWC_VERSION; import static org.opensearch.neuralsearch.util.TestUtils.generateModelId; + +import org.opensearch.neuralsearch.util.SparseEncodingModel; +import org.opensearch.neuralsearch.util.TextEmbeddingModel; import org.opensearch.test.rest.OpenSearchRestTestCase; public abstract class AbstractRestartUpgradeRestTestCase extends BaseNeuralSearchIT { @@ -61,9 +65,16 @@ protected final Optional getBWCVersion() { return Optional.ofNullable(System.getProperty(BWC_VERSION, null)); } - protected String uploadTextEmbeddingModel() throws Exception { - String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); - return registerModelGroupAndGetModelId(requestBody); + protected String getOrUploadTextEmbeddingModel() throws Exception { + TextEmbeddingModel textEmbeddingModel = TextEmbeddingModel.getInstance(); + String modelId = textEmbeddingModel.getModelId(); + if (modelId == null) { + String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); + String id = registerModelGroupAndGetModelId(requestBody); + textEmbeddingModel.setModelId(id); + return id; + } + return modelId; } protected String registerModelGroupAndGetModelId(final String requestBody) throws Exception { @@ -79,11 +90,18 @@ protected void createPipelineProcessor(final String modelId, final String pipeli createPipelineProcessor(requestBody, pipelineName, modelId, null); } - protected String uploadSparseEncodingModel() throws Exception { - String requestBody = Files.readString( - Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI()) - ); - return registerModelGroupAndGetModelId(requestBody); + protected String getOrUploadSparseEncodingModel() throws Exception { + SparseEncodingModel sparseEncodingModel = SparseEncodingModel.getInstance(); + String modelId = sparseEncodingModel.getModelId(); + if (modelId == null) { + String requestBody = Files.readString( + Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI()) + ); + String id = registerModelGroupAndGetModelId(requestBody); + sparseEncodingModel.setModelId(id); + return id; + } + return modelId; } protected void createPipelineForTextImageProcessor(final String modelId, final String pipelineName) throws Exception { diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/BatchIngestionIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/BatchIngestionIT.java index 7fa0b1301..4e90fd6f7 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/BatchIngestionIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/BatchIngestionIT.java @@ -25,7 +25,7 @@ public void testBatchIngestionWithNeuralSparseProcessor_E2EFlow() throws Excepti waitForClusterHealthGreen(NODES_BWC_CLUSTER); String indexName = getIndexNameForTest(); if (isRunningAgainstOldCluster()) { - String modelId = uploadSparseEncodingModel(); + String modelId = getOrUploadSparseEncodingModel(); loadModel(modelId); createPipelineForSparseEncodingProcessor(modelId, PIPELINE_NAME, batchSize); createIndexWithConfiguration( @@ -45,7 +45,7 @@ public void testBatchIngestionWithNeuralSparseProcessor_E2EFlow() throws Excepti bulkAddDocuments(indexName, TEXT_FIELD_NAME, PIPELINE_NAME, docs); validateDocCountAndInfo(indexName, 10, () -> getDocById(indexName, "9"), EMBEDDING_FIELD_NAME, Map.class); } finally { - wipeOfTestResources(indexName, PIPELINE_NAME, modelId, null); + // wipeOfTestResources(indexName, PIPELINE_NAME, null, null); } } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchIT.java index d08d208da..16cd7117e 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchIT.java @@ -13,16 +13,16 @@ import org.opensearch.index.query.MatchQueryBuilder; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; import static org.opensearch.neuralsearch.util.TestUtils.PARAM_NAME_WEIGHTS; -import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; import static org.opensearch.neuralsearch.util.TestUtils.DEFAULT_NORMALIZATION_METHOD; import static org.opensearch.neuralsearch.util.TestUtils.DEFAULT_COMBINATION_METHOD; +import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; import org.opensearch.knn.index.query.rescore.RescoreContext; import org.opensearch.neuralsearch.query.HybridQueryBuilder; import org.opensearch.neuralsearch.query.NeuralQueryBuilder; +import org.opensearch.neuralsearch.util.TestUtils; public class HybridSearchIT extends AbstractRestartUpgradeRestTestCase { private static final String PIPELINE_NAME = "nlp-hybrid-pipeline"; @@ -56,7 +56,7 @@ private void validateNormalizationProcessor(final String fileName, final String throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = getOrUploadTextEmbeddingModel(); loadModel(modelId); createPipelineProcessor(modelId, pipelineName); createIndexWithConfiguration( @@ -69,7 +69,7 @@ private void validateNormalizationProcessor(final String fileName, final String } else { String modelId = null; try { - modelId = getModelId(getIngestionPipeline(pipelineName), TEXT_EMBEDDING_PROCESSOR); + modelId = TestUtils.getModelId(getIngestionPipeline(pipelineName), TEXT_EMBEDDING_PROCESSOR); loadModel(modelId); addDocuments(getIndexNameForTest(), false); HybridQueryBuilder hybridQueryBuilder = getQueryBuilder(modelId, null, null, null); @@ -77,7 +77,7 @@ private void validateNormalizationProcessor(final String fileName, final String hybridQueryBuilder = getQueryBuilder(modelId, Boolean.FALSE, Map.of("ef_search", 100), RescoreContext.getDefault()); validateTestIndex(getIndexNameForTest(), searchPipelineName, hybridQueryBuilder); } finally { - wipeOfTestResources(getIndexNameForTest(), pipelineName, modelId, searchPipelineName); + // wipeOfTestResources(getIndexNameForTest(), pipelineName, null, searchPipelineName); } } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchWithRescoreIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchWithRescoreIT.java index 9329a934b..798123298 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchWithRescoreIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/HybridSearchWithRescoreIT.java @@ -16,7 +16,6 @@ import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; import static org.opensearch.neuralsearch.util.TestUtils.PARAM_NAME_WEIGHTS; import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.index.query.QueryBuilder; @@ -24,6 +23,7 @@ import org.opensearch.knn.index.query.rescore.RescoreContext; import org.opensearch.neuralsearch.query.HybridQueryBuilder; import org.opensearch.neuralsearch.query.NeuralQueryBuilder; +import org.opensearch.neuralsearch.util.TestUtils; public class HybridSearchWithRescoreIT extends AbstractRestartUpgradeRestTestCase { private static final String PIPELINE_NAME = "nlp-hybrid-with-rescore-pipeline"; @@ -43,7 +43,7 @@ public void testHybridQueryWithRescore_whenIndexWithMultipleShards_E2EFlow() thr waitForClusterHealthGreen(NODES_BWC_CLUSTER); if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = getOrUploadTextEmbeddingModel(); loadModel(modelId); createPipelineProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -61,7 +61,8 @@ public void testHybridQueryWithRescore_whenIndexWithMultipleShards_E2EFlow() thr } else { String modelId = null; try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TestUtils.getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + ; loadModel(modelId); addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_UPGRADED, null, null); HybridQueryBuilder hybridQueryBuilder = getQueryBuilder(modelId, null, null); @@ -70,7 +71,7 @@ public void testHybridQueryWithRescore_whenIndexWithMultipleShards_E2EFlow() thr hybridQueryBuilder = getQueryBuilder(modelId, Map.of("ef_search", 100), RescoreContext.getDefault()); validateTestIndex(getIndexNameForTest(), hybridQueryBuilder, rescorer); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + // wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/KnnRadialSearchIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/KnnRadialSearchIT.java index 2e3ac34ab..14766f665 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/KnnRadialSearchIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/KnnRadialSearchIT.java @@ -8,9 +8,10 @@ import java.nio.file.Path; import java.util.Map; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.TEXT_IMAGE_EMBEDDING_PROCESSOR; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; +import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; + import org.opensearch.neuralsearch.query.NeuralQueryBuilder; +import org.opensearch.neuralsearch.util.TestUtils; public class KnnRadialSearchIT extends AbstractRestartUpgradeRestTestCase { private static final String PIPELINE_NAME = "radial-search-pipeline"; @@ -28,7 +29,7 @@ public void testKnnRadialSearch_E2EFlow() throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = getOrUploadTextEmbeddingModel(); loadModel(modelId); createPipelineForTextImageProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -40,12 +41,13 @@ public void testKnnRadialSearch_E2EFlow() throws Exception { } else { String modelId = null; try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_EMBEDDING_PROCESSOR); + modelId = TestUtils.getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + ; loadModel(modelId); addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_1, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT_1); validateIndexQuery(modelId); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + // wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/MultiModalSearchIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/MultiModalSearchIT.java index df3f8e94e..9f492ad44 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/MultiModalSearchIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/MultiModalSearchIT.java @@ -10,6 +10,7 @@ import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; import static org.opensearch.neuralsearch.util.TestUtils.TEXT_IMAGE_EMBEDDING_PROCESSOR; import static org.opensearch.neuralsearch.util.TestUtils.getModelId; + import org.opensearch.neuralsearch.query.NeuralQueryBuilder; public class MultiModalSearchIT extends AbstractRestartUpgradeRestTestCase { @@ -28,7 +29,7 @@ public void testTextImageEmbeddingProcessor_E2EFlow() throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = getOrUploadTextEmbeddingModel(); loadModel(modelId); createPipelineForTextImageProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -45,7 +46,7 @@ public void testTextImageEmbeddingProcessor_E2EFlow() throws Exception { addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_1, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT_1); validateTestIndex(modelId); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + // wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralQueryEnricherProcessorIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralQueryEnricherProcessorIT.java index 97182bfa0..39ca83374 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralQueryEnricherProcessorIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralQueryEnricherProcessorIT.java @@ -9,9 +9,9 @@ import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; import org.opensearch.common.settings.Settings; -import org.opensearch.neuralsearch.util.TestUtils; import org.opensearch.neuralsearch.query.NeuralQueryBuilder; import org.opensearch.neuralsearch.query.NeuralSparseQueryBuilder; +import org.opensearch.neuralsearch.util.TestUtils; import java.nio.file.Files; import java.nio.file.Path; @@ -37,7 +37,7 @@ public void testNeuralQueryEnricherProcessor_NeuralSparseSearch_E2EFlow() throws .queryText(TEXT_1); if (isRunningAgainstOldCluster()) { - String modelId = uploadSparseEncodingModel(); + String modelId = getOrUploadSparseEncodingModel(); loadModel(modelId); sparseEncodingQueryBuilderWithModelId.modelId(modelId); createPipelineForSparseEncodingProcessor(modelId, SPARSE_INGEST_PIPELINE_NAME); @@ -69,7 +69,7 @@ public void testNeuralQueryEnricherProcessor_NeuralSparseSearch_E2EFlow() throws search(getIndexNameForTest(), sparseEncodingQueryBuilderWithModelId, 1).get("hits") ); } finally { - wipeOfTestResources(getIndexNameForTest(), SPARSE_INGEST_PIPELINE_NAME, modelId, SPARSE_SEARCH_PIPELINE_NAME); + // wipeOfTestResources(getIndexNameForTest(), SPARSE_INGEST_PIPELINE_NAME, null, SPARSE_SEARCH_PIPELINE_NAME); } } } @@ -86,7 +86,7 @@ public void testNeuralQueryEnricherProcessor_NeuralSearch_E2EFlow() throws Excep .build(); if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = getOrUploadTextEmbeddingModel(); loadModel(modelId); neuralQueryBuilderWithModelId.modelId(modelId); createPipelineProcessor(modelId, DENSE_INGEST_PIPELINE_NAME); diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseSearchIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseSearchIT.java index 5978f71ab..91c99ca19 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseSearchIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseSearchIT.java @@ -33,7 +33,7 @@ public class NeuralSparseSearchIT extends AbstractRestartUpgradeRestTestCase { public void testSparseEncodingProcessor_E2EFlow() throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); if (isRunningAgainstOldCluster()) { - String modelId = uploadSparseEncodingModel(); + String modelId = getOrUploadSparseEncodingModel(); loadModel(modelId); createPipelineForSparseEncodingProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -65,7 +65,7 @@ public void testSparseEncodingProcessor_E2EFlow() throws Exception { ); validateTestIndex(modelId); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + // wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseTwoPhaseProcessorIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseTwoPhaseProcessorIT.java index 6a6994809..c67c93b8f 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseTwoPhaseProcessorIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/NeuralSparseTwoPhaseProcessorIT.java @@ -27,7 +27,7 @@ public void testNeuralSparseQueryTwoPhaseProcessor_NeuralSearch_E2EFlow() throws waitForClusterHealthGreen(NODES_BWC_CLUSTER); NeuralSparseQueryBuilder neuralSparseQueryBuilder = new NeuralSparseQueryBuilder().fieldName(TEST_ENCODING_FIELD).queryText(TEXT_1); if (isRunningAgainstOldCluster()) { - String modelId = uploadSparseEncodingModel(); + String modelId = getOrUploadSparseEncodingModel(); loadModel(modelId); neuralSparseQueryBuilder.modelId(modelId); createPipelineForSparseEncodingProcessor(modelId, NEURAL_SPARSE_INGEST_PIPELINE_NAME); @@ -53,12 +53,12 @@ public void testNeuralSparseQueryTwoPhaseProcessor_NeuralSearch_E2EFlow() throws Object resultWith2PhasePipeline = search(getIndexNameForTest(), neuralSparseQueryBuilder, 1).get("hits"); assertNotNull(resultWith2PhasePipeline); } finally { - wipeOfTestResources( - getIndexNameForTest(), - NEURAL_SPARSE_INGEST_PIPELINE_NAME, - modelId, - NEURAL_SPARSE_TWO_PHASE_SEARCH_PIPELINE_NAME - ); + // wipeOfTestResources( + // getIndexNameForTest(), + // NEURAL_SPARSE_INGEST_PIPELINE_NAME, + // null, + // NEURAL_SPARSE_TWO_PHASE_SEARCH_PIPELINE_NAME + // ); } } } diff --git a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/SemanticSearchIT.java b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/SemanticSearchIT.java index 9dc35c02d..336d445e5 100644 --- a/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/SemanticSearchIT.java +++ b/qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/restart/SemanticSearchIT.java @@ -8,9 +8,10 @@ import java.nio.file.Path; import java.util.Map; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; + import org.opensearch.neuralsearch.query.NeuralQueryBuilder; +import org.opensearch.neuralsearch.util.TestUtils; public class SemanticSearchIT extends AbstractRestartUpgradeRestTestCase { @@ -24,9 +25,8 @@ public class SemanticSearchIT extends AbstractRestartUpgradeRestTestCase { // Validate process , pipeline and document count in restart-upgrade scenario public void testTextEmbeddingProcessor_E2EFlow() throws Exception { waitForClusterHealthGreen(NODES_BWC_CLUSTER); - if (isRunningAgainstOldCluster()) { - String modelId = uploadTextEmbeddingModel(); + String modelId = getOrUploadTextEmbeddingModel(); loadModel(modelId); createPipelineProcessor(modelId, PIPELINE_NAME); createIndexWithConfiguration( @@ -38,12 +38,12 @@ public void testTextEmbeddingProcessor_E2EFlow() throws Exception { } else { String modelId = null; try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TestUtils.getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); loadModel(modelId); addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_1, null, null); validateTestIndex(modelId); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + // wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } } } diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/AbstractRollingUpgradeTestCase.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/AbstractRollingUpgradeTestCase.java index a1ad7178c..9fe23c972 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/AbstractRollingUpgradeTestCase.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/AbstractRollingUpgradeTestCase.java @@ -8,6 +8,7 @@ import java.nio.file.Path; import java.util.Locale; import java.util.Optional; + import org.junit.Before; import org.opensearch.common.settings.Settings; import org.opensearch.neuralsearch.BaseNeuralSearchIT; @@ -75,6 +76,48 @@ public static ClusterType instance(String value) { } } + protected enum TextEmbeddingModel { + INSTANCE; + + private static String modelId; + + public static void setModelId(String id) { + modelId = id; + } + + public static String getModelId() { + return modelId; + } + } + + protected enum TextImageEmbeddingModel { + INSTANCE; + + private static String modelId; + + public static void setModelId(String id) { + modelId = id; + } + + public static String getModelId() { + return modelId; + } + } + + protected enum SparseEncodingModel { + INSTANCE; + + private static String modelId; + + public static void setModelId(String id) { + modelId = id; + } + + public static String getModelId() { + return modelId; + } + } + protected final ClusterType getClusterType() { return ClusterType.instance(System.getProperty(BWCSUITE_CLUSTER)); } @@ -88,8 +131,14 @@ protected final Optional getBWCVersion() { } protected String uploadTextEmbeddingModel() throws Exception { - String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); - return registerModelGroupAndGetModelId(requestBody); + String modelId = TextEmbeddingModel.getModelId(); + if (modelId == null) { + String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); + String id = registerModelGroupAndGetModelId(requestBody); + TextEmbeddingModel.setModelId(id); + return id; + } + return modelId; } protected String registerModelGroupAndGetModelId(String requestBody) throws Exception { @@ -106,8 +155,14 @@ protected void createPipelineProcessor(String modelId, String pipelineName) thro } protected String uploadTextImageEmbeddingModel() throws Exception { - String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); - return registerModelGroupAndGetModelId(requestBody); + String modelId = TextImageEmbeddingModel.getModelId(); + if (modelId == null) { + String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); + String id = registerModelGroupAndGetModelId(requestBody); + TextImageEmbeddingModel.setModelId(id); + return id; + } + return modelId; } protected void createPipelineForTextImageProcessor(String modelId, String pipelineName) throws Exception { @@ -118,10 +173,16 @@ protected void createPipelineForTextImageProcessor(String modelId, String pipeli } protected String uploadSparseEncodingModel() throws Exception { - String requestBody = Files.readString( - Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI()) - ); - return registerModelGroupAndGetModelId(requestBody); + String modelId = SparseEncodingModel.getModelId(); + if (modelId == null) { + String requestBody = Files.readString( + Path.of(classLoader.getResource("processor/UploadSparseEncodingModelRequestBody.json").toURI()) + ); + String id = registerModelGroupAndGetModelId(requestBody); + SparseEncodingModel.setModelId(id); + return id; + } + return modelId; } protected void createPipelineForSparseEncodingProcessor(String modelId, String pipelineName, Integer batchSize) throws Exception { diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/BatchIngestionIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/BatchIngestionIT.java index 01fce83f0..201d64880 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/BatchIngestionIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/BatchIngestionIT.java @@ -4,8 +4,6 @@ */ package org.opensearch.neuralsearch.bwc.rolling; -import org.opensearch.neuralsearch.util.TestUtils; - import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -13,7 +11,6 @@ import static org.opensearch.neuralsearch.util.BatchIngestionUtils.prepareDataForBulkIngestion; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.SPARSE_ENCODING_PROCESSOR; public class BatchIngestionIT extends AbstractRollingUpgradeTestCase { private static final String SPARSE_PIPELINE = "BatchIngestionIT_sparse_pipeline_rolling"; @@ -39,7 +36,7 @@ public void testBatchIngestion_SparseEncodingProcessor_E2EFlow() throws Exceptio validateDocCountAndInfo(indexName, 5, () -> getDocById(indexName, "4"), EMBEDDING_FIELD_NAME, Map.class); break; case MIXED: - sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_PIPELINE), SPARSE_ENCODING_PROCESSOR); + sparseModelId = SparseEncodingModel.getModelId(); loadModel(sparseModelId); List> docsForMixed = prepareDataForBulkIngestion(5, 5); bulkAddDocuments(indexName, TEXT_FIELD_NAME, SPARSE_PIPELINE, docsForMixed); @@ -47,13 +44,13 @@ public void testBatchIngestion_SparseEncodingProcessor_E2EFlow() throws Exceptio break; case UPGRADED: try { - sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_PIPELINE), SPARSE_ENCODING_PROCESSOR); + sparseModelId = SparseEncodingModel.getModelId(); loadModel(sparseModelId); List> docsForUpgraded = prepareDataForBulkIngestion(10, 5); bulkAddDocuments(indexName, TEXT_FIELD_NAME, SPARSE_PIPELINE, docsForUpgraded); validateDocCountAndInfo(indexName, 15, () -> getDocById(indexName, "14"), EMBEDDING_FIELD_NAME, Map.class); } finally { - wipeOfTestResources(indexName, SPARSE_PIPELINE, sparseModelId, null); + wipeOfTestResources(indexName, SPARSE_PIPELINE, null, null); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchIT.java index de7ddef55..22721732d 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchIT.java @@ -14,10 +14,8 @@ import org.opensearch.index.query.MatchQueryBuilder; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; import static org.opensearch.neuralsearch.util.TestUtils.PARAM_NAME_WEIGHTS; -import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; import static org.opensearch.neuralsearch.util.TestUtils.DEFAULT_NORMALIZATION_METHOD; import static org.opensearch.neuralsearch.util.TestUtils.DEFAULT_COMBINATION_METHOD; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import org.opensearch.index.query.QueryBuilder; import org.opensearch.knn.index.query.rescore.RescoreContext; @@ -62,7 +60,7 @@ public void testNormalizationProcessor_whenIndexWithMultipleShards_E2EFlow() thr ); break; case MIXED: - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TextEmbeddingModel.getModelId(); int totalDocsCountMixed; if (isFirstMixedRound()) { totalDocsCountMixed = NUM_DOCS_PER_ROUND; @@ -77,7 +75,7 @@ public void testNormalizationProcessor_whenIndexWithMultipleShards_E2EFlow() thr break; case UPGRADED: try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TextEmbeddingModel.getModelId(); int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND; loadModel(modelId); addDocument(getIndexNameForTest(), "2", TEST_FIELD, TEXT_UPGRADED, null, null); @@ -86,7 +84,7 @@ public void testNormalizationProcessor_whenIndexWithMultipleShards_E2EFlow() thr hybridQueryBuilder = getQueryBuilder(modelId, Boolean.FALSE, Map.of("ef_search", 100), RescoreContext.getDefault()); validateTestIndexOnUpgrade(totalDocsCountUpgraded, modelId, hybridQueryBuilder, null); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, SEARCH_PIPELINE_NAME); + wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, SEARCH_PIPELINE_NAME); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchWithRescoreIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchWithRescoreIT.java index 3cea2400d..a212bc063 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchWithRescoreIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/HybridSearchWithRescoreIT.java @@ -20,10 +20,8 @@ import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; import static org.opensearch.neuralsearch.util.TestUtils.PARAM_NAME_WEIGHTS; -import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; import static org.opensearch.neuralsearch.util.TestUtils.DEFAULT_NORMALIZATION_METHOD; import static org.opensearch.neuralsearch.util.TestUtils.DEFAULT_COMBINATION_METHOD; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; public class HybridSearchWithRescoreIT extends AbstractRollingUpgradeTestCase { @@ -63,7 +61,7 @@ public void testHybridQueryWithRescore_whenIndexWithMultipleShards_E2EFlow() thr ); break; case MIXED: - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TextImageEmbeddingModel.getModelId(); int totalDocsCountMixed; if (isFirstMixedRound()) { totalDocsCountMixed = NUM_DOCS_PER_ROUND; @@ -79,7 +77,7 @@ public void testHybridQueryWithRescore_whenIndexWithMultipleShards_E2EFlow() thr break; case UPGRADED: try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TextImageEmbeddingModel.getModelId(); int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND; loadModel(modelId); addDocument(getIndexNameForTest(), "2", TEST_FIELD, TEXT_UPGRADED, null, null); @@ -89,7 +87,7 @@ public void testHybridQueryWithRescore_whenIndexWithMultipleShards_E2EFlow() thr hybridQueryBuilder = getQueryBuilder(modelId, Map.of("ef_search", 100), RescoreContext.getDefault()); validateTestIndexOnUpgrade(totalDocsCountUpgraded, modelId, hybridQueryBuilder, rescorer); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, SEARCH_PIPELINE_NAME); + wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, SEARCH_PIPELINE_NAME); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/KnnRadialSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/KnnRadialSearchIT.java index e9fb1a4a7..e760dae16 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/KnnRadialSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/KnnRadialSearchIT.java @@ -44,7 +44,7 @@ public void testKnnRadialSearch_E2EFlow() throws Exception { addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT); break; case MIXED: - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_EMBEDDING_PROCESSOR); + modelId = TextImageEmbeddingModel.getModelId(); int totalDocsCountMixed; if (isFirstMixedRound()) { totalDocsCountMixed = NUM_DOCS_PER_ROUND; @@ -63,7 +63,7 @@ public void testKnnRadialSearch_E2EFlow() throws Exception { addDocument(getIndexNameForTest(), "2", TEST_FIELD, TEXT_UPGRADED, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT_UPGRADED); validateIndexQueryOnUpgrade(totalDocsCountUpgraded, modelId, TEXT_UPGRADED, TEST_IMAGE_TEXT_UPGRADED); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/MultiModalSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/MultiModalSearchIT.java index 6ced20d95..e38828fec 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/MultiModalSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/MultiModalSearchIT.java @@ -8,8 +8,6 @@ import java.nio.file.Path; import java.util.Map; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.TEXT_IMAGE_EMBEDDING_PROCESSOR; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import org.opensearch.neuralsearch.query.NeuralQueryBuilder; public class MultiModalSearchIT extends AbstractRollingUpgradeTestCase { @@ -44,7 +42,7 @@ public void testTextImageEmbeddingProcessor_E2EFlow() throws Exception { addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT); break; case MIXED: - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_EMBEDDING_PROCESSOR); + modelId = TextImageEmbeddingModel.getModelId(); int totalDocsCountMixed; if (isFirstMixedRound()) { totalDocsCountMixed = NUM_DOCS_PER_ROUND; @@ -57,13 +55,13 @@ public void testTextImageEmbeddingProcessor_E2EFlow() throws Exception { break; case UPGRADED: try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_EMBEDDING_PROCESSOR); + modelId = TextImageEmbeddingModel.getModelId(); int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND; loadModel(modelId); addDocument(getIndexNameForTest(), "2", TEST_FIELD, TEXT_UPGRADED, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT_UPGRADED); validateTestIndexOnUpgrade(totalDocsCountUpgraded, modelId, TEXT_UPGRADED, TEST_IMAGE_TEXT_UPGRADED); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralQueryEnricherProcessorIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralQueryEnricherProcessorIT.java index e22e65e4a..4f22cb09d 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralQueryEnricherProcessorIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralQueryEnricherProcessorIT.java @@ -14,7 +14,6 @@ import java.util.List; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.SPARSE_ENCODING_PROCESSOR; import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; public class NeuralQueryEnricherProcessorIT extends AbstractRollingUpgradeTestCase { @@ -63,7 +62,7 @@ public void testNeuralQueryEnricherProcessor_NeuralSparseSearch_E2EFlow() throws ); break; case MIXED: - sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_INGEST_PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); + sparseModelId = SparseEncodingModel.getModelId(); loadModel(sparseModelId); sparseEncodingQueryBuilderWithModelId.modelId(sparseModelId); @@ -74,7 +73,7 @@ public void testNeuralQueryEnricherProcessor_NeuralSparseSearch_E2EFlow() throws break; case UPGRADED: try { - sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_INGEST_PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); + sparseModelId = SparseEncodingModel.getModelId(); loadModel(sparseModelId); sparseEncodingQueryBuilderWithModelId.modelId(sparseModelId); assertEquals( @@ -82,7 +81,7 @@ public void testNeuralQueryEnricherProcessor_NeuralSparseSearch_E2EFlow() throws search(getIndexNameForTest(), sparseEncodingQueryBuilderWithModelId, 1).get("hits") ); } finally { - wipeOfTestResources(getIndexNameForTest(), SPARSE_INGEST_PIPELINE_NAME, sparseModelId, SPARSE_SEARCH_PIPELINE_NAME); + wipeOfTestResources(getIndexNameForTest(), SPARSE_INGEST_PIPELINE_NAME, null, SPARSE_SEARCH_PIPELINE_NAME); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseSearchIT.java index 8cebae4a2..c8bb90abe 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseSearchIT.java @@ -12,9 +12,7 @@ import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.neuralsearch.util.TestUtils; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.SPARSE_ENCODING_PROCESSOR; import static org.opensearch.neuralsearch.util.TestUtils.objectToFloat; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import org.opensearch.neuralsearch.query.NeuralSparseQueryBuilder; public class NeuralSparseSearchIT extends AbstractRollingUpgradeTestCase { @@ -59,7 +57,7 @@ public void testSparseEncodingProcessor_E2EFlow() throws Exception { ); break; case MIXED: - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); + modelId = SparseEncodingModel.getModelId(); int totalDocsCountMixed; if (isFirstMixedRound()) { totalDocsCountMixed = NUM_DOCS_PER_ROUND; @@ -79,7 +77,7 @@ public void testSparseEncodingProcessor_E2EFlow() throws Exception { break; case UPGRADED: try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); + modelId = SparseEncodingModel.getModelId(); int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND; loadModel(modelId); addSparseEncodingDoc( @@ -92,7 +90,7 @@ public void testSparseEncodingProcessor_E2EFlow() throws Exception { ); validateTestIndexOnUpgrade(totalDocsCountUpgraded, modelId); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseTwoPhaseProcessorIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseTwoPhaseProcessorIT.java index 5338b777f..632083362 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseTwoPhaseProcessorIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/NeuralSparseTwoPhaseProcessorIT.java @@ -6,14 +6,12 @@ import org.opensearch.common.settings.Settings; import org.opensearch.neuralsearch.query.NeuralSparseQueryBuilder; -import org.opensearch.neuralsearch.util.TestUtils; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.SPARSE_ENCODING_PROCESSOR; public class NeuralSparseTwoPhaseProcessorIT extends AbstractRollingUpgradeTestCase { // add prefix to avoid conflicts with other IT class, since don't wipe resources after first round @@ -51,24 +49,19 @@ public void testNeuralSparseTwoPhaseProcessorIT_NeuralSparseSearch_E2EFlow() thr assertNotNull(search(getIndexNameForTest(), neuralSparseQueryBuilder, 1).get("hits")); break; case MIXED: - sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_INGEST_PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); + sparseModelId = SparseEncodingModel.getModelId(); loadModel(sparseModelId); neuralSparseQueryBuilder.modelId(sparseModelId); assertNotNull(search(getIndexNameForTest(), neuralSparseQueryBuilder, 1).get("hits")); break; case UPGRADED: try { - sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_INGEST_PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); + sparseModelId = SparseEncodingModel.getModelId(); loadModel(sparseModelId); neuralSparseQueryBuilder.modelId(sparseModelId); assertNotNull(search(getIndexNameForTest(), neuralSparseQueryBuilder, 1).get("hits")); } finally { - wipeOfTestResources( - getIndexNameForTest(), - SPARSE_INGEST_PIPELINE_NAME, - sparseModelId, - SPARSE_SEARCH_TWO_PHASE_PIPELINE_NAME - ); + wipeOfTestResources(getIndexNameForTest(), SPARSE_INGEST_PIPELINE_NAME, null, SPARSE_SEARCH_TWO_PHASE_PIPELINE_NAME); } break; default: diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/SemanticSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/SemanticSearchIT.java index 989d53897..d5304152e 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/SemanticSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/rolling/SemanticSearchIT.java @@ -8,8 +8,6 @@ import java.nio.file.Path; import java.util.Map; import static org.opensearch.neuralsearch.util.TestUtils.NODES_BWC_CLUSTER; -import static org.opensearch.neuralsearch.util.TestUtils.TEXT_EMBEDDING_PROCESSOR; -import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import org.opensearch.neuralsearch.query.NeuralQueryBuilder; public class SemanticSearchIT extends AbstractRollingUpgradeTestCase { @@ -39,7 +37,7 @@ public void testSemanticSearch_E2EFlow() throws Exception { addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT, null, null); break; case MIXED: - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TextEmbeddingModel.getModelId(); int totalDocsCountMixed; if (isFirstMixedRound()) { totalDocsCountMixed = NUM_DOCS_PER_ROUND; @@ -52,13 +50,13 @@ public void testSemanticSearch_E2EFlow() throws Exception { break; case UPGRADED: try { - modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_EMBEDDING_PROCESSOR); + modelId = TextEmbeddingModel.getModelId(); int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND; loadModel(modelId); addDocument(getIndexNameForTest(), "2", TEST_FIELD, TEXT_UPGRADED, null, null); validateTestIndexOnUpgrade(totalDocsCountUpgraded, modelId, TEXT_UPGRADED); } finally { - wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, modelId, null); + wipeOfTestResources(getIndexNameForTest(), PIPELINE_NAME, null, null); } break; default: diff --git a/src/testFixtures/java/org/opensearch/neuralsearch/util/SparseEncodingModel.java b/src/testFixtures/java/org/opensearch/neuralsearch/util/SparseEncodingModel.java new file mode 100644 index 000000000..ceb72f788 --- /dev/null +++ b/src/testFixtures/java/org/opensearch/neuralsearch/util/SparseEncodingModel.java @@ -0,0 +1,36 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.opensearch.neuralsearch.util; + +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +public class SparseEncodingModel { + private static SparseEncodingModel instance = null; + + public String modelId = null; + + private SparseEncodingModel() { + + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelId() { + return modelId; + } + + public static SparseEncodingModel getInstance() { + // To ensure only one instance is created + if (instance == null) { + instance = new SparseEncodingModel(); + } + return instance; + } +} diff --git a/src/testFixtures/java/org/opensearch/neuralsearch/util/TextEmbeddingModel.java b/src/testFixtures/java/org/opensearch/neuralsearch/util/TextEmbeddingModel.java new file mode 100644 index 000000000..dc37ffbf6 --- /dev/null +++ b/src/testFixtures/java/org/opensearch/neuralsearch/util/TextEmbeddingModel.java @@ -0,0 +1,36 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.opensearch.neuralsearch.util; + +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +public class TextEmbeddingModel { + private static TextEmbeddingModel instance = null; + + public String modelId = null; + + private TextEmbeddingModel() { + + } + + public void setModelId(String modelId) { + this.modelId = modelId; + } + + public String getModelId() { + return modelId; + } + + public static TextEmbeddingModel getInstance() { + // To ensure only one instance is created + if (instance == null) { + instance = new TextEmbeddingModel(); + } + return instance; + } +}