diff --git a/src/main/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessor.java b/src/main/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessor.java index 2c752b7ea..ed0d95d1a 100644 --- a/src/main/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessor.java +++ b/src/main/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessor.java @@ -179,7 +179,9 @@ private List> buildVectorFromResponse(MLOutput mlOutput) { final ModelTensorOutput modelTensorOutput = (ModelTensorOutput) mlOutput; final List tensorOutputList = modelTensorOutput.getMlModelOutputs(); if (CollectionUtils.isEmpty(tensorOutputList) || CollectionUtils.isEmpty(tensorOutputList.get(0).getMlModelTensors())) { - throw new IllegalStateException("Empty model result produced. Expected at least [1] tensor output and [1] model tensor, but got [0]"); + throw new IllegalStateException( + "Empty model result produced. Expected at least [1] tensor output and [1] model tensor, but got [0]" + ); } List> resultMaps = new ArrayList<>(); for (ModelTensors tensors : tensorOutputList) { diff --git a/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java b/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java index 601bf9003..2ac8853e4 100644 --- a/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java +++ b/src/main/java/org/opensearch/neuralsearch/plugin/NeuralSearch.java @@ -9,7 +9,6 @@ import java.util.Arrays; import java.util.Collection; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -100,10 +99,10 @@ public List> getQueries() { public Map getProcessors(Processor.Parameters parameters) { clientAccessor = new MLCommonsClientAccessor(new MachineLearningNodeClient(parameters.client)); return Map.of( - TextEmbeddingProcessor.TYPE, - new TextEmbeddingProcessorFactory(clientAccessor, parameters.env), - SparseEncodingProcessor.TYPE, - new SparseEncodingProcessorFactory(clientAccessor, parameters.env) + TextEmbeddingProcessor.TYPE, + new TextEmbeddingProcessorFactory(clientAccessor, parameters.env), + SparseEncodingProcessor.TYPE, + new SparseEncodingProcessorFactory(clientAccessor, parameters.env) ); } diff --git a/src/main/java/org/opensearch/neuralsearch/processor/NLPProcessor.java b/src/main/java/org/opensearch/neuralsearch/processor/NLPProcessor.java index 2ca516404..52962c5bb 100644 --- a/src/main/java/org/opensearch/neuralsearch/processor/NLPProcessor.java +++ b/src/main/java/org/opensearch/neuralsearch/processor/NLPProcessor.java @@ -164,20 +164,20 @@ Map buildMapWithProcessorKeyAndOriginalValue(IngestDocument inge } private void buildMapWithProcessorKeyAndOriginalValueForMapType( - String parentKey, - Object processorKey, - Map sourceAndMetadataMap, - Map treeRes + String parentKey, + Object processorKey, + Map sourceAndMetadataMap, + Map treeRes ) { if (processorKey == null || sourceAndMetadataMap == null) return; if (processorKey instanceof Map) { Map next = new LinkedHashMap<>(); for (Map.Entry nestedFieldMapEntry : ((Map) processorKey).entrySet()) { buildMapWithProcessorKeyAndOriginalValueForMapType( - nestedFieldMapEntry.getKey(), - nestedFieldMapEntry.getValue(), - (Map) sourceAndMetadataMap.get(parentKey), - next + nestedFieldMapEntry.getKey(), + nestedFieldMapEntry.getValue(), + (Map) sourceAndMetadataMap.get(parentKey), + next ); } treeRes.put(parentKey, next); @@ -214,9 +214,9 @@ private void validateNestedTypeValue(String sourceKey, Object sourceValue, Suppl validateListTypeValue(sourceKey, sourceValue); } else if (Map.class.isAssignableFrom(sourceValue.getClass())) { ((Map) sourceValue).values() - .stream() - .filter(Objects::nonNull) - .forEach(x -> validateNestedTypeValue(sourceKey, x, () -> maxDepth + 1)); + .stream() + .filter(Objects::nonNull) + .forEach(x -> validateNestedTypeValue(sourceKey, x, () -> maxDepth + 1)); } else if (!String.class.isAssignableFrom(sourceValue.getClass())) { throw new IllegalArgumentException("map type field [" + sourceKey + "] has non-string type, cannot process it"); } else if (StringUtils.isBlank(sourceValue.toString())) { diff --git a/src/main/java/org/opensearch/neuralsearch/query/SparseEncodingQueryBuilder.java b/src/main/java/org/opensearch/neuralsearch/query/SparseEncodingQueryBuilder.java index 3e938933c..2f0647d68 100644 --- a/src/main/java/org/opensearch/neuralsearch/query/SparseEncodingQueryBuilder.java +++ b/src/main/java/org/opensearch/neuralsearch/query/SparseEncodingQueryBuilder.java @@ -6,7 +6,6 @@ package org.opensearch.neuralsearch.query; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -125,18 +124,9 @@ public static SparseEncodingQueryBuilder fromXContent(XContentParser parser) thr requireValue(sparseEncodingQueryBuilder.fieldName(), "Field name must be provided for " + NAME + " query"); requireValue( sparseEncodingQueryBuilder.queryText(), - QUERY_TEXT_FIELD.getPreferredName() - + " must be provided for " - + NAME - + " query" - ); - requireValue( - sparseEncodingQueryBuilder.modelId(), - MODEL_ID_FIELD.getPreferredName() - + " must be provided for " - + NAME - + " query" + QUERY_TEXT_FIELD.getPreferredName() + " must be provided for " + NAME + " query" ); + requireValue(sparseEncodingQueryBuilder.modelId(), MODEL_ID_FIELD.getPreferredName() + " must be provided for " + NAME + " query"); return sparseEncodingQueryBuilder; } @@ -215,19 +205,14 @@ protected Query doToQuery(QueryShardContext context) throws IOException { private static void validateForRewrite(String queryText, String modelId) { if (StringUtils.isBlank(queryText) || StringUtils.isBlank(modelId)) { throw new IllegalArgumentException( - QUERY_TEXT_FIELD.getPreferredName() - + " and " - + MODEL_ID_FIELD.getPreferredName() - + " cannot be null." + QUERY_TEXT_FIELD.getPreferredName() + " and " + MODEL_ID_FIELD.getPreferredName() + " cannot be null." ); } } private static void validateFieldType(MappedFieldType fieldType) { if (null == fieldType || !fieldType.typeName().equals("rank_features")) { - throw new IllegalArgumentException( - "[" + NAME + "] query only works on [rank_features] fields" - ); + throw new IllegalArgumentException("[" + NAME + "] query only works on [rank_features] fields"); } } @@ -237,7 +222,9 @@ private static void validateQueryTokens(Map queryTokens) { } for (Map.Entry entry : queryTokens.entrySet()) { if (entry.getValue() <= 0) { - throw new IllegalArgumentException("Feature weight must be larger than 0, got: " + entry.getValue() + "for key " + entry.getKey()); + throw new IllegalArgumentException( + "Feature weight must be larger than 0, got: " + entry.getValue() + "for key " + entry.getKey() + ); } } } diff --git a/src/test/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessorTests.java b/src/test/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessorTests.java index e93033517..295daa948 100644 --- a/src/test/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessorTests.java +++ b/src/test/java/org/opensearch/neuralsearch/ml/MLCommonsClientAccessorTests.java @@ -217,7 +217,7 @@ public void testInferenceSentencesWithMapResult_whenModelTensorListEmpty_thenExc ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(IllegalStateException.class); Mockito.verify(resultListener).onFailure(argumentCaptor.capture()); assertEquals( - "Empty model result produced. Expected at least [1] tensor output and [1] model tensor, but got [0]", + "Empty model result produced. Expected at least [1] tensor output and [1] model tensor, but got [0]", argumentCaptor.getValue().getMessage() ); Mockito.verifyNoMoreInteractions(resultListener);