Skip to content

Commit

Permalink
Fixed a bug that does not get a space type from index setting when it…
Browse files Browse the repository at this point in the history
… is empty for compatibility.

 Signed-off-by: Dooyong Kim <[email protected]>
  • Loading branch information
Dooyong Kim committed Dec 3, 2024
1 parent 00328ec commit 36ed563
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SpaceType resolveSpaceType(
SpaceType topLevelSpaceType = getSpaceTypeFromString(topLevelSpaceTypeString);

if (isSpaceTypeConfigured(methodSpaceType) == false && isSpaceTypeConfigured(topLevelSpaceType) == false) {
return getSpaceTypeFromVectorDataType(vectorDataType);
return SpaceType.UNDEFINED;
}

if (isSpaceTypeConfigured(methodSpaceType) == false) {
Expand Down Expand Up @@ -75,13 +75,6 @@ private SpaceType getSpaceTypeFromMethodContext(final KNNMethodContext knnMethod
return knnMethodContext.getSpaceType();
}

private SpaceType getSpaceTypeFromVectorDataType(final VectorDataType vectorDataType) {
if (vectorDataType == VectorDataType.BINARY) {
return SpaceType.DEFAULT_BINARY;
}
return SpaceType.DEFAULT;
}

private SpaceType getSpaceTypeFromString(final String spaceType) {
if (Strings.isEmpty(spaceType)) {
return SpaceType.UNDEFINED;
Expand All @@ -93,4 +86,15 @@ private SpaceType getSpaceTypeFromString(final String spaceType) {
private boolean isSpaceTypeConfigured(final SpaceType spaceType) {
return spaceType != null && spaceType != SpaceType.UNDEFINED;
}

public SpaceType pickDefaultSpaceTypeWhenEmpty(SpaceType resolvedSpaceType, VectorDataType vectorDataType) {
if (resolvedSpaceType != SpaceType.UNDEFINED) {
return resolvedSpaceType;
} else {
if (vectorDataType == VectorDataType.BINARY) {
return SpaceType.DEFAULT_BINARY;
}
return SpaceType.DEFAULT;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,15 @@ public Mapper.Builder<?> parse(String name, Map<String, Object> node, ParserCont
// If the original knnMethodContext is not null, resolve its space type and engine from the rest of the
// configuration. This is consistent with the existing behavior for space type in 2.16 where we modify the
// parsed value
SpaceType resolvedSpaceType = SpaceTypeResolver.INSTANCE.resolveSpaceType(
final SpaceType resolvedSpaceType = SpaceTypeResolver.INSTANCE.resolveSpaceType(
builder.originalParameters.getKnnMethodContext(),
builder.vectorDataType.get(),
builder.topLevelSpaceType.get()
);
setSpaceType(builder.originalParameters.getKnnMethodContext(), resolvedSpaceType);
setSpaceType(
builder.originalParameters.getKnnMethodContext(),
SpaceTypeResolver.INSTANCE.pickDefaultSpaceTypeWhenEmpty(resolvedSpaceType, builder.vectorDataType.get())
);
validateSpaceType(builder);
resolveKNNMethodComponents(builder, parserContext, resolvedSpaceType);
validateFromKNNMethod(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ static KNNMethodContext createKNNMethodContextFromLegacy(
SpaceType topLevelSpaceType
) {
// If top level spaceType is set then use that spaceType otherwise default to spaceType from index-settings
final SpaceType finalSpaceToSet = topLevelSpaceType != SpaceType.UNDEFINED
? topLevelSpaceType
: KNNVectorFieldMapperUtil.getSpaceType(indexSettings);
final SpaceType finalSpaceToSet = topLevelSpaceType != SpaceType.UNDEFINED ? topLevelSpaceType : getSpaceType(indexSettings);
return new KNNMethodContext(
KNNEngine.NMSLIB,
finalSpaceToSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private TrainingModelRequest createTransportRequest(RestRequest restRequest) thr
vectorDataType,
topLevelSpaceType.getValue()
);
resolvedSpaceType = SpaceTypeResolver.INSTANCE.pickDefaultSpaceTypeWhenEmpty(resolvedSpaceType, vectorDataType);
setSpaceType(knnMethodContext, resolvedSpaceType);
TrainingModelRequest trainingModelRequest = new TrainingModelRequest(
modelId,
Expand Down

0 comments on commit 36ed563

Please sign in to comment.