Skip to content

Commit

Permalink
Fixing test Cases
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Jan 10, 2024
1 parent 781551c commit 494d972
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -84,13 +84,15 @@ private void validateTestIndex(String modelId) throws Exception {
Map<String, Object> response = search(getIndexNameForTest(), boolQueryBuilder, 1);
Map<String, Object> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"mappings": {
"properties": {
"passage_embedding": {
"type": "knn_vector"
"type": "rank_features"
},
"passage_text": {
"type": "text"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -109,13 +109,15 @@ private void validateTestIndexOnUpgrade(int numberOfDocs, String modelId) throws
Map<String, Object> response = search(getIndexNameForTest(), boolQueryBuilder, 1);
Map<String, Object> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"description": "An sparse encoding ingest pipeline",
"processors": [
{
"sparse_encoding": {
"model_id": "%s",
"field_map": {
"passage_text": "passage_embedding"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 494d972

Please sign in to comment.