Skip to content

Commit 279d4c2

Browse files
committed
Fix some tests
1 parent 7a5a29a commit 279d4c2

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,19 +1187,25 @@ static DenseVectorFieldMapper.DenseVectorIndexOptions defaultDenseVectorIndexOpt
11871187
IndexVersion indexVersionCreated,
11881188
MinimalServiceSettings modelSettings
11891189
) {
1190+
1191+
if (modelSettings.dimensions() == null) {
1192+
return null; // Cannot determine default index options without dimensions
1193+
}
1194+
11901195
DenseVectorFieldMapper.DenseVectorIndexOptions defaultIndexOptions = null;
11911196

11921197
// As embedding models for text perform better with BBQ, we aggressively default semantic_text fields to use optimized index
11931198
// options
11941199
if (indexVersionCreated.onOrAfter(SEMANTIC_TEXT_DEFAULTS_TO_BBQ)
11951200
|| indexVersionCreated.between(SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0)) {
1201+
11961202
DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswIndexOptions = defaultBbqHnswDenseVectorIndexOptions();
11971203
defaultIndexOptions = defaultBbqHnswIndexOptions.validate(modelSettings.elementType(), modelSettings.dimensions(), false)
11981204
? defaultBbqHnswIndexOptions
11991205
: null;
12001206
}
12011207

1202-
// Older indices or those incompatible with BBQ will continue to use legacy defaults
1208+
// Older indices or those incompatible with BBQ will continue to use legacy defaults, we specify them to ensure they are serialized
12031209
if (defaultIndexOptions == null) {
12041210
defaultIndexOptions = legacyDefaultDenseVectorIndexOptions();
12051211
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public void testInvalidTaskTypes() {
399399
useLegacyFormat
400400
)
401401
);
402-
assertThat(e.getMessage(), containsString("Failed to parse mapping: Wrong [task_type]"));
402+
assertThat(e.getMessage(), containsString("Invalid task_type in model_settings"));
403403
}
404404
}
405405

@@ -1133,7 +1133,7 @@ private MapperService mapperServiceForFieldWithModelSettings(
11331133
inferenceId,
11341134
modelSettings,
11351135
generateRandomChunkingSettings(),
1136-
randomSemanticTextIndexOptions(TaskType.TEXT_EMBEDDING),
1136+
modelSettings.taskType() == TaskType.TEXT_EMBEDDING ? randomSemanticTextIndexOptions(TaskType.TEXT_EMBEDDING) : null,
11371137
Map.of()
11381138
),
11391139
XContentType.JSON

0 commit comments

Comments
 (0)