-
Notifications
You must be signed in to change notification settings - Fork 132
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
Added more detailed error messages for KNN model training #2378
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import org.opensearch.common.ValidationException; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.knn.index.VectorDataType; | ||
import org.opensearch.knn.index.engine.MethodComponentContext; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.transport.TransportRequestOptions; | ||
|
@@ -31,6 +32,9 @@ | |
import java.util.Map; | ||
|
||
import static org.opensearch.knn.common.KNNConstants.BYTES_PER_KILOBYTES; | ||
import static org.opensearch.knn.common.KNNConstants.METHOD_PARAMETER_NLIST; | ||
import static org.opensearch.knn.common.KNNConstants.ENCODER_PARAMETER_PQ_CODE_SIZE; | ||
import static org.opensearch.knn.common.KNNConstants.METHOD_ENCODER_PARAMETER; | ||
import static org.opensearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER; | ||
|
||
/** | ||
|
@@ -134,6 +138,30 @@ protected void getTrainingIndexSizeInKB(TrainingModelRequest trainingModelReques | |
trainingVectors = trainingModelRequest.getMaximumVectorCount(); | ||
} | ||
|
||
long minTrainingVectorCount = 1000; | ||
MethodComponentContext encoderContext = (MethodComponentContext) trainingModelRequest.getKnnMethodContext() | ||
.getMethodComponentContext() | ||
.getParameters() | ||
.get(METHOD_ENCODER_PARAMETER); | ||
|
||
if (trainingModelRequest.getKnnMethodContext().getMethodComponentContext().getParameters().containsKey(METHOD_PARAMETER_NLIST) | ||
&& encoderContext.getParameters().containsKey(ENCODER_PARAMETER_PQ_CODE_SIZE)) { | ||
|
||
int nlist = ((Integer) trainingModelRequest.getKnnMethodContext() | ||
.getMethodComponentContext() | ||
.getParameters() | ||
.get(METHOD_PARAMETER_NLIST)); | ||
int code_size = ((Integer) encoderContext.getParameters().get(ENCODER_PARAMETER_PQ_CODE_SIZE)); | ||
minTrainingVectorCount = (long) Math.max(nlist, Math.pow(2, code_size)); | ||
} | ||
|
||
if (trainingVectors < minTrainingVectorCount) { | ||
ValidationException exception = new ValidationException(); | ||
exception.addValidationError("Number of training points should be greater than " + minTrainingVectorCount); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use String.format for concatenation |
||
listener.onFailure(exception); | ||
return; | ||
} | ||
|
||
listener.onResponse( | ||
estimateVectorSetSizeInKB(trainingVectors, trainingModelRequest.getDimension(), trainingModelRequest.getVectorDataType()) | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ | |
|
||
import java.io.IOException; | ||
|
||
import static org.opensearch.knn.common.KNNConstants.ENCODER_PARAMETER_PQ_M; | ||
|
||
/** | ||
* Request to train and serialize a model | ||
*/ | ||
|
@@ -283,6 +285,15 @@ public ActionRequestValidationException validate() { | |
exception.addValidationError("Description exceeds limit of " + KNNConstants.MAX_MODEL_DESCRIPTION_LENGTH + " characters"); | ||
} | ||
|
||
// Check if ENCODER_PARAMETER_PQ_M is divisible by vector dimension | ||
if (knnMethodContext.getMethodComponentContext().getParameters().containsKey(ENCODER_PARAMETER_PQ_M) | ||
&& knnMethodConfigContext.getDimension() % (Integer) knnMethodContext.getMethodComponentContext() | ||
.getParameters() | ||
.get(ENCODER_PARAMETER_PQ_M) != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if that parameter is always present or not, but if it's optional then this line can generate the runtime exception in case parameter is not present |
||
exception = exception == null ? new ActionRequestValidationException() : exception; | ||
exception.addValidationError("Training request ENCODER_PARAMETER_PQ_M is not divisible by vector dimensions"); | ||
} | ||
|
||
// Validate training index exists | ||
IndexMetadata indexMetadata = clusterService.state().metadata().index(trainingIndex); | ||
if (indexMetadata == null) { | ||
|
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.
can you make the 1000 value a class level constant?