in src/main/java/org/opensearch/knn/index/MethodComponent.java [125:161]
public boolean isTrainingRequired(MethodComponentContext methodComponentContext) {
if (requiresTraining) {
return true;
}
// Check if any of the parameters the user provided require training. For example, PQ as an encoder.
// If so, return true as well
Map<String, Object> providedParameters = methodComponentContext.getParameters();
if (providedParameters == null || providedParameters.isEmpty()) {
return false;
}
for (Map.Entry<String, Object> providedParameter : providedParameters.entrySet()) {
// MethodComponentContextParameters are parameters that are MethodComponentContexts.
// MethodComponent may or may not require training. So, we have to check if the parameter requires training.
// If the parameter does not exist, the parameter estimate will be skipped. It is not this function's job
// to validate the parameters.
Parameter<?> parameter = parameters.get(providedParameter.getKey());
if (!(parameter instanceof Parameter.MethodComponentContextParameter)) {
continue;
}
Parameter.MethodComponentContextParameter methodParameter = (Parameter.MethodComponentContextParameter) parameter;
Object providedValue = providedParameter.getValue();
if (!(providedValue instanceof MethodComponentContext)) {
continue;
}
MethodComponentContext parameterMethodComponentContext = (MethodComponentContext) providedValue;
MethodComponent methodComponent = methodParameter.getMethodComponent(parameterMethodComponentContext.getName());
if (methodComponent.isTrainingRequired(parameterMethodComponentContext)) {
return true;
}
}
return false;
}