Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds rescore parameter to KNNQuery #1969

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

jmazanec15
Copy link
Member

Description

Adds rescore parameter to knn query. With this commit, the rescore is a no-op. The functionality and validation will be added in a later commit.

The valid options look like:

"query": {
  "knn": {
    "target_field": {
      "vector": [0, 0],
      "k": 100,
      "rescore": true
    }
  }
}

"query": {
  "knn": {
    "target_field": {
      "vector": [0, 0],
      "k": 100,
      "rescore": {}
    }
  }
}

  "query": {
    "knn": {
      "target_field": {
        "vector": [0, 0],
        "k": 100,
        "rescore": {
            "oversample_factor": 1.2
        }
      }
    }
  }

Will update changelog once feature is completed

Related Issues

Related to #1779

Check List

  • Commits are signed per the DCO using --signoff.

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.

Adds rescore parameter to knn query. With this commit, the rescore is a
no-op. The functionality and validation will be added in a later commit.

Signed-off-by: John Mazanec <[email protected]>
src/main/java/org/opensearch/knn/common/KNNConstants.java Outdated Show resolved Hide resolved
public final class RescoreContext {

public static final float DEFAULT_OVERSAMPLE_FACTOR = 1.0f;
public static final float MAX_OVERSAMPLE_FACTOR = 5.0f;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jmazanec15 will 5 be good enough may be 100? I know nothing is good enough. but I was thinking with 100 as max and a cap of 10K on the k*oversampling factor should cover most of the cases.

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure I can increase. Let me update

@@ -110,6 +124,10 @@ public static KNNQueryBuilder.Builder streamInput(StreamInput in, Function<Strin
builder.methodParameters(MethodParametersParser.streamInput(in, IndexUtil::isClusterOnOrAfterMinRequiredVersion));
}

if (minClusterVersionCheck.apply(RESCORE_PARAMETER)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will affect neural, just a heads up

@@ -48,6 +48,8 @@ public class IndexUtil {
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_RADIAL_SEARCH = Version.V_2_14_0;
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_METHOD_PARAMETERS = Version.V_2_16_0;
private static final Version MINIMAL_SUPPORTED_VERSION_FOR_MODEL_VECTOR_DATA_TYPE = Version.V_2_16_0;
// TODO: Will update once 2.17 backport change is merged
private static final Version MINIMAL_RESCORE_FEATURE = Version.V_3_0_0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Look around if there is a need to have this in neural plugin

@@ -776,19 +777,23 @@ public void testDoToQuery_InvalidZeroByteVector() {

public void testSerialization() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Does KNNQueryBuilderValidParamsTests and KNNQueryBuilderInvalidParamsTests need an update?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ill add some basic ones, but do most of testing in the Rescore validation tests

Signed-off-by: John Mazanec <[email protected]>
Copy link
Member

@ryanbogan ryanbogan left a comment

Choose a reason for hiding this comment

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

LGTM

import static org.opensearch.knn.index.query.parser.RescoreParser.RESCORE_OVERSAMPLE_PARAMETER;
import static org.opensearch.knn.index.query.parser.RescoreParser.RESCORE_PARAMETER;

public class QueryParseIT extends KNNRestTestCase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: https://github.com/opensearch-project/k-NN/blob/main/src/test/java/org/opensearch/knn/index/query/InvalidSearchQueryIT.java

Seems like a duplicate in a way, maybe added a todo on one of them to merge for later

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that probably makes sense. Let me make a note on this and come back with it in another PR, with some other test cleanup.

Copy link
Contributor

@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 !!

@jmazanec15 jmazanec15 merged commit 9db7058 into opensearch-project:main Aug 15, 2024
31 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Aug 15, 2024
Adds rescore parameter to knn query. With this commit, the rescore is a
no-op. The functionality and validation will be added in a later commit.

Signed-off-by: John Mazanec <[email protected]>
(cherry picked from commit 9db7058)
junqiu-lei pushed a commit that referenced this pull request Aug 15, 2024
* Adds rescore parameter to KNNQuery (#1969)

Adds rescore parameter to knn query. With this commit, the rescore is a
no-op. The functionality and validation will be added in a later commit.

Signed-off-by: John Mazanec <[email protected]>
(cherry picked from commit 9db7058)

* fix version

Signed-off-by: John Mazanec <[email protected]>

---------

Signed-off-by: John Mazanec <[email protected]>
Co-authored-by: John Mazanec <[email protected]>
akashsha1 pushed a commit to akashsha1/k-NN that referenced this pull request Sep 16, 2024
Adds rescore parameter to knn query. With this commit, the rescore is a
no-op. The functionality and validation will be added in a later commit.

Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: Akash Shankaran <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants