-
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.
Signed-off-by: Varun Jain <[email protected]>
- Loading branch information
1 parent
dee67ca
commit b13eb80
Showing
5 changed files
with
120 additions
and
2 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
83 changes: 83 additions & 0 deletions
83
src/test/java/org/opensearch/neuralsearch/processor/NeuralQueryProcessorIT.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,83 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.neuralsearch.processor; | ||
|
||
import static org.opensearch.neuralsearch.TestUtils.createRandomVector; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.knn.index.SpaceType; | ||
import org.opensearch.neuralsearch.common.BaseNeuralSearchIT; | ||
import org.opensearch.neuralsearch.query.NeuralQueryBuilder; | ||
|
||
import com.google.common.primitives.Floats; | ||
|
||
public class NeuralQueryProcessorIT extends BaseNeuralSearchIT { | ||
|
||
public static final String index = "my-nlp-index"; | ||
public static final String search_pipeline = "search-pipeline"; | ||
public static final String ingest_pipeline = "nlp-pipeline"; | ||
private static final String TEST_KNN_VECTOR_FIELD_NAME_1 = "test-knn-vector-1"; | ||
private static final int TEST_DIMENSION = 768; | ||
private static final SpaceType TEST_SPACE_TYPE = SpaceType.L2; | ||
private final float[] testVector = createRandomVector(TEST_DIMENSION); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
updateClusterSettings(); | ||
prepareModel(); | ||
} | ||
|
||
@After | ||
@SneakyThrows | ||
public void tearDown() { | ||
super.tearDown(); | ||
deleteSearchPipeline(search_pipeline); | ||
findDeployedModels().forEach(this::deleteModel); | ||
} | ||
|
||
public void testNeuralQueryProcessor() throws Exception { | ||
initializeIndexIfNotExist(index); | ||
String modelId = getDeployedModelId(); | ||
createSearchRequestProcessor(modelId, search_pipeline); | ||
createPipelineProcessor(modelId, ingest_pipeline); | ||
updateIndexSettings(index, Settings.builder().put("index.search.default_pipeline", search_pipeline)); | ||
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder(); | ||
neuralQueryBuilder.fieldName(TEST_KNN_VECTOR_FIELD_NAME_1); | ||
neuralQueryBuilder.queryText("Hello World"); | ||
neuralQueryBuilder.k(1); | ||
Map<String, Object> response = search(index, neuralQueryBuilder, 2); | ||
|
||
assertFalse(response.isEmpty()); | ||
|
||
assertEquals(modelId, neuralQueryBuilder.modelId()); | ||
|
||
} | ||
|
||
private void initializeIndexIfNotExist(String indexName) throws IOException { | ||
if (index.equals(indexName) && !indexExists(index)) { | ||
prepareKnnIndex( | ||
index, | ||
Collections.singletonList(new KNNFieldConfig(TEST_KNN_VECTOR_FIELD_NAME_1, TEST_DIMENSION, TEST_SPACE_TYPE)) | ||
); | ||
addKnnDoc( | ||
index, | ||
"1", | ||
Collections.singletonList(TEST_KNN_VECTOR_FIELD_NAME_1), | ||
Collections.singletonList(Floats.asList(testVector).toArray()) | ||
); | ||
assertEquals(1, getDocCount(index)); | ||
} | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/test/resources/processor/SearchRequestPipelineConfiguration.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