-
Notifications
You must be signed in to change notification settings - Fork 126
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
Refactor kNN codec related classes #582
Refactor kNN codec related classes #582
Conversation
Signed-off-by: Martin Gaievski <[email protected]>
Codecov Report
@@ Coverage Diff @@
## main #582 +/- ##
============================================
+ Coverage 83.60% 84.04% +0.43%
- Complexity 1026 1034 +8
============================================
Files 148 148
Lines 4233 4224 -9
Branches 373 373
============================================
+ Hits 3539 3550 +11
+ Misses 518 498 -20
Partials 176 176
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
49f71d4
to
f853c7b
Compare
Signed-off-by: Martin Gaievski <[email protected]>
f853c7b
to
95c47da
Compare
public KnnVectorsFormat getKnnVectorsFormatForField(final String field) { | ||
if (isKnnVectorFieldType(field) == false) { | ||
log.debug( | ||
String.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to use String.format here.
String.format( | |
log.debug("Initialize KNN vector format for field [{}] with default params [max_connections] = \"{}\" and [beam_width] = \"{}\"", field, defaultMaxConnections, defaultBeamWidth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
int maxConnections = getMaxConnections(params); | ||
int beamWidth = getBeamWidth(params); | ||
log.debug( | ||
String.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use String.format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
|
||
/** | ||
* Extends the Codec to support a new file format for KNN index | ||
* based on the mappings. | ||
* | ||
*/ | ||
public final class KNN910Codec extends FilterCodec { | ||
|
||
private static final String KNN910 = "KNN910Codec"; | ||
private static final KNNCodecVersion version = KNNCodecVersion.V_9_1_0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For static final variable, the naming convention should be VERSION
I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, good catch
|
||
private static final String KNN920 = "KNN920Codec"; | ||
|
||
private static final KNNCodecVersion version = KNNCodecVersion.V_9_2_0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final KNNCodecVersion version = KNNCodecVersion.V_9_2_0; | |
private static final KNNCodecVersion VERSION = KNNCodecVersion.V_9_2_0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
|
||
public class KNN940Codec extends FilterCodec { | ||
private static final String KNN940 = "KNN940Codec"; | ||
private static final KNNCodecVersion version = KNNCodecVersion.V_9_4_0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final KNNCodecVersion version = KNNCodecVersion.V_9_4_0; | |
private static final KNNCodecVersion VERSION = KNNCodecVersion.V_9_4_0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
Signed-off-by: Martin Gaievski <[email protected]>
@@ -16,15 +16,15 @@ | |||
import org.opensearch.knn.index.codec.KNNFormatFacade; | |||
|
|||
public class KNN940Codec extends FilterCodec { | |||
private static final KNNCodecVersion version = KNNCodecVersion.V_9_4_0; | |||
private static final KNNCodecVersion VERSION = KNNCodecVersion.V_9_4_0; | |||
private final KNNFormatFacade knnFormatFacade; | |||
private final PerFieldKnnVectorsFormat perFieldKnnVectorsFormat; | |||
|
|||
/** | |||
* No arg constructor that uses Lucene94 as the delegate | |||
*/ | |||
public KNN940Codec() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FAR: why not pass KNNCodecVersion as parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to have default constructor as per SPI contract, all codec classes are defined in corresponding registry file. In such case approach with parameter will not work
src/main/java/org/opensearch/knn/index/codec/KNN910Codec/KNN910Codec.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. Thanks @martin-gaievski!
The backport to
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-582-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 3d0a9d7ed6b1c609a9ab1ed2eff897dbe05fca63
# Push it to GitHub
git push --set-upstream origin backport/backport-582-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 |
* Refactor codec related classes, create KNNCodecVersion abstraction Signed-off-by: Martin Gaievski <[email protected]> (cherry picked from commit 3d0a9d7)
* Refactor codec related classes, create KNNCodecVersion abstraction Signed-off-by: Martin Gaievski <[email protected]> (cherry picked from commit 3d0a9d7)
* Refactor codec related classes, create KNNCodecVersion abstraction Signed-off-by: Martin Gaievski <[email protected]>
Signed-off-by: Martin Gaievski [email protected]
Description
Refactor codec related classes, main idea is to simplify changes related to Lucene/core version bump in future.
Introduce codec version class that abstracts context that is specific to Lucene version, current version of codec is defined in this version class.
Check List
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.