Skip to content

[Enhancement] Optimize Merge On KNN Field when soft_delete mode - #18050

Open
luyuncheng wants to merge 1 commit into
opensearch-project:mainfrom
luyuncheng:OPT_Merge
Open

[Enhancement] Optimize Merge On KNN Field when soft_delete mode#18050
luyuncheng wants to merge 1 commit into
opensearch-project:mainfrom
luyuncheng:OPT_Merge

Conversation

@luyuncheng

@luyuncheng luyuncheng commented Apr 23, 2025

Copy link
Copy Markdown
Contributor

Description

[Describe what this change achieves]
when #1933 and #2077, OpenSearch always use soft deletes. but it would bring some performance drops.

OpenSearch K-NN would use KNN80BinaryDocValues with native engine and KNNVectorValues with lucene engine.

I found some scenarios as followings:

in some update scenarios, like index 10000 docs, and update/delete 60% docs, in one segment.
and then happens merge tasks. nativeEngine would merge all docs including deleted docs because of soft_delete mode.

easy tests like

int numBinary = 0;
BinaryDocValues binaryDocValues = leafReader.getBinaryDocValues("binary");
while (binaryDocValues.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
numBinary++;
}
assertEquals(numBinary, numUniqueDocs);

but we do not want to do heavy construct HNSW graph which is a CPU consuming tasks. and merge task take a very long time to index useless docs.

so i think we can skip this soft_delete docs at merge and it can optimize merge and index time obviously 30% at out benchmarks

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

Signed-off-by: luyuncheng <luyuncheng@bytedance.com>
@luyuncheng

Copy link
Copy Markdown
Contributor Author

@jmazanec15 @navneet1v i create a pr at OpenSearch repo for k-NN enhancement, because plugin can not handle merge controls, also would you please take a look about this enhancement?

@github-actions

Copy link
Copy Markdown
Contributor

❌ Gradle check result for d9b585c: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@bugmakerrrrrr bugmakerrrrrr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@luyuncheng Good idea! I left some comments, also I was wondering if this would affect recovery if I enable derived source.

@Override
public BinaryDocValues getBinary(FieldInfo fieldInfo) throws IOException {
BinaryDocValues binaryDocValues = docValuesProducer.getBinary(fieldInfo);
if (binaryDocValues != null && fieldInfo.attributes().containsKey(KNN_FIELD)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know if we should expose something of the plugin within the core. Maybe we can provide an extension point in the engine plugin.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@luyuncheng I think we should just make this generic. Why we want to make this specific to k-NN. Docs containing BDV should just be removed if they are deleted. What is the point of having the deleted docs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we should just make this generic. Why we want to make this specific to k-NN. Docs containing BDV should just be removed if they are deleted. What is the point of having the deleted docs?

Good Idea. i think all BinaryDocValues should skipped on merge with soft_deletes.

}

@Override
public KnnVectorsReader getVectorReader() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why don't we pruning the vector field?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 on this.

@luyuncheng luyuncheng Apr 25, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i need to override the KnnVectorsReader with different type like 'FloatVectorValues' and 'ByteVectorValues' and handle the iterator with different type and merge logic. so i think it would be better to create new PR and handle KnnVectorsReader carefully

@navneet1v

Copy link
Copy Markdown
Contributor

@jmazanec15 @navneet1v i create a pr at OpenSearch repo for k-NN enhancement, because plugin can not handle merge controls, also would you please take a look about this enhancement?

Sure I will take a look.

@navneet1v

Copy link
Copy Markdown
Contributor

@luyuncheng can you share some details on the soft_delete mode, since this is something I have not done any deep-dive on. Getting that understanding will help review the PR in better fashion.

@luyuncheng

Copy link
Copy Markdown
Contributor Author

can you share some details on the soft_delete mode, since this is something I have not done any deep-dive on. Getting that understanding will help review the PR in better fashion.

@navneet1v SoftDelete comes from https://issues.apache.org/jira/browse/LUCENE-8233 which is aim to maintain document history and make deleted docs can be retrieved even merges happened.

softdelete would record all changes for the docs, and write it into docValues. it changes to defaults mode at OpenSearch #1933 and at #2077.
But OpenSearch only use SoftDelete for _source retrieve, when delete/updates happens we should not rebuild knn graph for saving the CPU resources. so i create this pr to skip it

@jmazanec15

Copy link
Copy Markdown
Member

@luyuncheng will take a look - sorry I missed this one

@jmazanec15

Copy link
Copy Markdown
Member

Overall, this PR seems great to me! Thanks @luyuncheng! This looks like it would provide a clear benefit on merge.

@luyuncheng Do you know where in OpenSearch code base soft deletes are accessed to provide document history/delete recovery? One potential implication of making this change would be that features like derived source would not work to retrieve these vector values if they are not indexed into DocValues/VectorValues.

@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot Bot added the stalled Issues that have stalled label Jun 15, 2025
@opensearch-trigger-bot opensearch-trigger-bot Bot removed the stalled Issues that have stalled label Jun 28, 2025
@opensearch-trigger-bot

Copy link
Copy Markdown
Contributor

This PR is stalled because it has been open for 30 days with no activity.

@opensearch-trigger-bot opensearch-trigger-bot Bot added the stalled Issues that have stalled label Aug 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lucene stalled Issues that have stalled

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants