-
Notifications
You must be signed in to change notification settings - Fork 114
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 mappers to separate files #448
Move mappers to separate files #448
Conversation
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
} | ||
} | ||
|
||
Optional<float[]> getFloatsFromContext(ParseContext context, int dimension) throws IOException { |
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 part will be common with Lucene field mapper, extract it to a method to avoid code duplication
if (!KNNSettings.isKNNPluginEnabled()) { | ||
throw new IllegalStateException("KNN plugin is disabled. To enable " + "update knn.plugin.enabled setting to true"); | ||
validateIfKNNPluginEnabled(); | ||
validateIfCircuitBreakerTriggered(); |
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 part will be common with Lucene field mapper, extract it to a method to avoid code duplication
Codecov Report
@@ Coverage Diff @@
## main #448 +/- ##
============================================
+ Coverage 83.82% 83.86% +0.03%
- Complexity 933 948 +15
============================================
Files 133 136 +3
Lines 3828 3842 +14
Branches 349 349
============================================
+ Hits 3209 3222 +13
- Misses 457 458 +1
Partials 162 162
Continue to review full report at Codecov.
|
if (!KNNSettings.isKNNPluginEnabled()) { | ||
throw new IllegalStateException("KNN plugin is disabled. To enable " + "update knn.plugin.enabled setting to true"); | ||
validateIfKNNPluginEnabled(); | ||
validateIfCircuitBreakerTriggered(); |
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.
nit: May be validateIfCircuitBreakerIsNotTriggered??
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
@@ -69,7 +61,7 @@ | |||
*/ | |||
public abstract class KNNVectorFieldMapper extends ParametrizedFieldMapper { | |||
|
|||
private static Logger logger = LogManager.getLogger(KNNVectorFieldMapper.class); | |||
static Logger logger = LogManager.getLogger(KNNVectorFieldMapper.class); |
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.
lombok?
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
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.
realized that lombok logger is only private. we used that old logger in one of the sub-classes, I guess that's ok to create it's own logger specifically for that class. It will change a log file content a bit, as I think it places class name in the line prefix.
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.
make it protected rather than package private, why not create the logger in the class which is using it rather than creating it in the parent class.
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. |
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.
* | |
* The OpenSearch Contributors require contributions made to | |
* this file be licensed under the Apache-2.0 license or a | |
* compatible open source license. | |
* | |
* Modifications Copyright OpenSearch Contributors. See | |
* GitHub history for details. |
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
@@ -69,7 +61,7 @@ | |||
*/ | |||
public abstract class KNNVectorFieldMapper extends ParametrizedFieldMapper { | |||
|
|||
private static Logger logger = LogManager.getLogger(KNNVectorFieldMapper.class); | |||
static Logger logger = LogManager.getLogger(KNNVectorFieldMapper.class); |
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.
why not private?
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.
I was thinking or re-using same logger in sub-class to keep content of the log file same, as it puts the class name there.
But I on second though it should be a problem as long as we keep the content same.
Let me update, I also will use lombok for logger initialization
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.
I would suggest use different loggers for different classes specially for parent and child as sometimes it become difficult to find the right code path.
"Model \"" | ||
+ modelId | ||
+ "\" from " | ||
+ context.mapperService().index().getName() | ||
+ "'s mapping does not exist. Because the " | ||
+ "\"" | ||
+ MODEL_ID | ||
+ "\" parameter is not updateable, this index will need to " | ||
+ "be recreated with a valid model." |
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 can use String.format here, rather than "+" operator.
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
…license header Signed-off-by: Martin Gaievski <gaievski@amazon.com>
|
||
void validateIfKNNPluginEnabled() { | ||
if (!KNNSettings.isKNNPluginEnabled()) { | ||
throw new IllegalStateException("KNN plugin is disabled. To enable " + "update knn.plugin.enabled setting to true"); |
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.
nit: Remove + in middle?
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
import static org.opensearch.knn.common.KNNConstants.SPACE_TYPE; | ||
|
||
/** | ||
* Field mapper for original implementation |
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.
minor: Do you think we should add what the mapping looks like so users have more context?
{
"type": "knn_vector",
"dimension": 128
}
Also, add something like "This is the mapper for the original version. It defaults to using nmslib as the engine and retrieves parameters from index settings."
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
String spaceType = indexSettings.get(KNNSettings.INDEX_KNN_SPACE_TYPE.getKey()); | ||
if (spaceType == null) { | ||
log.info( | ||
"[KNN] The setting \"" |
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.
Should this use string builder?
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.
yeah, I think build and/or String.format for params, ack
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
* Move mappers to separate files Signed-off-by: Martin Gaievski <gaievski@amazon.com> (cherry picked from commit cfac544)
Signed-off-by: Martin Gaievski gaievski@amazon.com
Description
This is in preparation for new LuceneField mapper to keep size of KNNVectorFieldMapper manageable and to structure project better.
Extract mapper classes from file with abstract class KNNVectorFieldMapper to separate files, created new "mapper" package for new classes.
Issues Resolved
building block for #39
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.