|
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; |
|
45 | 46 | import org.elasticsearch.xpack.core.inference.results.UnifiedChatCompletionException; |
46 | 47 | import org.elasticsearch.xpack.inference.InferencePlugin; |
47 | 48 | import org.elasticsearch.xpack.inference.LocalStateInferencePlugin; |
| 49 | +import org.elasticsearch.xpack.inference.chunking.ChunkingSettingsBuilder; |
48 | 50 | import org.elasticsearch.xpack.inference.external.http.HttpClientManager; |
49 | 51 | import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSender; |
50 | 52 | import org.elasticsearch.xpack.inference.external.http.sender.HttpRequestSenderTests; |
|
57 | 59 | import org.elasticsearch.xpack.inference.services.elastic.authorization.ElasticInferenceServiceAuthorizationRequestHandler; |
58 | 60 | import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionModel; |
59 | 61 | import org.elasticsearch.xpack.inference.services.elastic.completion.ElasticInferenceServiceCompletionServiceSettings; |
| 62 | +import org.elasticsearch.xpack.inference.services.elastic.densetextembeddings.ElasticInferenceServiceDenseTextEmbeddingsModel; |
60 | 63 | import org.elasticsearch.xpack.inference.services.elastic.densetextembeddings.ElasticInferenceServiceDenseTextEmbeddingsModelTests; |
| 64 | +import org.elasticsearch.xpack.inference.services.elastic.densetextembeddings.ElasticInferenceServiceDenseTextEmbeddingsServiceSettings; |
61 | 65 | import org.elasticsearch.xpack.inference.services.elastic.rerank.ElasticInferenceServiceRerankModel; |
62 | 66 | import org.elasticsearch.xpack.inference.services.elastic.rerank.ElasticInferenceServiceRerankModelTests; |
| 67 | +import org.elasticsearch.xpack.inference.services.elastic.rerank.ElasticInferenceServiceRerankServiceSettings; |
63 | 68 | import org.elasticsearch.xpack.inference.services.elastic.response.ElasticInferenceServiceAuthorizationResponseEntity; |
64 | 69 | import org.elasticsearch.xpack.inference.services.elastic.sparseembeddings.ElasticInferenceServiceSparseEmbeddingsModel; |
| 70 | +import org.elasticsearch.xpack.inference.services.elastic.sparseembeddings.ElasticInferenceServiceSparseEmbeddingsServiceSettings; |
65 | 71 | import org.elasticsearch.xpack.inference.services.elasticsearch.ElserModels; |
66 | 72 | import org.elasticsearch.xpack.inference.services.settings.RateLimitSettings; |
67 | 73 | import org.hamcrest.MatcherAssert; |
|
91 | 97 | import static org.elasticsearch.xpack.inference.external.http.Utils.getUrl; |
92 | 98 | import static org.elasticsearch.xpack.inference.services.SenderServiceTests.createMockSender; |
93 | 99 | import static org.elasticsearch.xpack.inference.services.ServiceComponentsTests.createWithEmptySettings; |
| 100 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_CHAT_COMPLETION_ENDPOINT_ID_V1; |
| 101 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_CHAT_COMPLETION_MODEL_ID_V1; |
| 102 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_ELSER_2_MODEL_ID; |
| 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_MULTILINGUAL_EMBED_ENDPOINT_ID; |
| 105 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_MULTILINGUAL_EMBED_MODEL_ID; |
| 106 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_RERANK_ENDPOINT_ID_V1; |
| 107 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DEFAULT_RERANK_MODEL_ID_V1; |
| 108 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.DENSE_TEXT_EMBEDDINGS_DIMENSIONS; |
| 109 | +import static org.elasticsearch.xpack.inference.services.elastic.ElasticInferenceService.defaultDenseTextEmbeddingsSimilarity; |
94 | 110 | import static org.hamcrest.CoreMatchers.instanceOf; |
95 | 111 | import static org.hamcrest.CoreMatchers.is; |
96 | 112 | import static org.hamcrest.Matchers.contains; |
| 113 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
97 | 114 | import static org.hamcrest.Matchers.empty; |
98 | 115 | import static org.hamcrest.Matchers.equalTo; |
99 | 116 | import static org.hamcrest.Matchers.hasSize; |
@@ -1298,8 +1315,8 @@ public void testDefaultConfigs_Returns_DefaultEndpoints_WhenTaskTypeIsCorrect() |
1298 | 1315 | ".jina-embeddings-v3", |
1299 | 1316 | MinimalServiceSettings.textEmbedding( |
1300 | 1317 | ElasticInferenceService.NAME, |
1301 | | - ElasticInferenceService.DENSE_TEXT_EMBEDDINGS_DIMENSIONS, |
1302 | | - ElasticInferenceService.defaultDenseTextEmbeddingsSimilarity(), |
| 1318 | + DENSE_TEXT_EMBEDDINGS_DIMENSIONS, |
| 1319 | + defaultDenseTextEmbeddingsSimilarity(), |
1303 | 1320 | DenseVectorFieldMapper.ElementType.FLOAT |
1304 | 1321 | ), |
1305 | 1322 | service |
@@ -1328,6 +1345,93 @@ public void testDefaultConfigs_Returns_DefaultEndpoints_WhenTaskTypeIsCorrect() |
1328 | 1345 | } |
1329 | 1346 | } |
1330 | 1347 |
|
| 1348 | + public void testDefaultConfigs_Returns_DefaultEndpointsModels() throws Exception { |
| 1349 | + String responseJson = """ |
| 1350 | + { |
| 1351 | + "models": [ |
| 1352 | + { |
| 1353 | + "model_name": "rainbow-sprinkles", |
| 1354 | + "task_types": ["chat"] |
| 1355 | + }, |
| 1356 | + { |
| 1357 | + "model_name": "elser_model_2", |
| 1358 | + "task_types": ["embed/text/sparse"] |
| 1359 | + }, |
| 1360 | + { |
| 1361 | + "model_name": "jina-embeddings-v3", |
| 1362 | + "task_types": ["embed/text/dense"] |
| 1363 | + }, |
| 1364 | + { |
| 1365 | + "model_name": "elastic-rerank-v1", |
| 1366 | + "task_types": ["rerank/text/text-similarity"] |
| 1367 | + } |
| 1368 | + ] |
| 1369 | + } |
| 1370 | + """; |
| 1371 | + |
| 1372 | + webServer.enqueue(new MockResponse().setResponseCode(200).setBody(responseJson)); |
| 1373 | + |
| 1374 | + var senderFactory = HttpRequestSenderTests.createSenderFactory(threadPool, clientManager); |
| 1375 | + try (var service = createServiceWithAuthHandler(senderFactory, getUrl(webServer))) { |
| 1376 | + ensureAuthorizationCallFinished(service); |
| 1377 | + var listener = new TestPlainActionFuture<List<Model>>(); |
| 1378 | + |
| 1379 | + service.defaultConfigs(listener); |
| 1380 | + var models = listener.actionGet(TIMEOUT); |
| 1381 | + |
| 1382 | + var elasticInferenceServiceComponents = new ElasticInferenceServiceComponents(getUrl(webServer)); |
| 1383 | + |
| 1384 | + assertThat( |
| 1385 | + models, |
| 1386 | + containsInAnyOrder( |
| 1387 | + new ElasticInferenceServiceCompletionModel( |
| 1388 | + DEFAULT_CHAT_COMPLETION_ENDPOINT_ID_V1, |
| 1389 | + TaskType.CHAT_COMPLETION, |
| 1390 | + ElasticInferenceService.NAME, |
| 1391 | + new ElasticInferenceServiceCompletionServiceSettings(DEFAULT_CHAT_COMPLETION_MODEL_ID_V1), |
| 1392 | + EmptyTaskSettings.INSTANCE, |
| 1393 | + EmptySecretSettings.INSTANCE, |
| 1394 | + elasticInferenceServiceComponents |
| 1395 | + ), |
| 1396 | + new ElasticInferenceServiceSparseEmbeddingsModel( |
| 1397 | + DEFAULT_ELSER_ENDPOINT_ID_V2, |
| 1398 | + TaskType.SPARSE_EMBEDDING, |
| 1399 | + ElasticInferenceService.NAME, |
| 1400 | + new ElasticInferenceServiceSparseEmbeddingsServiceSettings(DEFAULT_ELSER_2_MODEL_ID, null), |
| 1401 | + EmptyTaskSettings.INSTANCE, |
| 1402 | + EmptySecretSettings.INSTANCE, |
| 1403 | + elasticInferenceServiceComponents, |
| 1404 | + ChunkingSettingsBuilder.DEFAULT_SETTINGS |
| 1405 | + ), |
| 1406 | + new ElasticInferenceServiceDenseTextEmbeddingsModel( |
| 1407 | + DEFAULT_MULTILINGUAL_EMBED_ENDPOINT_ID, |
| 1408 | + TaskType.TEXT_EMBEDDING, |
| 1409 | + ElasticInferenceService.NAME, |
| 1410 | + new ElasticInferenceServiceDenseTextEmbeddingsServiceSettings( |
| 1411 | + DEFAULT_MULTILINGUAL_EMBED_MODEL_ID, |
| 1412 | + defaultDenseTextEmbeddingsSimilarity(), |
| 1413 | + DENSE_TEXT_EMBEDDINGS_DIMENSIONS, |
| 1414 | + null |
| 1415 | + ), |
| 1416 | + EmptyTaskSettings.INSTANCE, |
| 1417 | + EmptySecretSettings.INSTANCE, |
| 1418 | + elasticInferenceServiceComponents, |
| 1419 | + ChunkingSettingsBuilder.DEFAULT_SETTINGS |
| 1420 | + ), |
| 1421 | + new ElasticInferenceServiceRerankModel( |
| 1422 | + DEFAULT_RERANK_ENDPOINT_ID_V1, |
| 1423 | + TaskType.RERANK, |
| 1424 | + ElasticInferenceService.NAME, |
| 1425 | + new ElasticInferenceServiceRerankServiceSettings(DEFAULT_RERANK_MODEL_ID_V1), |
| 1426 | + EmptyTaskSettings.INSTANCE, |
| 1427 | + EmptySecretSettings.INSTANCE, |
| 1428 | + elasticInferenceServiceComponents |
| 1429 | + ) |
| 1430 | + ) |
| 1431 | + ); |
| 1432 | + } |
| 1433 | + } |
| 1434 | + |
1331 | 1435 | public void testUnifiedCompletionError() { |
1332 | 1436 | var e = assertThrows(UnifiedChatCompletionException.class, () -> testUnifiedStream(404, """ |
1333 | 1437 | { |
|
0 commit comments