|
9 | 9 | import static org.opensearch.neuralsearch.TestUtils.createRandomVector;
|
10 | 10 |
|
11 | 11 | import java.util.Collections;
|
| 12 | +import java.util.List; |
12 | 13 | import java.util.Map;
|
13 | 14 |
|
14 | 15 | import org.apache.hc.core5.http.io.entity.EntityUtils;
|
|
26 | 27 | import com.google.common.primitives.Floats;
|
27 | 28 |
|
28 | 29 | import lombok.SneakyThrows;
|
| 30 | +import org.opensearch.neuralsearch.query.NeuralSparseQueryBuilder; |
29 | 31 |
|
30 | 32 | public class NeuralQueryEnricherProcessorIT extends BaseNeuralSearchIT {
|
31 | 33 |
|
32 | 34 | private static final String index = "my-nlp-index";
|
| 35 | + private static final String sparseIndex = "my-nlp-index-sparse"; |
33 | 36 | private static final String search_pipeline = "search-pipeline";
|
34 | 37 | private static final String ingest_pipeline = "nlp-pipeline";
|
35 | 38 | private static final String TEST_KNN_VECTOR_FIELD_NAME_1 = "test-knn-vector-1";
|
| 39 | + private static final String TEST_RANK_FEATURES_FIELD_NAME_1 = "test-rank-features-1"; |
36 | 40 | private final float[] testVector = createRandomVector(TEST_DIMENSION);
|
37 | 41 |
|
38 | 42 | @Before
|
@@ -61,6 +65,25 @@ public void testNeuralQueryEnricherProcessor_whenNoModelIdPassed_thenSuccess() {
|
61 | 65 | }
|
62 | 66 | }
|
63 | 67 |
|
| 68 | + @SneakyThrows |
| 69 | + public void testNeuralQueryEnricherProcessor_whenNoModelIdPassedInNeuralSparseQuery_thenSuccess() { |
| 70 | + String modelId = null; |
| 71 | + try { |
| 72 | + initializeIndexIfNotExist(sparseIndex); |
| 73 | + modelId = prepareSparseEncodingModel(); |
| 74 | + createSearchRequestProcessor(modelId, search_pipeline); |
| 75 | + createPipelineProcessor(modelId, ingest_pipeline, ProcessorType.TEXT_EMBEDDING); |
| 76 | + updateIndexSettings(sparseIndex, Settings.builder().put("index.search.default_pipeline", search_pipeline)); |
| 77 | + NeuralSparseQueryBuilder neuralSparseQueryBuilder = new NeuralSparseQueryBuilder(); |
| 78 | + neuralSparseQueryBuilder.fieldName(TEST_RANK_FEATURES_FIELD_NAME_1); |
| 79 | + neuralSparseQueryBuilder.queryText("hello"); |
| 80 | + Map<String, Object> response = search(sparseIndex, neuralSparseQueryBuilder, 2); |
| 81 | + assertFalse(response.isEmpty()); |
| 82 | + } finally { |
| 83 | + wipeOfTestResources(sparseIndex, ingest_pipeline, modelId, search_pipeline); |
| 84 | + } |
| 85 | + } |
| 86 | + |
64 | 87 | @SneakyThrows
|
65 | 88 | public void testNeuralQueryEnricherProcessor_whenGetEmptyQueryBody_thenSuccess() {
|
66 | 89 | String modelId = null;
|
@@ -120,5 +143,11 @@ private void initializeIndexIfNotExist(String indexName) {
|
120 | 143 | );
|
121 | 144 | assertEquals(1, getDocCount(indexName));
|
122 | 145 | }
|
| 146 | + |
| 147 | + if (sparseIndex.equals(indexName) && !indexExists(indexName)) { |
| 148 | + prepareSparseEncodingIndex(indexName, List.of(TEST_RANK_FEATURES_FIELD_NAME_1)); |
| 149 | + addSparseEncodingDoc(indexName, "1", List.of(TEST_RANK_FEATURES_FIELD_NAME_1), List.of(Map.of("hi", 1.0f, "hello", 1.1f))); |
| 150 | + assertEquals(1, getDocCount(indexName)); |
| 151 | + } |
123 | 152 | }
|
124 | 153 | }
|
0 commit comments