in src/main/java/org/opensearch/knn/index/KNNVectorFieldMapper.java [203:266]
public KNNVectorFieldMapper build(BuilderContext context) {
// Originally, a user would use index settings to set the spaceType, efConstruction and m hnsw
// parameters. Upon further review, it makes sense to set these parameters in the mapping of a
// particular field. However, because users migrating from older versions will still use the index
// settings to set these parameters, we will need to provide backwards compatibilty. In order to
// handle this, we first check if the mapping is set, and, if so use it. If not, we check if the model is
// set. If not, we fall back to the parameters set in the index settings. This means that if a user sets
// the mappings, setting the index settings will have no impact.
KNNMethodContext knnMethodContext = this.knnMethodContext.getValue();
if (knnMethodContext != null) {
return new MethodFieldMapper(name,
new KNNVectorFieldType(buildFullName(context), meta.getValue(), dimension.getValue()),
multiFieldsBuilder.build(this, context),
copyTo.build(),
ignoreMalformed(context),
stored.get(),
hasDocValues.get(),
knnMethodContext);
}
String modelIdAsString = this.modelId.get();
if (modelIdAsString != null) {
// Because model information is stored in cluster metadata, we are unable to get it here. This is
// because to get the cluster metadata, you need access to the cluster state. Because this code is
// sometimes used to initialize the cluster state/update cluster state, we cannot get the state here
// safely. So, we are unable to validate the model. The model gets validated during ingestion.
return new ModelFieldMapper(
name,
new KNNVectorFieldType(buildFullName(context), meta.getValue(), -1, modelIdAsString),
multiFieldsBuilder.build(this, context),
copyTo.build(),
ignoreMalformed(context),
stored.get(),
hasDocValues.get(),
modelDao,
modelIdAsString);
}
// Build legacy
if (this.spaceType == null) {
this.spaceType = LegacyFieldMapper.getSpaceType(context.indexSettings());
}
if (this.m == null) {
this.m = LegacyFieldMapper.getM(context.indexSettings());
}
if (this.efConstruction == null) {
this.efConstruction = LegacyFieldMapper.getEfConstruction(context.indexSettings());
}
return new LegacyFieldMapper(name,
new KNNVectorFieldType(buildFullName(context), meta.getValue(), dimension.getValue()),
multiFieldsBuilder.build(this, context),
copyTo.build(),
ignoreMalformed(context),
stored.get(),
hasDocValues.get(),
spaceType,
m,
efConstruction);
}