Skip to content

Commit

Permalink
Added the code to disable the graph builds and create graphs once
Browse files Browse the repository at this point in the history
Signed-off-by: Navneet Verma <navneev@amazon.com>
  • Loading branch information
navneet1v committed Apr 4, 2024
1 parent 771c4b5 commit 9c077ab
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tar.gz filter=lfs diff=lfs merge=lfs -text
32 changes: 32 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,35 @@ original PR with an appropriate label `backport <backport-branch-name>` is merge
run successfully on the PR. For example, if a PR on main needs to be backported to `1.x` branch, add a label
`backport 1.x` to the PR and make sure the backport workflow runs on the PR along with other checks. Once this PR is
merged to main, the workflow will create a backport PR to the `1.x` branch.


## Creating graphs once
1. Run this command to setup the cluster (code for OS: https://github.com/navneet1v/OpenSearch/tree/build-time)
```
./gradlew run -PcustomDistributionUrl="/path/to/repo/k-NN/temp/cluster.tar.gz"
```
2. First disable graph creation:
```
PUT _cluster/settings
{
"persistent": {
"knn.create_graphs": false
}
}
```

3. Now go ahead and index your data. and force merge segments down to 1.
4. Now enable the graph creation.
```
PUT _cluster/settings
{
"persistent": {
"knn.create_graphs": true
}
}
```
5. Now hit this API:
```
POST <index-name>/_forcemerge?one_merge=true
```
The above API will create a new segment and graph will be generated for that segment.
16 changes: 15 additions & 1 deletion src/main/java/org/opensearch/knn/index/KNNSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public class KNNSettings {
Setting.Property.Deprecated
);

public static final Setting<Boolean> CREATE_GRAPHS = Setting.boolSetting(
"knn.create_graphs",
false,
NodeScope, Dynamic
);

/**
* M - the number of bi-directional links created for every new element during construction.
* Reasonable range for M is 2-100. Higher M work better on datasets with high intrinsic
Expand Down Expand Up @@ -354,6 +360,10 @@ private Setting<?> getSetting(String key) {
return KNN_FAISS_AVX2_DISABLED_SETTING;
}

if("knn.create_graphs".equals(key)) {
return CREATE_GRAPHS;
}

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

Expand All @@ -371,7 +381,7 @@ public List<Setting<?>> getSettings() {
MODEL_INDEX_NUMBER_OF_REPLICAS_SETTING,
MODEL_CACHE_SIZE_LIMIT_SETTING,
ADVANCED_FILTERED_EXACT_SEARCH_THRESHOLD_SETTING,
KNN_FAISS_AVX2_DISABLED_SETTING
KNN_FAISS_AVX2_DISABLED_SETTING, CREATE_GRAPHS
);
return Stream.concat(settings.stream(), dynamicCacheSettings.values().stream()).collect(Collectors.toList());
}
Expand Down Expand Up @@ -513,6 +523,10 @@ public void onIndexModule(IndexModule module) {
});
}

public static boolean canCreateGraphs() {
return KNNSettings.state().getSettingValue("knn.create_graphs");
}

private static String percentageAsString(Integer percentage) {
return percentage + "%";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private KNNEngine getKNNEngine(@NonNull FieldInfo field) {

public void addKNNBinaryField(FieldInfo field, DocValuesProducer valuesProducer, boolean isMerge, boolean isRefresh)
throws IOException {
if(KNNSettings.canCreateGraphs() == false) {
log.info("Not creating graphs as value is : {}", KNNSettings.canCreateGraphs());
return;
}
log.info("Creating graphs as value is : {}", KNNSettings.canCreateGraphs());
// Get values to be indexed
BinaryDocValues values = valuesProducer.getBinary(field);
KNNCodecUtil.Pair pair = KNNCodecUtil.getFloats(values);
Expand Down
3 changes: 3 additions & 0 deletions temp/cluster.tar.gz
Git LFS file not shown

0 comments on commit 9c077ab

Please sign in to comment.