Skip to content

Commit 40ed2fd

Browse files
committed
Fix yaml tests
1 parent e9bfdc8 commit 40ed2fd

File tree

3 files changed

+215
-63
lines changed

3 files changed

+215
-63
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ protected void assertEqualInstances(SemanticTextField expectedInstance, Semantic
118118
@Override
119119
protected SemanticTextField createTestInstance() {
120120
List<String> rawValues = randomList(1, 5, () -> randomSemanticTextInput().toString());
121-
TestModel testModel = TestModel.createRandomInstance();
122121
try { // try catch required for override
123122
return randomSemanticText(
124123
useLegacyFormat,
125124
NAME,
126-
testModel,
125+
TestModel.createRandomInstance(),
127126
generateRandomChunkingSettings(),
128127
rawValues,
129128
randomFrom(XContentType.values())

x-pack/plugin/inference/src/yamlRestTest/resources/rest-api-spec/test/inference/10_semantic_text_field_mapping.yml

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ setup:
3535
}
3636
}
3737
38+
- do:
39+
inference.put:
40+
task_type: text_embedding
41+
inference_id: dense-inference-id-compatible-with-bbq
42+
body: >
43+
{
44+
"service": "text_embedding_test_service",
45+
"service_settings": {
46+
"model": "my_model",
47+
"dimensions": 64,
48+
"similarity": "cosine",
49+
"api_key": "abc64"
50+
},
51+
"task_settings": {
52+
}
53+
}
54+
3855
3956
- do:
4057
indices.create:
@@ -233,7 +250,7 @@ setup:
233250

234251
- do:
235252
indices.create:
236-
index: test-index-options
253+
index: test-index-options-with-bbq
237254
body:
238255
settings:
239256
index:
@@ -244,24 +261,72 @@ setup:
244261
properties:
245262
dense_field:
246263
type: semantic_text
247-
inference_id: dense-inference-id
264+
inference_id: dense-inference-id-compatible-with-bbq
248265

249266
# Checks vector mapping is not updated until first doc arrives
250267
- do:
251268
indices.get_mapping:
252-
index: test-index-options
269+
index: test-index-options-with-bbq
253270

254-
- match: { "test-index-options.mappings.properties.dense_field.type": semantic_text }
255-
- match: { "test-index-options.mappings.properties.dense_field.inference_id": dense-inference-id }
256-
- match: { "test-index-options.mappings.properties.dense_field.index_options.dense_vector.type": bbq_hnsw }
257-
- match: { "test-index-options.mappings.properties.dense_field.index_options.dense_vector.m": 16 }
258-
- match: { "test-index-options.mappings.properties.dense_field.index_options.dense_vector.ef_construction": 100 }
259-
- match: { "test-index-options.mappings.properties.dense_field.index_options.dense_vector.rescore_vector.oversample": 3 }
260-
- not_exists: test-index-options.mappings.properties.dense_field.model_settings
271+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.type": semantic_text }
272+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.inference_id": dense-inference-id-compatible-with-bbq }
273+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.index_options.dense_vector.type": bbq_hnsw }
274+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.index_options.dense_vector.m": 16 }
275+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.index_options.dense_vector.ef_construction": 100 }
276+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.index_options.dense_vector.rescore_vector.oversample": 3 }
277+
- not_exists: test-index-options-with-bbq.mappings.properties.dense_field.model_settings
261278

262279
- do:
263280
index:
264-
index: test-index-options
281+
index: test-index-options-with-bbq
282+
id: doc_2
283+
body:
284+
dense_field: "these are not the droids you're looking for. He's free to go around"
285+
_inference_fields.dense_field:
286+
inference:
287+
inference_id: dense-inference-id-compatible-with-bbq
288+
model_settings:
289+
task_type: text_embedding
290+
dimensions: 64
291+
similarity: cosine
292+
element_type: float
293+
chunks:
294+
dense_field:
295+
- start_offset: 0
296+
end_offset: 44
297+
embeddings: [ 0.05, -0.03, -0.03, 0.06, 0.01, -0.02, 0.07, 0.02, -0.04, 0.03, 0.00, 0.05, -0.06, 0.04, -0.01, 0.02, -0.05, 0.01, 0.03, -0.02, 0.06, -0.04, 0.00, 0.05, -0.03, 0.02, 0.01, -0.01, 0.04, -0.06, 0.03, 0.02, -0.02, 0.06, -0.01, 0.00, 0.04, -0.05, 0.01, 0.03, -0.04, 0.02, -0.03, 0.05, -0.02, 0.01, 0.03, -0.06, 0.04, 0.00, -0.01, 0.06, -0.03, 0.02, 0.01, -0.04, 0.05, -0.01, 0.00, 0.04, -0.05, 0.02, 0.03, -0.02 ]
298+
- start_offset: 44
299+
end_offset: 67
300+
embeddings: [ 0.05, -0.03, -0.03, 0.06, 0.01, -0.02, 0.07, 0.02, -0.04, 0.03, 0.00, 0.05, -0.06, 0.04, -0.01, 0.02, -0.05, 0.01, 0.03, -0.02, 0.06, -0.04, 0.00, 0.05, -0.03, 0.02, 0.01, -0.01, 0.04, -0.06, 0.03, 0.02, -0.02, 0.06, -0.01, 0.00, 0.04, -0.05, 0.01, 0.03, -0.04, 0.02, -0.03, 0.05, -0.02, 0.01, 0.03, -0.06, 0.04, 0.00, -0.01, 0.06, -0.03, 0.02, 0.01, -0.04, 0.05, -0.01, 0.00, 0.04, -0.05, 0.02, 0.03, -0.02 ]
301+
302+
303+
# Checks mapping is updated when first doc arrives
304+
- do:
305+
indices.get_mapping:
306+
index: test-index-options-with-bbq
307+
308+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.type": semantic_text }
309+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.inference_id": dense-inference-id-compatible-with-bbq }
310+
- match: { "test-index-options-with-bbq.mappings.properties.dense_field.model_settings.task_type": text_embedding }
311+
- exists: test-index-options-with-bbq.mappings.properties.dense_field.model_settings
312+
313+
---
314+
"Indexes dense vector document with index_options falls back to int8_hnsw for non-compatible models":
315+
# Checks mapping is not updated until first doc arrives
316+
- do:
317+
indices.get_mapping:
318+
index: test-index
319+
320+
- match: { "test-index.mappings.properties.dense_field.type": semantic_text }
321+
- match: { "test-index.mappings.properties.dense_field.inference_id": dense-inference-id }
322+
- match: { "test-index.mappings.properties.dense_field.index_options.dense_vector.type": int8_hnsw }
323+
- match: { "test-index.mappings.properties.dense_field.index_options.dense_vector.m": 16 }
324+
- match: { "test-index.mappings.properties.dense_field.index_options.dense_vector.ef_construction": 100 }
325+
- not_exists: test-index.mappings.properties.dense_field.model_settings
326+
327+
- do:
328+
index:
329+
index: test-index
265330
id: doc_2
266331
body:
267332
dense_field: "these are not the droids you're looking for. He's free to go around"
@@ -285,12 +350,15 @@ setup:
285350
# Checks mapping is updated when first doc arrives
286351
- do:
287352
indices.get_mapping:
288-
index: test-index-options
353+
index: test-index
289354

290-
- match: { "test-index-options.mappings.properties.dense_field.type": semantic_text }
291-
- match: { "test-index-options.mappings.properties.dense_field.inference_id": dense-inference-id }
292-
- match: { "test-index-options.mappings.properties.dense_field.model_settings.task_type": text_embedding }
293-
- exists: test-index-options.mappings.properties.dense_field.model_settings
355+
- match: { "test-index.mappings.properties.dense_field.type": semantic_text }
356+
- match: { "test-index.mappings.properties.dense_field.inference_id": dense-inference-id }
357+
- match: { "test-index.mappings.properties.dense_field.index_options.dense_vector.type": int8_hnsw }
358+
- match: { "test-index.mappings.properties.dense_field.index_options.dense_vector.m": 16 }
359+
- match: { "test-index.mappings.properties.dense_field.index_options.dense_vector.ef_construction": 100 }
360+
- exists: test-index.mappings.properties.dense_field.model_settings
361+
- match: { "test-index.mappings.properties.dense_field.model_settings.task_type": text_embedding }
294362

295363
---
296364
"Field caps with text embedding":
@@ -536,7 +604,7 @@ setup:
536604

537605
- do:
538606
indices.create:
539-
index: test-index-options
607+
index: test-index-options-with-bbq
540608
body:
541609
settings:
542610
index:
@@ -547,16 +615,16 @@ setup:
547615
properties:
548616
semantic_field:
549617
type: semantic_text
550-
inference_id: dense-inference-id
618+
inference_id: dense-inference-id-compatible-with-bbq
551619

552620
- do:
553621
indices.get_mapping:
554-
index: test-index-options
622+
index: test-index-options-with-bbq
555623

556-
- match: { "test-index-options.mappings.properties.semantic_field.index_options.dense_vector.type": bbq_hnsw }
557-
- match: { "test-index-options.mappings.properties.semantic_field.index_options.dense_vector.m": 16 }
558-
- match: { "test-index-options.mappings.properties.semantic_field.index_options.dense_vector.ef_construction": 100 }
559-
- match: { "test-index-options.mappings.properties.semantic_field.index_options.dense_vector.rescore_vector.oversample": 3 }
624+
- match: { "test-index-options-with-bbq.mappings.properties.semantic_field.index_options.dense_vector.type": bbq_hnsw }
625+
- match: { "test-index-options-with-bbq.mappings.properties.semantic_field.index_options.dense_vector.m": 16 }
626+
- match: { "test-index-options-with-bbq.mappings.properties.semantic_field.index_options.dense_vector.ef_construction": 100 }
627+
- match: { "test-index-options-with-bbq.mappings.properties.semantic_field.index_options.dense_vector.rescore_vector.oversample": 3 }
560628

561629

562630

0 commit comments

Comments
 (0)