|
11 | 11 | import org.elasticsearch.ElasticsearchStatusException; |
12 | 12 | import org.elasticsearch.action.ActionListener; |
13 | 13 | import org.elasticsearch.action.support.PlainActionFuture; |
| 14 | +import org.elasticsearch.action.support.TestPlainActionFuture; |
14 | 15 | import org.elasticsearch.common.ValidationException; |
15 | 16 | import org.elasticsearch.common.bytes.BytesArray; |
16 | 17 | import org.elasticsearch.common.bytes.BytesReference; |
|
48 | 49 | import org.elasticsearch.xpack.core.inference.results.UnifiedChatCompletionException; |
49 | 50 | import org.elasticsearch.xpack.inference.InferencePlugin; |
50 | 51 | import org.elasticsearch.xpack.inference.LocalStateInferencePlugin; |
| 52 | +import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; |
51 | 53 | import org.elasticsearch.xpack.inference.external.http.HttpClientManager; |
52 | 54 | import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSender; |
53 | 55 | import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSenderTests; |
|
61 | 63 | import org.elasticsearch.xpack.inference.services.elastic.authorization.ElasticInferenceServiceAuthorizationRequestHandler; |
62 | 64 | import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionModel; |
63 | 65 | import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionServiceSettings; |
| 66 | +import org.elasticsearch.xpack.inference.services.elastic.densetextembeddings.ElasticInferenceServiceDenseTextEmbeddingsModel; |
64 | 67 | import org.elasticsearch.xpack.inference.services.elastic.densetextembeddings.ElasticInferenceServiceDenseTextEmbeddingsModelTests; |
| 68 | +import org.elasticsearch.xpack.inference.services.elastic.densetextembeddings.ElasticInferenceServiceDenseTextEmbeddingsServiceSettings; |
65 | 69 | import org.elasticsearch.xpack.inference.services.elastic.rerank.ElasticInferenceServiceRerankModel; |
66 | 70 | import org.elasticsearch.xpack.inference.services.elastic.rerank.ElasticInferenceServiceRerankModelTests; |
| 71 | +import org.elasticsearch.xpack.inference.services.elastic.rerank.ElasticInferenceServiceRerankServiceSettings; |
67 | 72 | import org.elasticsearch.xpack.inference.services.elastic.response.ElasticInferenceServiceAuthorizationResponseEntity; |
68 | 73 | import org.elasticsearch.xpack.inference.services.elasticsearch.ElserModels; |
69 | 74 | import org.elasticsearch.xpack.inference.services.settings.RateLimitSettings; |
|
93 | 98 | import static org.elasticsearch.xpack.inference.external.http.Utils.entityAsMap; |
94 | 99 | import static org.elasticsearch.xpack.inference.external.http.Utils.getUrl; |
95 | 100 | import static org.elasticsearch.xpack.inference.services.ServiceComponentsTests.createWithEmptySettings; |
| 101 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_CHAT_COMPLETION_ENDPOINT_ID_V1; |
| 102 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_CHAT_COMPLETION_MODEL_ID_V1; |
| 103 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_ELSER_ENDPOINT_ID_V2; |
| 104 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_ELSER_MODEL_ID_V2; |
| 105 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_MULTILINGUAL_EMBED_ENDPOINT_ID; |
| 106 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_MULTILINGUAL_EMBED_MODEL_ID; |
| 107 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_RERANK_ENDPOINT_ID_V1; |
| 108 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_RERANK_MODEL_ID_V1; |
| 109 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DENSE_TEXT_EMBEDDINGS_DIMENSIONS; |
| 110 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.defaultDenseTextEmbeddingsSimilarity; |
96 | 111 | import static org.hamcrest.CoreMatchers.instanceOf; |
97 | 112 | import static org.hamcrest.CoreMatchers.is; |
| 113 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
98 | 114 | import static org.hamcrest.Matchers.empty; |
99 | 115 | import static org.hamcrest.Matchers.equalTo; |
100 | 116 | import static org.hamcrest.Matchers.hasSize; |
@@ -1312,8 +1328,8 @@ public void testDefaultConfigs_Returns_DefaultEndpoints_WhenTaskTypeIsCorrect() |
1312 | 1328 | ".multilingual-embed-v1-elastic", |
1313 | 1329 | MinimalServiceSettings.textEmbedding( |
1314 | 1330 | ElasticInferenceService.NAME, |
1315 | | - ElasticInferenceService.DENSE_TEXT_EMBEDDINGS_DIMENSIONS, |
1316 | | - ElasticInferenceService.defaultDenseTextEmbeddingsSimilarity(), |
| 1331 | + DENSE_TEXT_EMBEDDINGS_DIMENSIONS, |
| 1332 | + defaultDenseTextEmbeddingsSimilarity(), |
1317 | 1333 | DenseVectorFieldMapper.ElementType.FLOAT |
1318 | 1334 | ), |
1319 | 1335 | service |
@@ -1348,6 +1364,94 @@ public void testDefaultConfigs_Returns_DefaultEndpoints_WhenTaskTypeIsCorrect() |
1348 | 1364 | } |
1349 | 1365 | } |
1350 | 1366 |
|
| 1367 | + public void testDefaultConfigs_Returns_DefaultEndpointsModels() throws Exception { |
| 1368 | + String responseJson = """ |
| 1369 | + { |
| 1370 | + "models": [ |
| 1371 | + { |
| 1372 | + "model_name": "rainbow-sprinkles", |
| 1373 | + "task_types": ["chat"] |
| 1374 | + }, |
| 1375 | + { |
| 1376 | + "model_name": "elser_model_2", |
| 1377 | + "task_types": ["embed/text/sparse"] |
| 1378 | + }, |
| 1379 | + { |
| 1380 | + "model_name": "jina-embeddings-v3", |
| 1381 | + "task_types": ["embed/text/dense"] |
| 1382 | + }, |
| 1383 | + { |
| 1384 | + "model_name": "elastic-rerank-v1", |
| 1385 | + "task_types": ["rerank/text/text-similarity"] |
| 1386 | + } |
| 1387 | + ] |
| 1388 | + } |
| 1389 | + """; |
| 1390 | + |
| 1391 | + webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson)); |
| 1392 | + |
| 1393 | + var senderFactory = HttpRequestSenderTests.createSenderFactory(threadPool, clientManager); |
| 1394 | + try (var service = createServiceWithAuthHandler(senderFactory, getUrl(webServer))) { |
| 1395 | + ensureAuthorizationCallFinished(service); |
| 1396 | + var listener = new TestPlainActionFuture<List<Model>>(); |
| 1397 | + |
| 1398 | + service.defaultConfigs(listener); |
| 1399 | + var models = listener.actionGet(TIMEOUT); |
| 1400 | + |
| 1401 | + var elasticInferenceServiceComponents = new ElasticInferenceServiceComponents(getUrl(webServer)); |
| 1402 | + |
| 1403 | + assertThat( |
| 1404 | + models, |
| 1405 | + containsInAnyOrder( |
| 1406 | + new ElasticInferenceServiceCompletionModel( |
| 1407 | + DEFAULT_CHAT_COMPLETION_ENDPOINT_ID_V1, |
| 1408 | + TaskType.CHAT_COMPLETION, |
| 1409 | + ElasticInferenceService.NAME, |
| 1410 | + new ElasticInferenceServiceCompletionServiceSettings(DEFAULT_CHAT_COMPLETION_MODEL_ID_V1, null), |
| 1411 | + EmptyTaskSettings.INSTANCE, |
| 1412 | + EmptySecretSettings.INSTANCE, |
| 1413 | + elasticInferenceServiceComponents |
| 1414 | + ), |
| 1415 | + new ElasticInferenceServiceSparseEmbeddingsModel( |
| 1416 | + DEFAULT_ELSER_ENDPOINT_ID_V2, |
| 1417 | + TaskType.SPARSE_EMBEDDING, |
| 1418 | + ElasticInferenceService.NAME, |
| 1419 | + new ElasticInferenceServiceSparseEmbeddingsServiceSettings(DEFAULT_ELSER_MODEL_ID_V2, null, null), |
| 1420 | + EmptyTaskSettings.INSTANCE, |
| 1421 | + EmptySecretSettings.INSTANCE, |
| 1422 | + elasticInferenceServiceComponents, |
| 1423 | + ChunkingSettingsBuilder.DEFAULT_SETTINGS |
| 1424 | + ), |
| 1425 | + new ElasticInferenceServiceDenseTextEmbeddingsModel( |
| 1426 | + DEFAULT_MULTILINGUAL_EMBED_ENDPOINT_ID, |
| 1427 | + TaskType.TEXT_EMBEDDING, |
| 1428 | + ElasticInferenceService.NAME, |
| 1429 | + new ElasticInferenceServiceDenseTextEmbeddingsServiceSettings( |
| 1430 | + DEFAULT_MULTILINGUAL_EMBED_MODEL_ID, |
| 1431 | + defaultDenseTextEmbeddingsSimilarity(), |
| 1432 | + DENSE_TEXT_EMBEDDINGS_DIMENSIONS, |
| 1433 | + null, |
| 1434 | + null |
| 1435 | + ), |
| 1436 | + EmptyTaskSettings.INSTANCE, |
| 1437 | + EmptySecretSettings.INSTANCE, |
| 1438 | + elasticInferenceServiceComponents, |
| 1439 | + ChunkingSettingsBuilder.DEFAULT_SETTINGS |
| 1440 | + ), |
| 1441 | + new ElasticInferenceServiceRerankModel( |
| 1442 | + DEFAULT_RERANK_ENDPOINT_ID_V1, |
| 1443 | + TaskType.RERANK, |
| 1444 | + ElasticInferenceService.NAME, |
| 1445 | + new ElasticInferenceServiceRerankServiceSettings(DEFAULT_RERANK_MODEL_ID_V1, null), |
| 1446 | + EmptyTaskSettings.INSTANCE, |
| 1447 | + EmptySecretSettings.INSTANCE, |
| 1448 | + elasticInferenceServiceComponents |
| 1449 | + ) |
| 1450 | + ) |
| 1451 | + ); |
| 1452 | + } |
| 1453 | + } |
| 1454 | + |
1351 | 1455 | public void testUnifiedCompletionError() { |
1352 | 1456 | var e = assertThrows(UnifiedChatCompletionException.class, () -> testUnifiedStream(404, """ |
1353 | 1457 | { |
|
0 commit comments