Skip to content

Commit bae2d14

Browse files
committed
Added default BBQ index options test
1 parent 1b15536 commit bae2d14

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

x-pack/plugin/inference/src/internalClusterTest/java/org/elasticsearch/xpack/inference/integration/SemanticTextIndexOptionsIT.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,40 @@ public void testValidateIndexOptionsWithBasicLicense() throws Exception {
123123
safeGet(prepareCreate(INDEX_NAME).setMapping(generateMapping(inferenceFieldName, inferenceId, indexOptions)).execute())
124124
);
125125

126-
final Map<String, Object> expectedFieldMapping = generateExpectedFieldMapping(inferenceId, inferenceFieldName, indexOptions);
126+
final Map<String, Object> expectedFieldMapping = generateExpectedFieldMapping(inferenceFieldName, inferenceId, indexOptions);
127127
var getFieldMappingsResponse = safeGet(
128128
client().execute(GetFieldMappingsAction.INSTANCE, new GetFieldMappingsRequest().indices(INDEX_NAME).fields(inferenceFieldName))
129129
);
130130
assertThat(getFieldMappingsResponse.fieldMappings(INDEX_NAME, inferenceFieldName).sourceAsMap(), equalTo(expectedFieldMapping));
131131
}
132132

133+
public void testSetDefaultBBQIndexOptionsWithBasicLicense() throws Exception {
134+
final String inferenceId = "test-inference-id-2";
135+
final String inferenceFieldName = "inference_field";
136+
createInferenceEndpoint(TaskType.TEXT_EMBEDDING, inferenceId, BBQ_COMPATIBLE_SERVICE_SETTINGS);
137+
138+
setLicense("basic");
139+
assertAcked(safeGet(prepareCreate(INDEX_NAME).setMapping(generateMapping(inferenceFieldName, inferenceId, null)).execute()));
140+
141+
final Map<String, Object> expectedFieldMapping = generateExpectedFieldMapping(
142+
inferenceFieldName,
143+
inferenceId,
144+
SemanticTextFieldMapper.defaultBbqHnswDenseVectorIndexOptions()
145+
);
146+
var getFieldMappingsResponse = safeGet(
147+
client().execute(
148+
GetFieldMappingsAction.INSTANCE,
149+
new GetFieldMappingsRequest().indices(INDEX_NAME).fields(inferenceFieldName).includeDefaults(true)
150+
)
151+
);
152+
153+
// Filter out null/empty values from params we didn't set to make comparison easier
154+
Map<String, Object> actualFieldMappings = filterNullOrEmptyValues(
155+
getFieldMappingsResponse.fieldMappings(INDEX_NAME, inferenceFieldName).sourceAsMap()
156+
);
157+
assertThat(actualFieldMappings, equalTo(expectedFieldMapping));
158+
}
159+
133160
private void createInferenceEndpoint(TaskType taskType, String inferenceId, Map<String, Object> serviceSettings) throws IOException {
134161
final String service = switch (taskType) {
135162
case TEXT_EMBEDDING -> TestDenseInferenceServiceExtension.TestInferenceService.NAME;
@@ -207,6 +234,27 @@ private static Map<String, Object> generateExpectedFieldMapping(
207234
return expectedFieldMapping;
208235
}
209236

237+
@SuppressWarnings("unchecked")
238+
private static Map<String, Object> filterNullOrEmptyValues(Map<String, Object> map) {
239+
Map<String, Object> filteredMap = new HashMap<>();
240+
for (var entry : map.entrySet()) {
241+
Object value = entry.getValue();
242+
if (entry.getValue() instanceof Map<?, ?> mapValue) {
243+
if (mapValue.isEmpty()) {
244+
continue;
245+
}
246+
247+
value = filterNullOrEmptyValues((Map<String, Object>) mapValue);
248+
}
249+
250+
if (value != null) {
251+
filteredMap.put(entry.getKey(), value);
252+
}
253+
}
254+
255+
return filteredMap;
256+
}
257+
210258
private static void setLicense(String type) throws Exception {
211259
if (type.equals("basic")) {
212260
assertAcked(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ static boolean indexVersionDefaultsToBbqHnsw(IndexVersion indexVersion) {
12501250
|| indexVersion.between(SEMANTIC_TEXT_DEFAULTS_TO_BBQ_BACKPORT_8_X, IndexVersions.UPGRADE_TO_LUCENE_10_0_0);
12511251
}
12521252

1253-
static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDenseVectorIndexOptions() {
1253+
public static DenseVectorFieldMapper.DenseVectorIndexOptions defaultBbqHnswDenseVectorIndexOptions() {
12541254
int m = Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN;
12551255
int efConstruction = Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
12561256
DenseVectorFieldMapper.RescoreVector rescoreVector = new DenseVectorFieldMapper.RescoreVector(DEFAULT_RESCORE_OVERSAMPLE);

0 commit comments

Comments
 (0)