From fa247b49bb740558fe6f6b4d24ab121f389dd404 Mon Sep 17 00:00:00 2001 From: Bo Zhang Date: Wed, 8 Jan 2025 13:48:20 -0800 Subject: [PATCH] Correct NeuralQueryBuilder doEquals() and doHashCode(). Signed-off-by: Bo Zhang --- CHANGELOG.md | 1 + .../neuralsearch/bwc/HybridSearchIT.java | 1 - .../common/MinClusterVersionUtil.java | 3 + .../query/HybridQueryBuilder.java | 3 - .../query/NeuralQueryBuilder.java | 61 ++++- .../query/HybridQueryBuilderTests.java | 1 - .../query/NeuralQueryBuilderTests.java | 250 +++++++++--------- 7 files changed, 183 insertions(+), 137 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8820110fa..fedbc45aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Address inconsistent scoring in hybrid query results ([#998](https://github.com/opensearch-project/neural-search/pull/998)) - Fix bug where ingested document has list of nested objects ([#1040](https://github.com/opensearch-project/neural-search/pull/1040)) - Fixed document source and score field mismatch in sorted hybrid queries ([#1043](https://github.com/opensearch-project/neural-search/pull/1043)) +- Update NeuralQueryBuilder doEquals() and doHashCode() to cater the missing parameters information ([#1045](https://github.com/opensearch-project/neural-search/pull/1045)). - Fix bug where embedding is missing when ingested document has "." in field name, and mismatches fieldMap config ([#1062](https://github.com/opensearch-project/neural-search/pull/1062)) ### Infrastructure ### Documentation diff --git a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/HybridSearchIT.java b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/HybridSearchIT.java index 95924112c..44671ed4a 100644 --- a/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/HybridSearchIT.java +++ b/qa/rolling-upgrade/src/test/java/org/opensearch/neuralsearch/bwc/HybridSearchIT.java @@ -20,7 +20,6 @@ import static org.opensearch.neuralsearch.util.TestUtils.getModelId; import org.opensearch.index.query.QueryBuilder; -import org.opensearch.index.query.QueryBuilders; import org.opensearch.knn.index.query.rescore.RescoreContext; import org.opensearch.neuralsearch.query.HybridQueryBuilder; import org.opensearch.neuralsearch.query.NeuralQueryBuilder; diff --git a/src/main/java/org/opensearch/neuralsearch/common/MinClusterVersionUtil.java b/src/main/java/org/opensearch/neuralsearch/common/MinClusterVersionUtil.java index 0f5cbefcf..a17e138e2 100644 --- a/src/main/java/org/opensearch/neuralsearch/common/MinClusterVersionUtil.java +++ b/src/main/java/org/opensearch/neuralsearch/common/MinClusterVersionUtil.java @@ -14,6 +14,7 @@ import static org.opensearch.knn.index.query.KNNQueryBuilder.MAX_DISTANCE_FIELD; import static org.opensearch.knn.index.query.KNNQueryBuilder.MIN_SCORE_FIELD; import static org.opensearch.neuralsearch.query.NeuralQueryBuilder.MODEL_ID_FIELD; +import static org.opensearch.neuralsearch.query.NeuralQueryBuilder.QUERY_IMAGE_FIELD; /** * A util class which holds the logic to determine the min version supported by the request parameters @@ -22,12 +23,14 @@ public final class MinClusterVersionUtil { private static final Version MINIMAL_SUPPORTED_VERSION_DEFAULT_MODEL_ID = Version.V_2_11_0; private static final Version MINIMAL_SUPPORTED_VERSION_RADIAL_SEARCH = Version.V_2_14_0; + private static final Version MINIMAL_SUPPORTED_VERSION_QUERY_IMAGE_FIX = Version.V_2_19_0; // Note this minimal version will act as a override private static final Map MINIMAL_VERSION_NEURAL = ImmutableMap.builder() .put(MODEL_ID_FIELD.getPreferredName(), MINIMAL_SUPPORTED_VERSION_DEFAULT_MODEL_ID) .put(MAX_DISTANCE_FIELD.getPreferredName(), MINIMAL_SUPPORTED_VERSION_RADIAL_SEARCH) .put(MIN_SCORE_FIELD.getPreferredName(), MINIMAL_SUPPORTED_VERSION_RADIAL_SEARCH) + .put(QUERY_IMAGE_FIELD.getPreferredName(), MINIMAL_SUPPORTED_VERSION_QUERY_IMAGE_FIX) .build(); public static boolean isClusterOnOrAfterMinReqVersionForDefaultModelIdSupport() { diff --git a/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java b/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java index 60d9fd639..338758802 100644 --- a/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java +++ b/src/main/java/org/opensearch/neuralsearch/query/HybridQueryBuilder.java @@ -51,8 +51,6 @@ public final class HybridQueryBuilder extends AbstractQueryBuilder queries = new ArrayList<>(); - private String fieldName; - static final int MAX_NUMBER_OF_SUB_QUERIES = 5; public HybridQueryBuilder(StreamInput in) throws IOException { @@ -255,7 +253,6 @@ protected boolean doEquals(HybridQueryBuilder obj) { return false; } EqualsBuilder equalsBuilder = new EqualsBuilder(); - equalsBuilder.append(fieldName, obj.fieldName); equalsBuilder.append(queries, obj.queries); return equalsBuilder.isEquals(); } diff --git a/src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java b/src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java index 40af1be4f..42d56b85c 100644 --- a/src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java +++ b/src/main/java/org/opensearch/neuralsearch/query/NeuralQueryBuilder.java @@ -18,6 +18,7 @@ import static org.opensearch.neuralsearch.processor.TextImageEmbeddingProcessor.INPUT_TEXT; import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -25,7 +26,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.lucene.search.Query; import org.opensearch.common.SetOnce; import org.opensearch.core.ParseField; @@ -76,8 +76,7 @@ public class NeuralQueryBuilder extends AbstractQueryBuilder @VisibleForTesting static final ParseField QUERY_TEXT_FIELD = new ParseField("query_text"); - @VisibleForTesting - static final ParseField QUERY_IMAGE_FIELD = new ParseField("query_image"); + public static final ParseField QUERY_IMAGE_FIELD = new ParseField("query_image"); public static final ParseField MODEL_ID_FIELD = new ParseField("model_id"); @@ -236,7 +235,16 @@ public static NeuralQueryBuilder.Builder builder() { public NeuralQueryBuilder(StreamInput in) throws IOException { super(in); this.fieldName = in.readString(); - this.queryText = in.readString(); + // The query image field was introduced since v2.11.0 through the + // https://github.com/opensearch-project/neural-search/pull/359 but at that time we didn't add it to + // NeuralQueryBuilder(StreamInput in) and doWriteTo(StreamOutput out) function. The fix will be + // introduced in v2.19.0 so we need this check for the backward compatibility. + if (isClusterOnOrAfterMinReqVersion(QUERY_IMAGE_FIELD.getPreferredName())) { + this.queryText = in.readOptionalString(); + this.queryImage = in.readOptionalString(); + } else { + this.queryText = in.readString(); + } // If cluster version is on or after 2.11 then default model Id support is enabled if (isClusterOnOrAfterMinReqVersionForDefaultModelIdSupport()) { this.modelId = in.readOptionalString(); @@ -265,7 +273,16 @@ public NeuralQueryBuilder(StreamInput in) throws IOException { @Override protected void doWriteTo(StreamOutput out) throws IOException { out.writeString(this.fieldName); - out.writeString(this.queryText); + // The query image field was introduced since v2.11.0 through the + // https://github.com/opensearch-project/neural-search/pull/359 but at that time we didn't add it to + // NeuralQueryBuilder(StreamInput in) and doWriteTo(StreamOutput out) function. The fix will be + // introduced in v2.19.0 so we need this check for the backward compatibility. + if (isClusterOnOrAfterMinReqVersion(QUERY_IMAGE_FIELD.getPreferredName())) { + out.writeOptionalString(this.queryText); + out.writeOptionalString(this.queryImage); + } else { + out.writeString(this.queryText); + } // If cluster version is on or after 2.11 then default model Id support is enabled if (isClusterOnOrAfterMinReqVersionForDefaultModelIdSupport()) { out.writeOptionalString(this.modelId); @@ -285,6 +302,7 @@ protected void doWriteTo(StreamOutput out) throws IOException { if (isClusterOnOrAfterMinReqVersion(EXPAND_NESTED_FIELD.getPreferredName())) { out.writeOptionalBoolean(this.expandNested); } + if (isClusterOnOrAfterMinReqVersion(METHOD_PARAMS_FIELD.getPreferredName())) { MethodParametersParser.streamOutput(out, methodParameters, MinClusterVersionUtil::isClusterOnOrAfterMinReqVersion); } @@ -295,7 +313,12 @@ protected void doWriteTo(StreamOutput out) throws IOException { protected void doXContent(XContentBuilder xContentBuilder, Params params) throws IOException { xContentBuilder.startObject(NAME); xContentBuilder.startObject(fieldName); - xContentBuilder.field(QUERY_TEXT_FIELD.getPreferredName(), queryText); + if (Objects.nonNull(queryText)) { + xContentBuilder.field(QUERY_TEXT_FIELD.getPreferredName(), queryText); + } + if (Objects.nonNull(queryImage)) { + xContentBuilder.field(QUERY_IMAGE_FIELD.getPreferredName(), queryImage); + } if (Objects.nonNull(modelId)) { xContentBuilder.field(MODEL_ID_FIELD.getPreferredName(), modelId); } @@ -501,15 +524,39 @@ protected boolean doEquals(NeuralQueryBuilder obj) { EqualsBuilder equalsBuilder = new EqualsBuilder(); equalsBuilder.append(fieldName, obj.fieldName); equalsBuilder.append(queryText, obj.queryText); + equalsBuilder.append(queryImage, obj.queryImage); equalsBuilder.append(modelId, obj.modelId); equalsBuilder.append(k, obj.k); + equalsBuilder.append(maxDistance, obj.maxDistance); + equalsBuilder.append(minScore, obj.minScore); + equalsBuilder.append(expandNested, obj.expandNested); + equalsBuilder.append(getVector(vectorSupplier), getVector(obj.vectorSupplier)); equalsBuilder.append(filter, obj.filter); + equalsBuilder.append(methodParameters, obj.methodParameters); + equalsBuilder.append(rescoreContext, obj.rescoreContext); return equalsBuilder.isEquals(); } @Override protected int doHashCode() { - return new HashCodeBuilder().append(fieldName).append(queryText).append(modelId).append(k).toHashCode(); + return Objects.hash( + fieldName, + queryText, + queryImage, + modelId, + k, + maxDistance, + minScore, + expandNested, + Arrays.hashCode(getVector(vectorSupplier)), + filter, + methodParameters, + rescoreContext + ); + } + + private float[] getVector(final Supplier vectorSupplier) { + return Objects.isNull(vectorSupplier) ? null : vectorSupplier.get(); } @Override diff --git a/src/test/java/org/opensearch/neuralsearch/query/HybridQueryBuilderTests.java b/src/test/java/org/opensearch/neuralsearch/query/HybridQueryBuilderTests.java index 3a453693f..1640d8e02 100644 --- a/src/test/java/org/opensearch/neuralsearch/query/HybridQueryBuilderTests.java +++ b/src/test/java/org/opensearch/neuralsearch/query/HybridQueryBuilderTests.java @@ -477,7 +477,6 @@ public void testStreams_whenWrittingToStream_thenSuccessful() { .queryText(QUERY_TEXT) .modelId(MODEL_ID) .k(K) - .vectorSupplier(TEST_VECTOR_SUPPLIER) .build(); original.add(neuralQueryBuilder); diff --git a/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java b/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java index 5791d57d2..5c146be1c 100644 --- a/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java +++ b/src/test/java/org/opensearch/neuralsearch/query/NeuralQueryBuilderTests.java @@ -57,6 +57,7 @@ import org.opensearch.index.query.QueryShardContext; import org.opensearch.knn.index.query.KNNQueryBuilder; import org.opensearch.knn.index.query.rescore.RescoreContext; +import org.opensearch.neuralsearch.common.MinClusterVersionUtil; import org.opensearch.neuralsearch.common.VectorUtil; import org.opensearch.neuralsearch.ml.MLCommonsClientAccessor; import org.opensearch.neuralsearch.util.NeuralSearchClusterTestUtils; @@ -571,7 +572,6 @@ private void testStreams() { NeuralQueryBuilder original = NeuralQueryBuilder.builder() .fieldName(FIELD_NAME) .queryText(QUERY_TEXT) - .queryImage(IMAGE_TEXT) .modelId(MODEL_ID) .k(K) .boost(BOOST) @@ -579,6 +579,10 @@ private void testStreams() { .filter(TEST_FILTER) .build(); + if (MinClusterVersionUtil.isClusterOnOrAfterMinReqVersion(QUERY_IMAGE_FIELD.getPreferredName())) { + original.queryImage(IMAGE_TEXT); + } + BytesStreamOutput streamOutput = new BytesStreamOutput(); original.writeTo(streamOutput); @@ -594,140 +598,97 @@ private void testStreams() { } public void testHashAndEquals() { - String fieldName1 = "field 1"; - String fieldName2 = "field 2"; - String queryText1 = "query text 1"; - String queryText2 = "query text 2"; - String imageText1 = "query image 1"; - String modelId1 = "model-1"; - String modelId2 = "model-2"; - float boost1 = 1.8f; - float boost2 = 3.8f; - String queryName1 = "query-1"; - String queryName2 = "query-2"; - int k1 = 1; - int k2 = 2; - - QueryBuilder filter1 = new MatchAllQueryBuilder(); - QueryBuilder filter2 = new MatchNoneQueryBuilder(); - - NeuralQueryBuilder neuralQueryBuilder_baseline = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .queryImage(imageText1) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName1) - .filter(filter1) - .build(); + final String fieldName2 = "field 2"; + final String queryText2 = "query text 2"; + final String queryImage2 = "query image 2"; + final String modelId2 = "model-2"; + final float boost2 = 3.8f; + final String queryName2 = "query-2"; + final int k2 = 2; + final float minScore1 = 1f; + final float minScore2 = 2f; + final float maxDistance1 = 10f; + final float maxDistance2 = 20f; + final Supplier vectorSupplier2 = () -> new float[] { 1.f }; + final Supplier vectorSupplier3 = () -> new float[] { 3.f }; + final Map methodParameters2 = Map.of("ef_search", 100); + final Map methodParameters3 = Map.of("ef_search", 101); + final RescoreContext rescoreContext2 = RescoreContext.getDefault(); + final RescoreContext rescoreContext3 = RescoreContext.builder().build(); + + final QueryBuilder filter2 = new MatchNoneQueryBuilder(); + + final NeuralQueryBuilder neuralQueryBuilder_baseline = getBaselineNeuralQueryBuilder(); // Identical to neuralQueryBuilder_baseline - NeuralQueryBuilder neuralQueryBuilder_baselineCopy = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName1) - .filter(filter1) - .build(); - - // Identical to neuralQueryBuilder_baseline except default boost and query name - NeuralQueryBuilder neuralQueryBuilder_defaultBoostAndQueryName = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_baselineCopy = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_baselineCopy.vectorSupplier(vectorSupplier2); + neuralQueryBuilder_baselineCopy.methodParameters(methodParameters2); + neuralQueryBuilder_baselineCopy.rescoreContext(rescoreContext2); // Identical to neuralQueryBuilder_baseline except diff field name - NeuralQueryBuilder neuralQueryBuilder_diffFieldName = NeuralQueryBuilder.builder() - .fieldName(fieldName2) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName1) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_diffFieldName = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffFieldName.fieldName(fieldName2); // Identical to neuralQueryBuilder_baseline except diff query text - NeuralQueryBuilder neuralQueryBuilder_diffQueryText = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText2) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName1) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_diffQueryText = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffQueryText.queryText(queryText2); + + // Identical to neuralQueryBuilder_baseline except diff image text + final NeuralQueryBuilder neuralQueryBuilder_diffImageText = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffImageText.queryImage(queryImage2); // Identical to neuralQueryBuilder_baseline except diff model ID - NeuralQueryBuilder neuralQueryBuilder_diffModelId = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId2) - .k(k1) - .boost(boost1) - .queryName(queryName1) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_diffModelId = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffModelId.modelId(modelId2); // Identical to neuralQueryBuilder_baseline except diff k - NeuralQueryBuilder neuralQueryBuilder_diffK = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k2) - .boost(boost1) - .queryName(queryName1) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_diffK = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffK.k(k2); + + // Identical to neuralQueryBuilder_baseline except diff maxDistance + final NeuralQueryBuilder neuralQueryBuilder_baseline_withMaxDistance = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_baseline_withMaxDistance.k(null); + neuralQueryBuilder_baseline_withMaxDistance.maxDistance(maxDistance1); + final NeuralQueryBuilder neuralQueryBuilder_diffMaxDistance = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffMaxDistance.k(null); + neuralQueryBuilder_diffMaxDistance.maxDistance(maxDistance2); + + // Identical to neuralQueryBuilder_baseline except diff minScore + final NeuralQueryBuilder neuralQueryBuilder_baseline_withMinScore = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_baseline_withMinScore.k(null); + neuralQueryBuilder_baseline_withMinScore.minScore(minScore1); + final NeuralQueryBuilder neuralQueryBuilder_diffMinScore = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffMinScore.k(null); + neuralQueryBuilder_diffMinScore.minScore(minScore2); + + // Identical to neuralQueryBuilder_baseline except for expandNested + final NeuralQueryBuilder neuralQueryBuilder_diffExpandNested = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffExpandNested.expandNested(Boolean.FALSE); + + // Identical to neuralQueryBuilder_baseline except for vectorSupplier + final NeuralQueryBuilder neuralQueryBuilder_diffVectorSupplier = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffVectorSupplier.vectorSupplier(vectorSupplier3); // Identical to neuralQueryBuilder_baseline except diff boost - NeuralQueryBuilder neuralQueryBuilder_diffBoost = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .boost(boost2) - .queryName(queryName1) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_diffBoost = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffBoost.boost(boost2); // Identical to neuralQueryBuilder_baseline except diff query name - NeuralQueryBuilder neuralQueryBuilder_diffQueryName = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName2) - .filter(filter1) - .build(); + final NeuralQueryBuilder neuralQueryBuilder_diffQueryName = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffQueryName.queryName(queryName2); - // Identical to neuralQueryBuilder_baseline except no filter - NeuralQueryBuilder neuralQueryBuilder_noFilter = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName2) - .build(); + // Identical to neuralQueryBuilder_baseline except diff filter + final NeuralQueryBuilder neuralQueryBuilder_diffFilter = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffFilter.filter(filter2); - // Identical to neuralQueryBuilder_baseline except no filter - NeuralQueryBuilder neuralQueryBuilder_diffFilter = NeuralQueryBuilder.builder() - .fieldName(fieldName1) - .queryText(queryText1) - .modelId(modelId1) - .k(k1) - .boost(boost1) - .queryName(queryName2) - .filter(filter2) - .build(); + // Identical to neuralQueryBuilder_baseline except diff methodParameters + final NeuralQueryBuilder neuralQueryBuilder_diffMethodParameters = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffMethodParameters.methodParameters(methodParameters3); + + // Identical to neuralQueryBuilder_baseline except diff rescoreContext + final NeuralQueryBuilder neuralQueryBuilder_diffRescoreContext = getBaselineNeuralQueryBuilder(); + neuralQueryBuilder_diffRescoreContext.rescoreContext(rescoreContext3); assertEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_baseline); assertEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_baseline.hashCode()); @@ -735,32 +696,71 @@ public void testHashAndEquals() { assertEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_baselineCopy); assertEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_baselineCopy.hashCode()); - assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_defaultBoostAndQueryName); - assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_defaultBoostAndQueryName.hashCode()); - assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffFieldName); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffFieldName.hashCode()); assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffQueryText); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffQueryText.hashCode()); + assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffImageText); + assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffImageText.hashCode()); + assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffModelId); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffModelId.hashCode()); assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffK); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffK.hashCode()); + assertNotEquals(neuralQueryBuilder_baseline_withMaxDistance, neuralQueryBuilder_diffMaxDistance); + assertNotEquals(neuralQueryBuilder_baseline_withMaxDistance.hashCode(), neuralQueryBuilder_diffMaxDistance.hashCode()); + + assertNotEquals(neuralQueryBuilder_baseline_withMinScore, neuralQueryBuilder_diffMinScore); + assertNotEquals(neuralQueryBuilder_baseline_withMinScore.hashCode(), neuralQueryBuilder_diffMinScore.hashCode()); + assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffBoost); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffBoost.hashCode()); assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffQueryName); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffQueryName.hashCode()); - assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_noFilter); - assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_noFilter.hashCode()); - assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffFilter); assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffFilter.hashCode()); + + assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffMethodParameters); + assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffMethodParameters.hashCode()); + + assertNotEquals(neuralQueryBuilder_baseline, neuralQueryBuilder_diffRescoreContext); + assertNotEquals(neuralQueryBuilder_baseline.hashCode(), neuralQueryBuilder_diffRescoreContext.hashCode()); + } + + private NeuralQueryBuilder getBaselineNeuralQueryBuilder() { + final String fieldName1 = "field 1"; + final String queryText1 = "query text 1"; + final String queryImage1 = "query image 1"; + final String modelId1 = "model-1"; + final float boost1 = 1.8f; + final String queryName1 = "query-1"; + final int k1 = 1; + final Supplier vectorSupplier1 = () -> new float[] { 1.f }; + final Map methodParameters1 = Map.of("ef_search", 100); + final RescoreContext rescoreContext1 = RescoreContext.getDefault(); + + final QueryBuilder filter1 = new MatchAllQueryBuilder(); + + return NeuralQueryBuilder.builder() + .fieldName(fieldName1) + .queryText(queryText1) + .queryImage(queryImage1) + .modelId(modelId1) + .k(k1) + .boost(boost1) + .queryName(queryName1) + .expandNested(Boolean.TRUE) + .vectorSupplier(vectorSupplier1) + .filter(filter1) + .methodParameters(methodParameters1) + .rescoreContext(rescoreContext1) + .build(); } @SneakyThrows