forked from opensearch-project/neural-search
-
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.
Signed-off-by: Junqiu Lei <[email protected]>
- Loading branch information
1 parent
5f3a1c1
commit c09945f
Showing
7 changed files
with
223 additions
and
61 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
82 changes: 82 additions & 0 deletions
82
qa/restart-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/KnnRadialSearchIT.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,82 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.bwc; | ||
|
||
import java.nio.file.Files; | ||
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 KnnRadialSearchIT extends AbstractRestartUpgradeRestTestCase { | ||
private static final String PIPELINE_NAME = "nlp-ingest-pipeline"; | ||
private static final String TEST_FIELD = "passage_text"; | ||
private static final String TEST_IMAGE_FIELD = "passage_image"; | ||
private static final String TEXT = "Hello world"; | ||
private static final String TEXT_1 = "Hello world a"; | ||
private static final String TEST_IMAGE_TEXT = "/9j/4AAQSkZJRgABAQAASABIAAD"; | ||
private static final String TEST_IMAGE_TEXT_1 = "/9j/4AAQSkZJRgbdwoeicfhoid"; | ||
|
||
// Test rolling-upgrade with kNN radial search | ||
// Create Text Image Embedding Processor, Ingestion Pipeline and add document | ||
// Validate radial query, pipeline and document count in restart-upgrade scenario | ||
public void testKnnRadialSearch_E2EFlow() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
|
||
if (isRunningAgainstOldCluster()) { | ||
String modelId = uploadTextEmbeddingModel(); | ||
loadModel(modelId); | ||
createPipelineForTextImageProcessor(modelId, PIPELINE_NAME); | ||
createIndexWithConfiguration( | ||
getIndexNameForTest(), | ||
Files.readString(Path.of(classLoader.getResource("processor/IndexMappingMultipleShard.json").toURI())), | ||
PIPELINE_NAME | ||
); | ||
addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT); | ||
} else { | ||
String modelId = null; | ||
try { | ||
modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_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); | ||
} | ||
} | ||
} | ||
|
||
private void validateIndexQuery(final String modelId) { | ||
NeuralQueryBuilder neuralQueryBuilderWithMinScoreQuery = new NeuralQueryBuilder( | ||
"passage_embedding", | ||
TEXT, | ||
TEST_IMAGE_TEXT, | ||
modelId, | ||
null, | ||
null, | ||
0.01f, | ||
null, | ||
null | ||
); | ||
Map<String, Object> responseWithMinScoreQuery = search(getIndexNameForTest(), neuralQueryBuilderWithMinScoreQuery, 1); | ||
assertNotNull(responseWithMinScoreQuery); | ||
|
||
NeuralQueryBuilder neuralQueryBuilderWithMaxDistanceQuery = new NeuralQueryBuilder( | ||
"passage_embedding", | ||
TEXT, | ||
TEST_IMAGE_TEXT, | ||
modelId, | ||
null, | ||
100000f, | ||
null, | ||
null, | ||
null | ||
); | ||
Map<String, Object> responseWithMaxDistanceQuery = search(getIndexNameForTest(), neuralQueryBuilderWithMaxDistanceQuery, 1); | ||
assertNotNull(responseWithMaxDistanceQuery); | ||
} | ||
} |
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
108 changes: 108 additions & 0 deletions
108
qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/KnnRadialSearchIT.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,108 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.neuralsearch.bwc; | ||
|
||
import java.nio.file.Files; | ||
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 KnnRadialSearchIT extends AbstractRollingUpgradeTestCase { | ||
private static final String PIPELINE_NAME = "nlp-ingest-pipeline"; | ||
private static final String TEST_FIELD = "passage_text"; | ||
private static final String TEST_IMAGE_FIELD = "passage_image"; | ||
private static final String TEXT = "Hello world"; | ||
private static final String TEXT_MIXED = "Hello world mixed"; | ||
private static final String TEXT_UPGRADED = "Hello world upgraded"; | ||
private static final String TEST_IMAGE_TEXT = "/9j/4AAQSkZJRgABAQAASABIAAD"; | ||
private static final String TEST_IMAGE_TEXT_MIXED = "/9j/4AAQSkZJRgbdwoeicfhoid"; | ||
private static final String TEST_IMAGE_TEXT_UPGRADED = "/9j/4AAQSkZJR8eydhgfwceocvlk"; | ||
|
||
private static final int NUM_DOCS_PER_ROUND = 1; | ||
private static String modelId = ""; | ||
|
||
// Test rolling-upgrade with kNN radial search | ||
// Create Text Image Embedding Processor, Ingestion Pipeline and add document | ||
// Validate radial query, pipeline and document count in rolling-upgrade scenario | ||
public void testKnnRadialSearch_E2EFlow() throws Exception { | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
switch (getClusterType()) { | ||
case OLD: | ||
modelId = uploadTextImageEmbeddingModel(); | ||
loadModel(modelId); | ||
createPipelineForTextImageProcessor(modelId, PIPELINE_NAME); | ||
createIndexWithConfiguration( | ||
getIndexNameForTest(), | ||
Files.readString(Path.of(classLoader.getResource("processor/IndexMappings.json").toURI())), | ||
PIPELINE_NAME | ||
); | ||
addDocument(getIndexNameForTest(), "0", TEST_FIELD, TEXT, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT); | ||
break; | ||
case MIXED: | ||
modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_EMBEDDING_PROCESSOR); | ||
int totalDocsCountMixed; | ||
if (isFirstMixedRound()) { | ||
totalDocsCountMixed = NUM_DOCS_PER_ROUND; | ||
validateIndexQueryOnUpgrade(totalDocsCountMixed, modelId, TEXT, TEST_IMAGE_TEXT); | ||
addDocument(getIndexNameForTest(), "1", TEST_FIELD, TEXT_MIXED, TEST_IMAGE_FIELD, TEST_IMAGE_TEXT_MIXED); | ||
} else { | ||
totalDocsCountMixed = 2 * NUM_DOCS_PER_ROUND; | ||
validateIndexQueryOnUpgrade(totalDocsCountMixed, modelId, TEXT_MIXED, TEST_IMAGE_TEXT_MIXED); | ||
} | ||
break; | ||
case UPGRADED: | ||
try { | ||
modelId = getModelId(getIngestionPipeline(PIPELINE_NAME), TEXT_IMAGE_EMBEDDING_PROCESSOR); | ||
int totalDocsCountUpgraded = 3 * NUM_DOCS_PER_ROUND; | ||
loadModel(modelId); | ||
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); | ||
} | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected value: " + getClusterType()); | ||
} | ||
} | ||
|
||
private void validateIndexQueryOnUpgrade(final int numberOfDocs, final String modelId, final String text, final String imageText) | ||
throws Exception { | ||
int docCount = getDocCount(getIndexNameForTest()); | ||
assertEquals(numberOfDocs, docCount); | ||
loadModel(modelId); | ||
|
||
NeuralQueryBuilder neuralQueryBuilderWithMinScoreQuery = new NeuralQueryBuilder( | ||
"passage_embedding", | ||
text, | ||
imageText, | ||
modelId, | ||
null, | ||
null, | ||
0.01f, | ||
null, | ||
null | ||
); | ||
Map<String, Object> responseWithMinScore = search(getIndexNameForTest(), neuralQueryBuilderWithMinScoreQuery, 1); | ||
assertNotNull(responseWithMinScore); | ||
|
||
NeuralQueryBuilder neuralQueryBuilderWithMaxDistanceQuery = new NeuralQueryBuilder( | ||
"passage_embedding", | ||
text, | ||
imageText, | ||
modelId, | ||
null, | ||
100000f, | ||
null, | ||
null, | ||
null | ||
); | ||
Map<String, Object> responseWithMaxScore = search(getIndexNameForTest(), neuralQueryBuilderWithMaxDistanceQuery, 1); | ||
assertNotNull(responseWithMaxScore); | ||
} | ||
} |
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