forked from opensearch-project/k-NN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the default values for ef_search and ef_constrction for enabl…
…ing better indexing and search latency for vector search Signed-off-by: Navneet Verma <[email protected]>
- Loading branch information
Showing
6 changed files
with
130 additions
and
7 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/IndexSettingIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.knn.bwc; | ||
|
||
import org.junit.Assert; | ||
import org.opensearch.Version; | ||
import org.opensearch.knn.index.KNNSettings; | ||
|
||
public class IndexSettingIT extends AbstractRestartUpgradeTestCase { | ||
private static final String TEST_FIELD = "test-field"; | ||
private static final int DIMENSIONS = 5; | ||
|
||
public void testOldIndexSettingsPersistedAfterUpgrade() throws Exception { | ||
if(isRunningAgainstOldCluster()) { | ||
// create index with Old Values | ||
createKnnIndex(testIndex, getKNNDefaultIndexSettings(), createKnnIndexMapping(TEST_FIELD, DIMENSIONS)); | ||
int old_ef_search = Integer.parseInt(getIndexSettingByName(testIndex, | ||
KNNSettings.KNN_ALGO_PARAM_EF_SEARCH, true)); | ||
Assert.assertEquals(KNNSettings.INDEX_KNN_DEFAULT_ALGO_PARAM_EF_SEARCH.intValue(), old_ef_search); | ||
} else { | ||
int old_ef_search = Integer.parseInt(getIndexSettingByName(testIndex, | ||
KNNSettings.KNN_ALGO_PARAM_EF_SEARCH, true)); | ||
Assert.assertEquals(KNNSettings.INDEX_KNN_DEFAULT_ALGO_PARAM_EF_SEARCH.intValue(), old_ef_search); | ||
deleteKNNIndex(testIndex); | ||
} | ||
} | ||
|
||
// private void assertEfSearchOldDefaultValue(String indexName) { | ||
// if (Version.fromString(getBWCVersion().get()).onOrAfter(Version.V_2_10_0)) { | ||
// | ||
// } | ||
// | ||
// } | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/org/opensearch/knn/index/KNNIndexSettingProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.knn.index; | ||
|
||
import lombok.NoArgsConstructor; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.index.shard.IndexSettingProvider; | ||
|
||
@NoArgsConstructor | ||
public class KNNIndexSettingProvider implements IndexSettingProvider { | ||
|
||
private static final Settings EF_SEARCH_SETTING = Settings.builder().put(KNNSettings.KNN_ALGO_PARAM_EF_SEARCH, | ||
KNNSettings.INDEX_KNN_NEW_DEFAULT_ALGO_PARAM_EF_SEARCH).build(); | ||
|
||
/** | ||
* Returns explicitly set default index {@link Settings} for the given index. This should not | ||
* return null. | ||
* | ||
* @param indexName {@link String} name of the index | ||
* @param isDataStreamIndex boolean: index is a datastream index or not | ||
* @param templateAndRequestSettings {@link Settings} | ||
*/ | ||
@Override | ||
public Settings getAdditionalIndexSettings(String indexName, boolean isDataStreamIndex, Settings templateAndRequestSettings) { | ||
if(isKNNIndex(templateAndRequestSettings) && isEfSearchNotSetByUser(templateAndRequestSettings)) { | ||
return EF_SEARCH_SETTING; | ||
} | ||
return IndexSettingProvider.super.getAdditionalIndexSettings(indexName, isDataStreamIndex, templateAndRequestSettings); | ||
} | ||
|
||
private boolean isKNNIndex(Settings templateAndRequestSettings) { | ||
return templateAndRequestSettings.getAsBoolean(KNNSettings.KNN_INDEX, false); | ||
} | ||
|
||
private boolean isEfSearchNotSetByUser(Settings templateAndRequestSettings) { | ||
return templateAndRequestSettings.hasValue(KNNSettings.KNN_ALGO_PARAM_EF_SEARCH) == false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters