Skip to content

Commit

Permalink
Renaming and addressing comments of Martin
Browse files Browse the repository at this point in the history
Signed-off-by: Varun Jain <[email protected]>
  • Loading branch information
vibrantvarun committed Sep 29, 2023
1 parent c3d0649 commit ef5f939
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
import org.opensearch.ingest.Processor;
import org.opensearch.ml.client.MachineLearningNodeClient;
import org.opensearch.neuralsearch.ml.MLCommonsClientAccessor;
import org.opensearch.neuralsearch.processor.NeuralQueryProcessor;
import org.opensearch.neuralsearch.processor.NormalizationProcessor;
import org.opensearch.neuralsearch.processor.NormalizationProcessorWorkflow;
import org.opensearch.neuralsearch.processor.SparseEncodingProcessor;
import org.opensearch.neuralsearch.processor.TextEmbeddingProcessor;
import org.opensearch.neuralsearch.processor.*;
import org.opensearch.neuralsearch.processor.EnrichingQueryDefaultProcessor;
import org.opensearch.neuralsearch.processor.combination.ScoreCombinationFactory;
import org.opensearch.neuralsearch.processor.combination.ScoreCombiner;
import org.opensearch.neuralsearch.processor.factory.NormalizationProcessorFactory;
Expand Down Expand Up @@ -145,6 +142,6 @@ public List<Setting<?>> getSettings() {
public Map<String, org.opensearch.search.pipeline.Processor.Factory<SearchRequestProcessor>> getRequestProcessors(
Parameters parameters
) {
return Map.of(NeuralQueryProcessor.TYPE, new NeuralQueryProcessor.Factory());
return Map.of(EnrichingQueryDefaultProcessor.TYPE, new EnrichingQueryDefaultProcessor.Factory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
@Setter
@Getter
public class NeuralQueryProcessor extends AbstractProcessor implements SearchRequestProcessor {
public class EnrichingQueryDefaultProcessor extends AbstractProcessor implements SearchRequestProcessor {

/**
* Key to reference this processor type from a search pipeline.
Expand All @@ -46,7 +46,7 @@ public String getType() {
return TYPE;
}

private NeuralQueryProcessor(
private EnrichingQueryDefaultProcessor(
String tag,
String description,
boolean ignoreFailure,
Expand Down Expand Up @@ -77,10 +77,10 @@ public static class Factory implements Processor.Factory<SearchRequestProcessor>
/**
* Create the processor object.
*
* @return NeuralQueryProcessor
* @return EnrichingQueryDefaultProcessor
*/
@Override
public NeuralQueryProcessor create(
public EnrichingQueryDefaultProcessor create(
Map<String, Processor.Factory<SearchRequestProcessor>> processorFactories,
String tag,
String description,
Expand All @@ -100,7 +100,7 @@ public NeuralQueryProcessor create(
throw new IllegalArgumentException("model Id or neural info map either of them should be provided");
}

return new NeuralQueryProcessor(tag, description, ignoreFailure, modelId, neuralInfoMap);
return new EnrichingQueryDefaultProcessor(tag, description, ignoreFailure, modelId, neuralInfoMap);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Optional;

import org.opensearch.ingest.Processor;
import org.opensearch.neuralsearch.processor.NeuralQueryProcessor;
import org.opensearch.neuralsearch.processor.EnrichingQueryDefaultProcessor;
import org.opensearch.neuralsearch.processor.NormalizationProcessor;
import org.opensearch.neuralsearch.processor.TextEmbeddingProcessor;
import org.opensearch.neuralsearch.processor.factory.NormalizationProcessorFactory;
Expand Down Expand Up @@ -83,6 +83,6 @@ public void testRequestProcessors() {
parameters
);
assertNotNull(processors);
assertNotNull(processors.get(NeuralQueryProcessor.TYPE));
assertNotNull(processors.get(EnrichingQueryDefaultProcessor.TYPE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import static org.opensearch.neuralsearch.TestUtils.createRandomVector;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

Expand All @@ -22,7 +21,7 @@

import com.google.common.primitives.Floats;

public class NeuralQueryProcessorIT extends BaseNeuralSearchIT {
public class EnrichingQueryDefaultProcessorIT extends BaseNeuralSearchIT {

private static final String index = "my-nlp-index";
private static final String search_pipeline = "search-pipeline";
Expand All @@ -48,7 +47,7 @@ public void tearDown() {
}

@SneakyThrows
public void testNeuralQueryProcessor() throws Exception {
public void testEnrichingQueryProcessor_whenNoModelIdPassed_thenSuccess() {
initializeIndexIfNotExist();
String modelId = getDeployedModelId();
createSearchRequestProcessor(modelId, search_pipeline);
Expand All @@ -64,8 +63,9 @@ public void testNeuralQueryProcessor() throws Exception {

}

private void initializeIndexIfNotExist() throws IOException {
if (index.equals(NeuralQueryProcessorIT.index) && !indexExists(index)) {
@SneakyThrows
private void initializeIndexIfNotExist() {
if (index.equals(EnrichingQueryDefaultProcessorIT.index) && !indexExists(index)) {
prepareKnnIndex(
index,
Collections.singletonList(new KNNFieldConfig(TEST_KNN_VECTOR_FIELD_NAME_1, TEST_DIMENSION, TEST_SPACE_TYPE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import org.opensearch.search.builder.SearchSourceBuilder;
import org.opensearch.test.OpenSearchTestCase;

public class NeuralQueryProcessorTests extends OpenSearchTestCase {
public class EnrichingQueryDefaultProcessorTests extends OpenSearchTestCase {

public void testFactory() throws Exception {
NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory();
NeuralQueryProcessor processor = createTestProcessor(factory);
public void testFactory_whenMissingQueryParam_thenThrowException() throws Exception {
EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory();
EnrichingQueryDefaultProcessor processor = createTestProcessor(factory);
assertEquals("vasdcvkcjkbldbjkd", processor.getModelId());
assertEquals("bahbkcdkacb", processor.getNeuralFieldDefaultIdMap().get("fieldName").toString());

Expand All @@ -30,33 +30,33 @@ public void testFactory() throws Exception {
}

public void testFactory_whenModelIdIsNotString_thenFail() {
NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory();
EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory();
Map<String, Object> configMap = new HashMap<>();
configMap.put("default_model_id", 55555L);
expectThrows(IllegalArgumentException.class, () -> factory.create(Collections.emptyMap(), null, null, false, configMap, null));
}

public void testProcessRequest() throws Exception {
NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory();
public void testProcessRequest_whenVisitingQueryBuilder_thenSuccess() throws Exception {
EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory();
NeuralQueryBuilder neuralQueryBuilder = new NeuralQueryBuilder();
SearchRequest searchRequest = new SearchRequest();
searchRequest.source(new SearchSourceBuilder().query(neuralQueryBuilder));
NeuralQueryProcessor processor = createTestProcessor(factory);
EnrichingQueryDefaultProcessor processor = createTestProcessor(factory);
SearchRequest processSearchRequest = processor.processRequest(searchRequest);
assertEquals(processSearchRequest, searchRequest);
}

public void testType() throws Exception {
NeuralQueryProcessor.Factory factory = new NeuralQueryProcessor.Factory();
NeuralQueryProcessor processor = createTestProcessor(factory);
assertEquals(NeuralQueryProcessor.TYPE, processor.getType());
EnrichingQueryDefaultProcessor.Factory factory = new EnrichingQueryDefaultProcessor.Factory();
EnrichingQueryDefaultProcessor processor = createTestProcessor(factory);
assertEquals(EnrichingQueryDefaultProcessor.TYPE, processor.getType());
}

private NeuralQueryProcessor createTestProcessor(NeuralQueryProcessor.Factory factory) throws Exception {
private EnrichingQueryDefaultProcessor createTestProcessor(EnrichingQueryDefaultProcessor.Factory factory) throws Exception {
Map<String, Object> configMap = new HashMap<>();
configMap.put("default_model_id", "vasdcvkcjkbldbjkd");
configMap.put("neural_field_default_id", Map.of("fieldName", "bahbkcdkacb"));
NeuralQueryProcessor processor = factory.create(Collections.emptyMap(), null, null, false, configMap, null);
EnrichingQueryDefaultProcessor processor = factory.create(Collections.emptyMap(), null, null, false, configMap, null);
return processor;
}
}

0 comments on commit ef5f939

Please sign in to comment.