Skip to content

Adjusting the merge policy setting to make merges less aggressive#3128

Open
shatejas wants to merge 10 commits intoopensearch-project:mainfrom
shatejas:merge-policy-fix
Open

Adjusting the merge policy setting to make merges less aggressive#3128
shatejas wants to merge 10 commits intoopensearch-project:mainfrom
shatejas:merge-policy-fix

Conversation

@shatejas
Copy link
Collaborator

@shatejas shatejas commented Feb 24, 2026

Description

The default setting for opensearch changed, this caused faiss graph creation to use more CPU possibly affecting searches for cases where merge and search is happening on the same cluster. This change makes sure k-NN indices have less aggressive defaults

Related Issues

None

Testing details

Index created:

{
  "settings": {
    "index": {
			"knn": "true",
      "number_of_shards": 1,
      "number_of_replicas": 0,
			"knn.derived_source.enabled": false
    }
  },
  "mappings": {
    "properties": {
      "location": {
        "type": "knn_vector",
        "dimension": 768,
        "method": {
          "name": "hnsw",
          "space_type": "cosinesimil",
          "engine": "{{ _.engine }}",
          "parameters": {
            "ef_construction": 200,
            "m": 16
          }
        }
      },
			"tenant": {
				"type" : "text"
			}
    }
  }
}
{
	"target_index": {
		"settings": {
			"index": {
				"replication": {
					"type": "DOCUMENT"
				},
				"number_of_shards": "1",
				"provided_name": "target_index",
				"merge": {
					"policy": {
						"floor_segment": "2mb",
						"max_merge_at_once": "10"
					}
				},
				"knn": "true",
				"creation_date": "1771961852031",
				"number_of_replicas": "0",
				"uuid": "U4m6NE8KS0SSg-GqCLUdvQ",
				"version": {
					"created": "137277827"
				},
				"knn.derived_source": {
					"enabled": "false"
				}
			}
		}
	}
}

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

The default setting for opensearch changed, this caused faiss graph
creation to use more CPU possibly affecting searches for cases
where merge and search is happening on the same cluster. This change
makes sure k-NN indices have less aggressive defaults

Signed-off-by: Tejas Shah <shatejas@amazon.com>
Signed-off-by: Tejas Shah <shatejas@amazon.com>
CHANGELOG.md Outdated

### Bug Fixes
* Fix score conversion logic for radial exact search [#3110](https://github.com/opensearch-project/k-NN/pull/3110)
* Adjusting the merge policy setting to make merges less aggressive [#3128](https://github.com/opensearch-project/k-NN/pull/3128)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should move this to enhancement section

Comment on lines +291 to +294
// Aggressive merges for k-NN can hogg CPU which can degrade search performance
// These settings are being overridden to make it less aggressive
// Core has max_merge_at_once default as 30, which can make merges more aggressive
.put("index.merge.policy.max_merge_at_once", 10)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also lets have a IT to validate that index settings are getting set with correct values for index.knn true and false

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Signed-off-by: Tejas Shah <shatejas@amazon.com>
Vikasht34
Vikasht34 previously approved these changes Feb 24, 2026
Copy link
Collaborator

@Vikasht34 Vikasht34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Signed-off-by: Tejas Shah <shatejas@amazon.com>
String derivedSourceEnabled = getIndexSettingByName(indexName, KNN_DERIVED_SOURCE_ENABLED);
assertEquals(Boolean.toString(isKnnIndex), derivedSourceEnabled);

String maxMergeAtOnce = getIndexSettingByName(indexName, "index.merge.policy.max_merge_at_once", !isKnnIndex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We can use the settings key here as well

Signed-off-by: Tejas Shah <shatejas@amazon.com>
Signed-off-by: Tejas Shah <shatejas@amazon.com>
navneet1v
navneet1v previously approved these changes Mar 10, 2026
@navneet1v
Copy link
Collaborator

@shatejas Lets fix the CI issues.

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.44%. Comparing base (a2372a3) to head (ca24f9d).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #3128   +/-   ##
=========================================
  Coverage     82.43%   82.44%           
  Complexity     3874     3874           
=========================================
  Files           418      418           
  Lines         14474    14479    +5     
  Branches       1851     1851           
=========================================
+ Hits          11932    11937    +5     
  Misses         1782     1782           
  Partials        760      760           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Navneet Verma <navneev@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants