MB-60274: Set an upper bound for K value for KNN queries #1953
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
JIRA
https://issues.couchbase.com/browse/MB-60274
Description
Currently, the value of K in KNN queries is only lower-bounded to 1 without an upper limit. This lack of an upper boundary leads to issues where users setting K to extremely high values, such as 999999999, cause a crash due to excessive memory allocation exceeding 8GB.
To address this issue, this commit introduces an upper bound check for variable K. Setting an upper limit of 10000 for K prevents excessive memory demands, capping the maximum memory requirement at a reasonable 120KB. This change ensures system stability by preventing memory overflow issues caused by excessively high K values."