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 reset for vector #237

Merged

Conversation

martin-gaievski
Copy link
Member

Add ability to reset vector value by using 'null'

Description

Adding possibility to unset vector's value by updating vector field with 'null' value

Issues Resolved

#51

Check List

  • New functionality includes testing.
    • All tests pass
  • 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.

Adding posibility to reset vector value by updating it with null

Signed-off-by: Martin Gaievski <[email protected]>
@martin-gaievski martin-gaievski added the Features Introduces a new unit of functionality that satisfies a requirement label Dec 6, 2021
@martin-gaievski martin-gaievski requested review from VijayanB, jmazanec15 and a team December 6, 2021 23:01
@VijayanB VijayanB added the v1.3.0 Issues and PRs related to version 1.3.0 label Dec 7, 2021
@VijayanB VijayanB linked an issue Dec 7, 2021 that may be closed by this pull request
…case test based on similarity score

Signed-off-by: Martin Gaievski <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2021

Codecov Report

Merging #237 (550cbdd) into main (0c46bec) will increase coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #237      +/-   ##
============================================
+ Coverage     83.21%   83.22%   +0.01%     
- Complexity      864      865       +1     
============================================
  Files           123      123              
  Lines          3777     3780       +3     
  Branches        358      359       +1     
============================================
+ Hits           3143     3146       +3     
+ Misses          474      473       -1     
- Partials        160      161       +1     
Impacted Files Coverage Δ
...org/opensearch/knn/index/KNNVectorFieldMapper.java 83.61% <66.66%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c46bec...550cbdd. Read the comment docs.

VijayanB
VijayanB previously approved these changes Dec 7, 2021
@martin-gaievski
Copy link
Member Author

Added a bit more tests after discussing with Jack offline, scenario added: after vector has been reset to null we assign some value to vector again. After that document should be discoverable by search and when doc is retrieved the vector value should be updated

Comment on lines 428 to 432
//retrieving document by id
final Map<String, Object> knnDocMap = getKnnDoc(INDEX_NAME, docOneId);
final Float[] vectorInDocument = getVectorFromDocument(knnDocMap, FIELD_NAME);
assertEquals(vectorForDocumentOne.length, vectorInDocument.length);
assertArrayEquals(vectorForDocumentOne, vectorInDocument);
Copy link
Member

Choose a reason for hiding this comment

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

Whats the purpose of this assertion? I think the test can remove this to simplify the test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, we can assert documents fields after the update only, this particular assertion is redundant. I'll remove it in next commit

addKnnDoc(INDEX_NAME, docTwoId, FIELD_NAME, vectorForDocumentTwo);

//checking that one of two documents in retrievable based on closer similarity to query vector
int k = 1;
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just make k = 2 and then:

  1. Make sure 2 docs are returned by the k-NN query
  2. Update doc 2 to null
  3. Assert the value returned from retrieving doc is null
  4. Make sure 1 doc is returned by the k-NN query when k = 2 (doc id 1)
  5. Update doc 2 back to the vector
  6. Make sure retrieving doc 2 gives the correct vector
  7. Make sure 2 docs are returned by the k-NN query

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed offline, changing test to use k equals 2 instead of 1 for knn searches

Copy link
Member

@jmazanec15 jmazanec15 left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@martin-gaievski martin-gaievski merged commit 7a676eb into opensearch-project:main Dec 7, 2021
@martin-gaievski martin-gaievski deleted the reset-vector-value branch December 7, 2021 22:42
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Mar 7, 2022
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Mar 7, 2022
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Features Introduces a new unit of functionality that satisfies a requirement v1.3.0 Issues and PRs related to version 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Provide possibility to unset value for vector field(reset)
4 participants