|
18 | 18 | import org.elasticsearch.common.settings.Settings; |
19 | 19 | import org.elasticsearch.common.util.LazyInitializable; |
20 | 20 | import org.elasticsearch.core.Nullable; |
| 21 | +import org.elasticsearch.core.Strings; |
21 | 22 | import org.elasticsearch.core.TimeValue; |
22 | 23 | import org.elasticsearch.inference.ChunkedInferenceServiceResults; |
23 | 24 | import org.elasticsearch.inference.ChunkingOptions; |
@@ -113,6 +114,13 @@ public class ElasticsearchInternalService extends BaseElasticsearchInternalServi |
113 | 114 | private static final Logger logger = LogManager.getLogger(ElasticsearchInternalService.class); |
114 | 115 | private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(ElasticsearchInternalService.class); |
115 | 116 |
|
| 117 | + /** |
| 118 | + * Fix for https://github.com/elastic/elasticsearch/issues/124675 |
| 119 | + * In 8.13.0 we transitioned from model_version to model_id. Any elser inference endpoints created prior to 8.13.0 will still use |
| 120 | + * service_settings.model_version. |
| 121 | + */ |
| 122 | + private static final String OLD_MODEL_ID_FIELD_NAME = "model_version"; |
| 123 | + |
116 | 124 | private final Settings settings; |
117 | 125 |
|
118 | 126 | public ElasticsearchInternalService(InferenceServiceExtension.InferenceServiceFactoryContext context) { |
@@ -491,14 +499,18 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M |
491 | 499 | Map<String, Object> serviceSettingsMap = removeFromMapOrThrowIfNull(config, ModelConfigurations.SERVICE_SETTINGS); |
492 | 500 | Map<String, Object> taskSettingsMap = removeFromMapOrDefaultEmpty(config, ModelConfigurations.TASK_SETTINGS); |
493 | 501 |
|
| 502 | + migrateModelVersionToModelId(serviceSettingsMap); |
| 503 | + |
494 | 504 | ChunkingSettings chunkingSettings = null; |
495 | 505 | if (TaskType.TEXT_EMBEDDING.equals(taskType) || TaskType.SPARSE_EMBEDDING.equals(taskType)) { |
496 | 506 | chunkingSettings = ChunkingSettingsBuilder.fromMap(removeFromMap(config, ModelConfigurations.CHUNKING_SETTINGS)); |
497 | 507 | } |
498 | 508 |
|
499 | 509 | String modelId = (String) serviceSettingsMap.get(MODEL_ID); |
500 | 510 | if (modelId == null) { |
501 | | - throw new IllegalArgumentException("Error parsing request config, model id is missing"); |
| 511 | + throw new IllegalArgumentException( |
| 512 | + Strings.format("Error parsing request config, model id is missing for inference id: %s", inferenceEntityId) |
| 513 | + ); |
502 | 514 | } |
503 | 515 |
|
504 | 516 | if (MULTILINGUAL_E5_SMALL_VALID_IDS.contains(modelId)) { |
@@ -530,6 +542,18 @@ public Model parsePersistedConfig(String inferenceEntityId, TaskType taskType, M |
530 | 542 | } |
531 | 543 | } |
532 | 544 |
|
| 545 | + /** |
| 546 | + * Fix for https://github.com/elastic/elasticsearch/issues/124675 |
| 547 | + * In 8.13.0 we transitioned from model_version to model_id. Any elser inference endpoints created prior to 8.13.0 will still use |
| 548 | + * service_settings.model_version. We need to look for that key and migrate it to model_id. |
| 549 | + */ |
| 550 | + private void migrateModelVersionToModelId(Map<String, Object> serviceSettingsMap) { |
| 551 | + if (serviceSettingsMap.containsKey(OLD_MODEL_ID_FIELD_NAME)) { |
| 552 | + String modelId = ServiceUtils.removeAsType(serviceSettingsMap, OLD_MODEL_ID_FIELD_NAME, String.class); |
| 553 | + serviceSettingsMap.put(ElserInternalServiceSettings.MODEL_ID, modelId); |
| 554 | + } |
| 555 | + } |
| 556 | + |
533 | 557 | @Override |
534 | 558 | public void checkModelConfig(Model model, ActionListener<Model> listener) { |
535 | 559 | if (model instanceof CustomElandEmbeddingModel elandModel && elandModel.getTaskType() == TaskType.TEXT_EMBEDDING) { |
|
0 commit comments