Skip to content

Commit

Permalink
Add cluster setting
Browse files Browse the repository at this point in the history
  • Loading branch information
VijayanB committed Aug 15, 2024
1 parent c8ec49f commit f3f2c81
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/main/java/org/opensearch/knn/index/KNNSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public class KNNSettings {
public static final String MODEL_CACHE_SIZE_LIMIT = "knn.model.cache.size.limit";
public static final String ADVANCED_FILTERED_EXACT_SEARCH_THRESHOLD = "index.knn.advanced.filtered_exact_search_threshold";
public static final String KNN_FAISS_AVX2_DISABLED = "knn.faiss.avx2.disabled";
public static final String KNN_SKIP_BUILDING_GRAPH = "knn.skip_building_graph";
/**
* TODO: This setting is only added to ensure that main branch of k_NN plugin doesn't break till other parts of the
* code is getting ready. Will remove this setting once all changes related to integration of KNNVectorsFormat is added
* for native engines.
*/
public static final String KNN_USE_LUCENE_VECTOR_FORMAT_ENABLED = "knn.use.format.enabled";

/**
* Default setting values
Expand Down Expand Up @@ -254,6 +261,27 @@ public class KNNSettings {
);

/**
<<<<<<< HEAD
=======
* TODO: This setting is only added to ensure that main branch of k_NN plugin doesn't break till other parts of the
* code is getting ready. Will remove this setting once all changes related to integration of KNNVectorsFormat is added
* for native engines.
*/
public static final Setting<Boolean> KNN_USE_LUCENE_VECTOR_FORMAT_ENABLED_SETTING = Setting.boolSetting(
KNN_USE_LUCENE_VECTOR_FORMAT_ENABLED,
false,
NodeScope
);

public static final Setting<Boolean> KNN_SKIP_BUILDING_GRAPH_SETTING = Setting.boolSetting(
KNN_SKIP_BUILDING_GRAPH,
false,
NodeScope,
Dynamic
);

/**
>>>>>>> fae6ebcf... sample
* Dynamic settings
*/
public static Map<String, Setting<?>> dynamicCacheSettings = new HashMap<String, Setting<?>>() {
Expand Down Expand Up @@ -370,6 +398,14 @@ private Setting<?> getSetting(String key) {
return KNN_VECTOR_STREAMING_MEMORY_LIMIT_PCT_SETTING;
}

if (KNN_USE_LUCENE_VECTOR_FORMAT_ENABLED.equals(key)) {
return KNN_USE_LUCENE_VECTOR_FORMAT_ENABLED_SETTING;
}

if (KNN_SKIP_BUILDING_GRAPH.equals(key)) {
return KNN_SKIP_BUILDING_GRAPH_SETTING;
}

throw new IllegalArgumentException("Cannot find setting by key [" + key + "]");
}

Expand All @@ -388,7 +424,9 @@ public List<Setting<?>> getSettings() {
MODEL_CACHE_SIZE_LIMIT_SETTING,
ADVANCED_FILTERED_EXACT_SEARCH_THRESHOLD_SETTING,
KNN_FAISS_AVX2_DISABLED_SETTING,
KNN_VECTOR_STREAMING_MEMORY_LIMIT_PCT_SETTING
KNN_VECTOR_STREAMING_MEMORY_LIMIT_PCT_SETTING,
KNN_USE_LUCENE_VECTOR_FORMAT_ENABLED_SETTING,
KNN_SKIP_BUILDING_GRAPH_SETTING
);
return Stream.concat(settings.stream(), dynamicCacheSettings.values().stream()).collect(Collectors.toList());
}
Expand All @@ -409,6 +447,10 @@ public static double getCircuitBreakerUnsetPercentage() {
return KNNSettings.state().getSettingValue(KNNSettings.KNN_CIRCUIT_BREAKER_UNSET_PERCENTAGE);
}

public static boolean shouldSkipBuildingGraph() {
return state().getSettingValue(KNN_SKIP_BUILDING_GRAPH);
}

public static boolean isFaissAVX2Disabled() {
try {
return KNNSettings.state().getSettingValue(KNNSettings.KNN_FAISS_AVX2_DISABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,17 @@ private KNNEngine getKNNEngine(@NonNull FieldInfo field) {
return KNNEngine.getEngine(engineName);
}

private boolean shouldSkipAddingKNNBinaryField() {
return KNNSettings.shouldSkipBuildingGraph();
}

public void addKNNBinaryField(FieldInfo field, DocValuesProducer valuesProducer, boolean isMerge, boolean isRefresh)
throws IOException {
if (shouldSkipAddingKNNBinaryField()) {
log.info("skipping graph");
return;
}
log.info("Will build graph");
// Get values to be indexed
BinaryDocValues values = valuesProducer.getBinary(field);
final KNNEngine knnEngine = getKNNEngine(field);
Expand Down

0 comments on commit f3f2c81

Please sign in to comment.