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

Move engine and lib components into separate files #438

Merged
merged 5 commits into from
Jul 13, 2022

Conversation

jmazanec15
Copy link
Member

@jmazanec15 jmazanec15 commented Jul 11, 2022

Description

Refactors current implementation of the KNNEngine and KNNLIbrary abstractions. It pulls out the different components into their own files so that they are more readable and easier to modify.

Additionally, refactors lib versioning logic. Right now, we have two methods related to versioning: getLatestBuildVersion and getLatestLibVersion. The build version is used to build the filename for the engine. However, the getLatestLibVersion is not used. So, this PR simplifies it to just maintain the current lib version as a string.

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.

Refactors library and engine structure to be less coupled. Pulls classes
and interfaces out into individual files. Additionally, renames package
from util to engine.

Signed-off-by: John Mazanec <jmazane@amazon.com>
Removes complex versioning related to the engines. Simplifies it to a
single string.

Signed-off-by: John Mazanec <jmazane@amazon.com>
Signed-off-by: John Mazanec <jmazane@amazon.com>
@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2022

Codecov Report

Merging #438 (6c05fd6) into main (03f0049) will decrease coverage by 0.23%.
The diff coverage is 81.37%.

@@             Coverage Diff              @@
##               main     #438      +/-   ##
============================================
- Coverage     84.02%   83.79%   -0.24%     
- Complexity      911      934      +23     
============================================
  Files           130      133       +3     
  Lines          3880     3831      -49     
  Branches        359      349      -10     
============================================
- Hits           3260     3210      -50     
- Misses          458      459       +1     
  Partials        162      162              
Impacted Files Coverage Δ
...main/java/org/opensearch/knn/index/util/Faiss.java 74.48% <74.48%> (ø)
...ain/java/org/opensearch/knn/index/util/Nmslib.java 83.33% <83.33%> (ø)
...index/codec/KNN80Codec/KNN80DocValuesConsumer.java 88.67% <100.00%> (-0.42%) ⬇️
.../java/org/opensearch/knn/index/util/KNNEngine.java 100.00% <100.00%> (ø)
...a/org/opensearch/knn/index/util/NativeLibrary.java 100.00% <100.00%> (ø)
...ava/org/opensearch/knn/index/KNNMethodContext.java 92.50% <0.00%> (-0.76%) ⬇️
...g/opensearch/knn/index/MethodComponentContext.java 91.13% <0.00%> (-0.63%) ⬇️
...java/org/opensearch/knn/index/MethodComponent.java 88.88% <0.00%> (-0.25%) ⬇️
.../main/java/org/opensearch/knn/index/KNNMethod.java 100.00% <0.00%> (ø)
...rg/opensearch/knn/index/codec/KNNCodecService.java 100.00% <0.00%> (ø)
... and 3 more

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 03f0049...6c05fd6. Read the comment docs.

@jmazanec15 jmazanec15 marked this pull request as ready for review July 11, 2022 20:01
@jmazanec15 jmazanec15 requested a review from a team July 11, 2022 20:01
class Nmslib extends NativeLibrary {

final static String HNSW_LIB_NAME = "hnsw";
final static String EXTENSION = ".hnsw";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final static String EXTENSION = ".hnsw";
final static String HNSW_LIB_EXTENSION = ".hnsw";

Copy link
Member Author

Choose a reason for hiding this comment

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

So this is a little bit confusing. HNSW_LIB_NAME is redundant with METHOD_HNSW, so I will delete that.

EXTENSION is actually the libraries extension. Given that we are in the Nmslib class, I think it can be kept as EXTENSION. Ill add a comment.

Signed-off-by: John Mazanec <jmazane@amazon.com>
@jmazanec15 jmazanec15 added 2.2.0 Refactoring Improve the design, structure, and implementation while preserving its functionality labels Jul 12, 2022
Signed-off-by: John Mazanec <jmazane@amazon.com>
*/
@SuppressWarnings("unchecked")
MethodAsMapBuilder addParameter(String parameterName, String prefix, String suffix) {
indexDescription += prefix;
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe we can refactor in one of next PRs to something more efficient like StringBuilder. Seems we're accumulating multiple small strings and concatenate all of them into one final string object.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense. Will take for future PR.

Copy link
Member

@martin-gaievski martin-gaievski left a comment

Choose a reason for hiding this comment

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

looks good, thank you

@jmazanec15 jmazanec15 merged commit fe9f293 into opensearch-project:main Jul 13, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 13, 2022
Refactors library and engine structure to be less coupled. Pulls classes
and interfaces out into individual files. Cleans up implementation.

Signed-off-by: John Mazanec <jmazane@amazon.com>
(cherry picked from commit fe9f293)
@heemin32 heemin32 added v2.2.0 and removed 2.2.0 labels Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Refactoring Improve the design, structure, and implementation while preserving its functionality v2.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants