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

Add stored fields for knn_vector type #1630

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

jmazanec15
Copy link
Member

Description

Fixes bug where we were not creating stored field type for knn_vector even when the mapping parameter is passed. To do this, we create a stored field from the bytes of the vectors. Then, implemented valueForDisplay in order to ensure that the vectors are displayed properly.

Example:

Request:
{
  "stored_fields": ["test_vector"],
  "query": {
    "match_all": {}
  }
}

Response:
{
  "took":248,
  "timed_out":false,
  "_shards":{
    "total":1,
    "successful":1,
    "skipped":0,
    "failed":0
  },
  "hits":{
    "total":{
      "value":1,
      "relation":"eq"
    },
    "max_score":1.0,
    "hits":[
      {
        "_index":"test_index",
        "_id":"1",
        "_score":1.0,
        "fields":{"test_vector":[[-128,0,1,127]]}
      }
    ]
  }
}

Along with this, clean up the field mapper implementations.

Add relevant uTs and iTs to ensure functionality is working as expected.

Issues Resolved

#1606

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed as 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.

@jmazanec15 jmazanec15 added Bug Fixes Changes to a system or product designed to handle a programming bug/glitch backport 2.x backport 2.13 labels Apr 18, 2024
@@ -109,8 +98,8 @@ private static KNNVectorFieldMapper toType(FieldMapper in) {
public static class Builder extends ParametrizedFieldMapper.Builder {
protected Boolean ignoreMalformed;

protected final Parameter<Boolean> stored = Parameter.boolParam("store", false, m -> toType(m).stored, false);
protected final Parameter<Boolean> hasDocValues = Parameter.boolParam("doc_values", false, m -> toType(m).hasDocValues, true);
protected final Parameter<Boolean> stored = Parameter.storeParam(m -> toType(m).stored, false);
Copy link
Member Author

Choose a reason for hiding this comment

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

changed these to use built ins to clean up the code.

@@ -735,11 +733,6 @@ Optional<float[]> getFloatsFromContext(ParseContext context, int dimension, Meth
return Optional.of(array);
}

@Override
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed as it is default for ParametrizedFieldMapper

@jmazanec15
Copy link
Member Author

@luyuncheng could you take a look at this PR?

@jmazanec15 jmazanec15 requested a review from navneet1v April 19, 2024 16:42
Fixes bug where we were not creating stored field type for knn_vector
even when the mapping parameter is passed. Along with this, clean up
the field mapper implementations.

Add relevant uTs and iTs to ensure functionality is working as expected.

Signed-off-by: John Mazanec <jmazane@amazon.com>
@jmazanec15 jmazanec15 merged commit 699510d into opensearch-project:main Apr 22, 2024
53 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-1630-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 699510d61dd8c583653118be172fb60a00463760
# Push it to GitHub
git push --set-upstream origin backport/backport-1630-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-1630-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.13 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.13 2.13
# Navigate to the new working tree
cd .worktrees/backport-2.13
# Create a new branch
git switch --create backport/backport-1630-to-2.13
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 699510d61dd8c583653118be172fb60a00463760
# Push it to GitHub
git push --set-upstream origin backport/backport-1630-to-2.13
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.13

Then, create a pull request where the base branch is 2.13 and the compare/head branch is backport/backport-1630-to-2.13.

jmazanec15 added a commit to jmazanec15/k-NN-1 that referenced this pull request Apr 22, 2024
Fixes bug where we were not creating stored field type for knn_vector
even when the mapping parameter is passed. Along with this, clean up
the field mapper implementations.

Add relevant uTs and iTs to ensure functionality is working as expected.

Signed-off-by: John Mazanec <jmazane@amazon.com>
(cherry picked from commit 699510d)
Signed-off-by: John Mazanec <jmazane@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport 2.13 Bug Fixes Changes to a system or product designed to handle a programming bug/glitch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants