Skip to content

Commit

Permalink
Update knn index default to always do approximate search
Browse files Browse the repository at this point in the history
Signed-off-by: Vijayan Balasubramanian <[email protected]>
  • Loading branch information
VijayanB committed Dec 12, 2024
1 parent 2b9a741 commit 5701675
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ protected static final boolean isRunningAgainstOldCluster() {
protected final Optional<String> getBWCVersion() {
return Optional.ofNullable(System.getProperty(BWC_VERSION, null));
}

@Override
protected Settings getKNNDefaultIndexSettings() {
if (isApproximateThresholdSupported(getBWCVersion())) {
return super.getKNNDefaultIndexSettings();
}
// for bwc will return old default setting without approximate value threshold setting
return getDefaultIndexSettings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@ protected final Optional<String> getBWCVersion() {
return Optional.ofNullable(System.getProperty(BWC_VERSION, null));
}

@Override
protected Settings getKNNDefaultIndexSettings() {
if (isApproximateThresholdSupported(getBWCVersion())) {
return super.getKNNDefaultIndexSettings();
}
// for bwc will return old default setting without approximate value threshold setting
return getDefaultIndexSettings();
}

}
4 changes: 2 additions & 2 deletions src/test/java/org/opensearch/knn/index/OpenSearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public void testKNNIndex_whenBuildGraphThresholdIsPresent_thenGetThresholdValue(
public void testKNNIndex_whenBuildThresholdIsNotProvided_thenShouldNotReturnSetting() throws Exception {
final String knnIndexMapping = createKnnIndexMapping(FIELD_NAME, KNNEngine.getMaxDimensionByEngine(KNNEngine.DEFAULT));
final String indexName = "test-index-with-build-graph-settings";
createKnnIndex(indexName, knnIndexMapping);
createKnnIndex(indexName, getDefaultIndexSettings(), knnIndexMapping);
final String buildVectorDataStructureThresholdSetting = getIndexSettingByName(
indexName,
KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD
Expand All @@ -655,7 +655,7 @@ public void testKNNIndex_whenBuildThresholdIsNotProvided_thenShouldNotReturnSett
public void testKNNIndex_whenGetIndexSettingWithDefaultIsCalled_thenReturnDefaultBuildGraphThresholdValue() throws Exception {
final String knnIndexMapping = createKnnIndexMapping(FIELD_NAME, KNNEngine.getMaxDimensionByEngine(KNNEngine.DEFAULT));
final String indexName = "test-index-with-build-vector-graph-settings";
createKnnIndex(indexName, knnIndexMapping);
createKnnIndex(indexName, getDefaultIndexSettings(), knnIndexMapping);
final String buildVectorDataStructureThresholdSetting = getIndexSettingByName(
indexName,
KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,14 @@ protected void updateClusterSettings(String settingKey, Object value) throws Exc
* Return default index settings for index creation
*/
protected Settings getKNNDefaultIndexSettings() {
return Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put("index.knn", true).build();
return buildKNNIndexSettings(0);
}

/**
* Return default index settings for index creation
*/
protected Settings getDefaultIndexSettings() {
return Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0).put(KNN_INDEX, true).build();
}

protected Settings getKNNSegmentReplicatedIndexSettings() {
Expand Down

0 comments on commit 5701675

Please sign in to comment.