From 850ddbad14b97e02c1c80130da307ff462afa26d Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Sun, 15 Dec 2024 15:45:50 -0800 Subject: [PATCH] Update custom mappings Signed-off-by: Vijayan Balasubramanian --- .../java/org/opensearch/knn/KNNSingleNodeTestCase.java | 9 +-------- .../org/opensearch/knn/index/KNNESSettingsTestIT.java | 8 ++++++-- .../org/opensearch/knn/integ/ExpandNestedDocsIT.java | 2 ++ .../org/opensearch/knn/integ/KNNScriptScoringIT.java | 7 ++++++- .../org/opensearch/knn/integ/PainlessScriptScoreIT.java | 7 ++++++- .../knn/plugin/action/RestKNNStatsHandlerIT.java | 8 +++++++- .../knn/plugin/action/RestLegacyKNNStatsHandlerIT.java | 8 +++++++- .../java/org/opensearch/knn/recall/RecallTestsIT.java | 3 +++ 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/opensearch/knn/KNNSingleNodeTestCase.java b/src/test/java/org/opensearch/knn/KNNSingleNodeTestCase.java index 7bfce5b94..41cd4e8a5 100644 --- a/src/test/java/org/opensearch/knn/KNNSingleNodeTestCase.java +++ b/src/test/java/org/opensearch/knn/KNNSingleNodeTestCase.java @@ -96,7 +96,7 @@ public void tearDown() throws Exception { * Create a k-NN index with default settings */ protected IndexService createKNNIndex(String indexName) { - return createIndex(indexName, getKNNDefaultIndexSettings()); + return createIndex(indexName, getKNNDefaultIndexSettingsBuildsGraphAlways()); } /** @@ -161,13 +161,6 @@ protected void createKnnNestedIndexMapping(String indexName, String fieldPath, I OpenSearchAssertions.assertAcked(client().admin().indices().putMapping(request).actionGet()); } - /** - * Get default k-NN settings for test cases - */ - protected Settings getKNNDefaultIndexSettings() { - return Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", true).build(); - } - /** * Get default k-NN settings for test cases with build graph always */ diff --git a/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java b/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java index 20940f151..b6bbb748a 100644 --- a/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java +++ b/src/test/java/org/opensearch/knn/index/KNNESSettingsTestIT.java @@ -106,7 +106,11 @@ public void testCreateIndexWithInvalidSpaceType() throws IOException { } public void testUpdateIndexSetting() throws IOException { - Settings settings = Settings.builder().put("index.knn", true).put(KNNSettings.KNN_ALGO_PARAM_EF_SEARCH, 512).build(); + Settings settings = Settings.builder() + .put("index.knn", true) + .put(KNNSettings.KNN_ALGO_PARAM_EF_SEARCH, 512) + .put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0) + .build(); createKnnIndex(INDEX_NAME, settings, createKnnIndexMapping(FIELD_NAME, 2)); assertEquals("512", getIndexSettingByName(INDEX_NAME, KNNSettings.KNN_ALGO_PARAM_EF_SEARCH)); @@ -122,7 +126,7 @@ public void testUpdateIndexSetting() throws IOException { @SuppressWarnings("unchecked") public void testCacheRebuiltAfterUpdateIndexSettings() throws Exception { - createKnnIndex(INDEX_NAME, buildKNNIndexSettings(0), createKnnIndexMapping(FIELD_NAME, 2)); + createKnnIndex(INDEX_NAME, getKNNDefaultIndexSettings(), createKnnIndexMapping(FIELD_NAME, 2)); Float[] vector = { 6.0f, 6.0f }; addKnnDoc(INDEX_NAME, "1", FIELD_NAME, vector); diff --git a/src/test/java/org/opensearch/knn/integ/ExpandNestedDocsIT.java b/src/test/java/org/opensearch/knn/integ/ExpandNestedDocsIT.java index 164aa7100..6aa9797b7 100644 --- a/src/test/java/org/opensearch/knn/integ/ExpandNestedDocsIT.java +++ b/src/test/java/org/opensearch/knn/integ/ExpandNestedDocsIT.java @@ -20,6 +20,7 @@ import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.knn.KNNRestTestCase; import org.opensearch.knn.NestedKnnDocBuilder; +import org.opensearch.knn.index.KNNSettings; import org.opensearch.knn.index.VectorDataType; import org.opensearch.knn.index.engine.KNNEngine; import org.opensearch.knn.index.mapper.Mode; @@ -323,6 +324,7 @@ private void createKnnIndex( .put("number_of_shards", numOfShards) .put("number_of_replicas", 0) .put("index.knn", true) + .put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0) .build(); createKnnIndex(INDEX_NAME, settings, mapping); } diff --git a/src/test/java/org/opensearch/knn/integ/KNNScriptScoringIT.java b/src/test/java/org/opensearch/knn/integ/KNNScriptScoringIT.java index d1288c5f3..42a4f2b95 100644 --- a/src/test/java/org/opensearch/knn/integ/KNNScriptScoringIT.java +++ b/src/test/java/org/opensearch/knn/integ/KNNScriptScoringIT.java @@ -14,6 +14,7 @@ import org.opensearch.knn.KNNRestTestCase; import org.opensearch.knn.KNNResult; import org.opensearch.knn.common.KNNConstants; +import org.opensearch.knn.index.KNNSettings; import org.opensearch.knn.index.SpaceType; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.opensearch.client.Request; @@ -840,7 +841,11 @@ private void createIndexAndAssertScriptScore( /* * Create knn index and populate data */ - Settings settings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", enableKnn).build(); + Settings.Builder builder = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", enableKnn); + if (enableKnn) { + builder.put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0); + } + Settings settings = builder.build(); createKnnIndex(INDEX_NAME, settings, mapper); try { final int numDocsWithField = randomIntBetween(4, 10); diff --git a/src/test/java/org/opensearch/knn/integ/PainlessScriptScoreIT.java b/src/test/java/org/opensearch/knn/integ/PainlessScriptScoreIT.java index 9daef76e9..4d5248a45 100644 --- a/src/test/java/org/opensearch/knn/integ/PainlessScriptScoreIT.java +++ b/src/test/java/org/opensearch/knn/integ/PainlessScriptScoreIT.java @@ -9,6 +9,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.knn.KNNRestTestCase; import org.opensearch.knn.KNNResult; +import org.opensearch.knn.index.KNNSettings; import org.opensearch.knn.index.engine.KNNMethodContext; import org.opensearch.knn.index.engine.MethodComponentContext; import org.opensearch.knn.index.SpaceType; @@ -622,7 +623,11 @@ private Response buildIndexAndRunPainlessScript( /* * Create knn index and populate data */ - Settings settings = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", enableKnn).build(); + Settings.Builder builder = Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", enableKnn); + if (enableKnn) { + builder.put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0); + } + Settings settings = builder.build(); createKnnIndex(INDEX_NAME, settings, mapper); try { for (Map.Entry data : documents.entrySet()) { diff --git a/src/test/java/org/opensearch/knn/plugin/action/RestKNNStatsHandlerIT.java b/src/test/java/org/opensearch/knn/plugin/action/RestKNNStatsHandlerIT.java index 671185abf..e8da15589 100644 --- a/src/test/java/org/opensearch/knn/plugin/action/RestKNNStatsHandlerIT.java +++ b/src/test/java/org/opensearch/knn/plugin/action/RestKNNStatsHandlerIT.java @@ -24,6 +24,7 @@ import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryBuilders; import org.opensearch.knn.KNNRestTestCase; +import org.opensearch.knn.index.KNNSettings; import org.opensearch.knn.index.query.KNNQueryBuilder; import org.opensearch.knn.index.SpaceType; import org.opensearch.knn.plugin.stats.KNNStats; @@ -292,7 +293,12 @@ public void testScriptStats_multipleShards() throws Exception { // Create an index with a single vector createKnnIndex( INDEX_NAME, - Settings.builder().put("number_of_shards", 2).put("number_of_replicas", 0).put("index.knn", true).build(), + Settings.builder() + .put("number_of_shards", 2) + .put("number_of_replicas", 0) + .put("index.knn", true) + .put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0) + .build(), createKnnIndexMapping(FIELD_NAME, 2) ); diff --git a/src/test/java/org/opensearch/knn/plugin/action/RestLegacyKNNStatsHandlerIT.java b/src/test/java/org/opensearch/knn/plugin/action/RestLegacyKNNStatsHandlerIT.java index bea93e13c..e00d90056 100644 --- a/src/test/java/org/opensearch/knn/plugin/action/RestLegacyKNNStatsHandlerIT.java +++ b/src/test/java/org/opensearch/knn/plugin/action/RestLegacyKNNStatsHandlerIT.java @@ -12,6 +12,7 @@ package org.opensearch.knn.plugin.action; import org.opensearch.knn.KNNRestTestCase; +import org.opensearch.knn.index.KNNSettings; import org.opensearch.knn.index.SpaceType; import org.opensearch.knn.index.query.KNNQueryBuilder; import org.opensearch.knn.plugin.KNNPlugin; @@ -266,7 +267,12 @@ public void testScriptStats_multipleShards() throws Exception { // Create an index with a single vector createKnnIndex( INDEX_NAME, - Settings.builder().put("number_of_shards", 2).put("number_of_replicas", 0).put("index.knn", true).build(), + Settings.builder() + .put("number_of_shards", 2) + .put("number_of_replicas", 0) + .put("index.knn", true) + .put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0) + .build(), createKnnIndexMapping(FIELD_NAME, 2) ); diff --git a/src/test/java/org/opensearch/knn/recall/RecallTestsIT.java b/src/test/java/org/opensearch/knn/recall/RecallTestsIT.java index 3dfb67415..be2dd7b82 100644 --- a/src/test/java/org/opensearch/knn/recall/RecallTestsIT.java +++ b/src/test/java/org/opensearch/knn/recall/RecallTestsIT.java @@ -46,6 +46,7 @@ import static org.opensearch.knn.common.KNNConstants.PARAMETERS; import static org.opensearch.knn.common.KNNConstants.TYPE; import static org.opensearch.knn.common.KNNConstants.TYPE_KNN_VECTOR; +import static org.opensearch.knn.index.KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD; import static org.opensearch.knn.index.KNNSettings.KNN_ALGO_PARAM_EF_SEARCH; import static org.opensearch.knn.index.KNNSettings.KNN_ALGO_PARAM_INDEX_THREAD_QTY; import static org.opensearch.knn.index.KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_ENABLED; @@ -152,6 +153,7 @@ public void testRecall_whenNmslibHnswFP32_thenRecallAbove75percent() { .put("number_of_shards", SHARD_COUNT) .put("number_of_replicas", REPLICA_COUNT) .put("index.knn", true) + .put(INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0) .put(KNN_ALGO_PARAM_EF_SEARCH, HNSW_EF_SEARCH) .build(), builder.toString() @@ -531,6 +533,7 @@ private Settings getSettings() { .put("number_of_shards", SHARD_COUNT) .put("number_of_replicas", REPLICA_COUNT) .put("index.knn", true) + .put(INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, 0) .build(); } }