-
Notifications
You must be signed in to change notification settings - Fork 73
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: Varun Jain <[email protected]>
- Loading branch information
1 parent
1f880dd
commit a92e37c
Showing
8 changed files
with
173 additions
and
9 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
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
82 changes: 82 additions & 0 deletions
82
qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/TextSearch.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 com.carrotsearch.randomizedtesting.RandomizedTest; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import static org.opensearch.neuralsearch.TestUtils.NODES_BWC_CLUSTER; | ||
|
||
public class TextSearch extends AbstractRollingUpgradeTestCase{ | ||
private static final String PIPELINE_NAME = "nlp-pipeline"; | ||
private static final String TEST_FIELD = "test-field"; | ||
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 int NUM_DOCS = 1; | ||
|
||
public void testIndex() throws Exception{ | ||
waitForClusterHealthGreen(NODES_BWC_CLUSTER); | ||
switch (getClusterType()){ | ||
case OLD: | ||
String modelId= uploadTextEmbeddingModel(); | ||
loadModel(modelId); | ||
createPipelineProcessor(modelId,PIPELINE_NAME); | ||
createIndexWithConfiguration( | ||
testIndex, | ||
Files.readString(Path.of(classLoader.getResource("processor/IndexMappings.json").toURI())), | ||
PIPELINE_NAME | ||
); | ||
addDocument(testIndex, "0",TEST_FIELD,TEXT); | ||
break; | ||
case MIXED: | ||
int totalDocsCountMixed; | ||
if (isFirstMixedRound()){ | ||
totalDocsCountMixed=NUM_DOCS; | ||
validateTestIndexOnUpgrade(totalDocsCountMixed); | ||
addDocument(testIndex, "1",TEST_FIELD,TEXT_MIXED); | ||
}else{ | ||
totalDocsCountMixed=2*NUM_DOCS; | ||
validateTestIndexOnUpgrade(totalDocsCountMixed); | ||
} | ||
break; | ||
case UPGRADED: | ||
int totalDocsCountUpgraded=3*NUM_DOCS; | ||
addDocument(testIndex, "2",TEST_FIELD,TEXT_UPGRADED); | ||
validateTestIndexOnUpgrade(totalDocsCountUpgraded); | ||
deleteIndex(testIndex); | ||
break; | ||
} | ||
|
||
} | ||
|
||
private void validateTestIndexOnUpgrade(int numberOfDocs) throws Exception { | ||
int docCount=getDocCount(testIndex); | ||
assertEquals(numberOfDocs,docCount); | ||
} | ||
|
||
private String uploadTextEmbeddingModel() throws Exception { | ||
String requestBody = Files.readString(Path.of(classLoader.getResource("processor/UploadModelRequestBody.json").toURI())); | ||
return registerModelGroupAndGetModelId(requestBody); | ||
} | ||
|
||
private String registerModelGroupAndGetModelId(String requestBody) throws Exception { | ||
String modelGroupRegisterRequestBody = Files.readString( | ||
Path.of(classLoader.getResource("processor/CreateModelGroupRequestBody.json").toURI()) | ||
).replace("<MODEL_GROUP_NAME>", "public_model_" + RandomizedTest.randomAsciiAlphanumOfLength(8)); | ||
|
||
String modelGroupId=registerModelGroup(modelGroupRegisterRequestBody); | ||
|
||
requestBody = requestBody.replace("<MODEL_GROUP_ID>", modelGroupId); | ||
|
||
return uploadModelId(requestBody); | ||
} | ||
|
||
protected void createPipelineProcessor(String modelId, String pipelineName, ProcessorType processorType) throws Exception { | ||
String requestBody=Files.readString(Path.of(classLoader.getResource("processor/PipelineConfiguration.json").toURI())); | ||
createPipelineProcessor(requestBody,pipelineName,modelId); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
qa/rolling-upgrade/src/test/resources/processor/CreateModelGroupRequestBody.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,4 @@ | ||
{ | ||
"name": "<MODEL_GROUP_NAME>", | ||
"description": "This is a public model group" | ||
} |
32 changes: 32 additions & 0 deletions
32
qa/rolling-upgrade/src/test/resources/processor/IndexMappings.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,32 @@ | ||
{ | ||
"settings": { | ||
"index": { | ||
"knn": true, | ||
"knn.algo_param.ef_search": 100, | ||
"refresh_interval": "30s", | ||
"default_pipeline": "%s" | ||
}, | ||
"number_of_shards": 1, | ||
"number_of_replicas": 0 | ||
}, | ||
"mappings": { | ||
"properties": { | ||
"passage_embedding": { | ||
"type": "knn_vector", | ||
"dimension": 768, | ||
"method": { | ||
"name": "hnsw", | ||
"space_type": "l2", | ||
"engine": "lucene", | ||
"parameters": { | ||
"ef_construction": 128, | ||
"m": 24 | ||
} | ||
} | ||
}, | ||
"passage_text": { | ||
"type": "text" | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
qa/rolling-upgrade/src/test/resources/processor/PipelineConfiguration.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,18 @@ | ||
{ | ||
"description": "text embedding pipeline for hybrid", | ||
"processors": [ | ||
{ | ||
"text_embedding": { | ||
"model_id": "%s", | ||
"field_map": { | ||
"title": "title_knn", | ||
"favor_list": "favor_list_knn", | ||
"favorites": { | ||
"game": "game_knn", | ||
"movie": "movie_knn" | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} |
15 changes: 15 additions & 0 deletions
15
qa/rolling-upgrade/src/test/resources/processor/UploadModelRequestBody.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,15 @@ | ||
{ | ||
"name": "traced_small_model", | ||
"version": "1.0.0", | ||
"model_format": "TORCH_SCRIPT", | ||
"model_task_type": "text_embedding", | ||
"model_content_hash_value": "e13b74006290a9d0f58c1376f9629d4ebc05a0f9385f40db837452b167ae9021", | ||
"model_group_id": "<MODEL_GROUP_ID>", | ||
"model_config": { | ||
"model_type": "bert", | ||
"embedding_dimension": 768, | ||
"framework_type": "sentence_transformers", | ||
"all_config": "{\"architectures\":[\"BertModel\"],\"max_position_embeddings\":512,\"model_type\":\"bert\",\"num_attention_heads\":12,\"num_hidden_layers\":6}" | ||
}, | ||
"url": "https://github.com/opensearch-project/ml-commons/blob/2.x/ml-algorithms/src/test/resources/org/opensearch/ml/engine/algorithms/text_embedding/traced_small_model.zip?raw=true" | ||
} |