-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.x' into backport/backport-820-to-2.x
- Loading branch information
Showing
9 changed files
with
232 additions
and
1 deletion.
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
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
65 changes: 65 additions & 0 deletions
65
...pgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseTwoPhaseProcessorIT.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,65 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.bwc; | ||
|
||
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 AbstractRestartUpgradeRestTestCase { | ||
|
||
private static final String NEURAL_SPARSE_INGEST_PIPELINE_NAME = "nstp-nlp-ingest-pipeline-dense"; | ||
private static final String NEURAL_SPARSE_TWO_PHASE_SEARCH_PIPELINE_NAME = "nstp-nlp-two-phase-search-pipeline-sparse"; | ||
private static final String TEST_ENCODING_FIELD = "passage_embedding"; | ||
private static final String TEST_TEXT_FIELD = "passage_text"; | ||
private static final String TEXT_1 = "Hello world a b"; | ||
|
||
public void testNeuralSparseQueryTwoPhaseProcessor_NeuralSearch_E2EFlow() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
NeuralSparseQueryBuilder neuralSparseQueryBuilder = new NeuralSparseQueryBuilder().fieldName(TEST_ENCODING_FIELD).queryText(TEXT_1); | ||
if (isRunningAgainstOldCluster()) { | ||
String modelId = uploadSparseEncodingModel(); | ||
loadModel(modelId); | ||
neuralSparseQueryBuilder.modelId(modelId); | ||
createPipelineForSparseEncodingProcessor(modelId, NEURAL_SPARSE_INGEST_PIPELINE_NAME); | ||
createIndexWithConfiguration( | ||
getIndexNameForTest(), | ||
Files.readString(Path.of(classLoader.getResource("processor/SparseIndexMappings.json").toURI())), | ||
NEURAL_SPARSE_INGEST_PIPELINE_NAME | ||
); | ||
addSparseEncodingDoc(getIndexNameForTest(), "0", List.of(), List.of(), List.of(TEST_TEXT_FIELD), List.of(TEXT_1)); | ||
createNeuralSparseTwoPhaseSearchProcessor(NEURAL_SPARSE_TWO_PHASE_SEARCH_PIPELINE_NAME); | ||
updateIndexSettings( | ||
getIndexNameForTest(), | ||
Settings.builder().put("index.search.default_pipeline", NEURAL_SPARSE_TWO_PHASE_SEARCH_PIPELINE_NAME) | ||
); | ||
Object resultWith2PhasePipeline = search(getIndexNameForTest(), neuralSparseQueryBuilder, 1).get("hits"); | ||
assertNotNull(resultWith2PhasePipeline); | ||
} else { | ||
String modelId = null; | ||
try { | ||
modelId = TestUtils.getModelId(getIngestionPipeline(NEURAL_SPARSE_INGEST_PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); | ||
loadModel(modelId); | ||
neuralSparseQueryBuilder.modelId(modelId); | ||
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 | ||
); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...tart-upgrade/src/test/resources/processor/NeuralSparseTwoPhaseProcessorConfiguration.json
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,16 @@ | ||
{ | ||
"request_processors": [ | ||
{ | ||
"neural_sparse_two_phase_processor": { | ||
"tag": "neural-sparse", | ||
"description": "This processor is making two-phase rescorer.", | ||
"enabled": true, | ||
"two_phase_parameter": { | ||
"prune_ratio": %f, | ||
"expansion_rate": %f, | ||
"max_window_size": %d | ||
} | ||
} | ||
} | ||
] | ||
} |
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
78 changes: 78 additions & 0 deletions
78
...pgrade/src/test/java/org/opensearch/neuralsearch/bwc/NeuralSparseTwoPhaseProcessorIT.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,78 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.bwc; | ||
|
||
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 | ||
private static final String SPARSE_INGEST_PIPELINE_NAME = "nstp-nlp-ingest-pipeline-sparse"; | ||
private static final String SPARSE_SEARCH_TWO_PHASE_PIPELINE_NAME = "nstp-nlp-two-phase-search-pipeline-sparse"; | ||
private static final String TEST_ENCODING_FIELD = "passage_embedding"; | ||
private static final String TEST_TEXT_FIELD = "passage_text"; | ||
private static final String TEXT_1 = "Hello world a b"; | ||
private String sparseModelId = ""; | ||
|
||
// test of NeuralSparseTwoPhaseProcessor supports neural_sparse query's two phase speed up | ||
// the feature is introduced from 2.15 | ||
public void testNeuralSparseTwoPhaseProcessorIT_NeuralSparseSearch_E2EFlow() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
// will set the model_id after we obtain the id | ||
NeuralSparseQueryBuilder neuralSparseQueryBuilder = new NeuralSparseQueryBuilder().fieldName(TEST_ENCODING_FIELD).queryText(TEXT_1); | ||
|
||
switch (getClusterType()) { | ||
case OLD: | ||
sparseModelId = uploadSparseEncodingModel(); | ||
loadModel(sparseModelId); | ||
neuralSparseQueryBuilder.modelId(sparseModelId); | ||
createPipelineForSparseEncodingProcessor(sparseModelId, SPARSE_INGEST_PIPELINE_NAME); | ||
createIndexWithConfiguration( | ||
getIndexNameForTest(), | ||
Files.readString(Path.of(classLoader.getResource("processor/SparseIndexMappings.json").toURI())), | ||
SPARSE_INGEST_PIPELINE_NAME | ||
); | ||
addSparseEncodingDoc(getIndexNameForTest(), "0", List.of(), List.of(), List.of(TEST_TEXT_FIELD), List.of(TEXT_1)); | ||
createNeuralSparseTwoPhaseSearchProcessor(SPARSE_SEARCH_TWO_PHASE_PIPELINE_NAME); | ||
updateIndexSettings( | ||
getIndexNameForTest(), | ||
Settings.builder().put("index.search.default_pipeline", SPARSE_SEARCH_TWO_PHASE_PIPELINE_NAME) | ||
); | ||
assertNotNull(search(getIndexNameForTest(), neuralSparseQueryBuilder, 1).get("hits")); | ||
break; | ||
case MIXED: | ||
sparseModelId = TestUtils.getModelId(getIngestionPipeline(SPARSE_INGEST_PIPELINE_NAME), SPARSE_ENCODING_PROCESSOR); | ||
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); | ||
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 | ||
); | ||
} | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected value: " + getClusterType()); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ling-upgrade/src/test/resources/processor/NeuralSparseTwoPhaseProcessorConfiguration.json
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,16 @@ | ||
{ | ||
"request_processors": [ | ||
{ | ||
"neural_sparse_two_phase_processor": { | ||
"tag": "neural-sparse", | ||
"description": "This processor is making two-phase rescorer.", | ||
"enabled": true, | ||
"two_phase_parameter": { | ||
"prune_ratio": %f, | ||
"expansion_rate": %f, | ||
"max_window_size": %d | ||
} | ||
} | ||
} | ||
] | ||
} |
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
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