Skip to content

Commit 4b0aded

Browse files
moving inference timeout from index settings to cluster settings
1 parent 56cef20 commit 4b0aded

File tree

4 files changed

+11
-43
lines changed

4 files changed

+11
-43
lines changed

server/src/main/java/org/elasticsearch/index/mapper/InferenceMetadataFieldsMapper.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
import org.elasticsearch.cluster.metadata.IndexMetadata;
1616
import org.elasticsearch.common.settings.Setting;
1717
import org.elasticsearch.common.settings.Settings;
18-
import org.elasticsearch.core.TimeValue;
1918
import org.elasticsearch.index.IndexVersion;
2019
import org.elasticsearch.index.IndexVersions;
2120
import org.elasticsearch.index.query.SearchExecutionContext;
2221

2322
import java.util.Map;
24-
import java.util.concurrent.TimeUnit;
2523
import java.util.function.Function;
2624

2725
/**
@@ -30,7 +28,6 @@
3028
* the field name for removal from _source.
3129
*/
3230
public abstract class InferenceMetadataFieldsMapper extends MetadataFieldMapper {
33-
public static final TimeValue DEFAULT_SEMANTIC_TEXT_INFERENCE_TIMEOUT = TimeValue.timeValueSeconds(TimeUnit.SECONDS.toSeconds(10));
3431
/**
3532
* Internal index setting to control the format used for semantic text fields.
3633
* Determines whether to use the legacy format (default: true).
@@ -44,12 +41,6 @@ public abstract class InferenceMetadataFieldsMapper extends MetadataFieldMapper
4441
Setting.Property.IndexScope,
4542
Setting.Property.InternalIndex
4643
);
47-
public static final Setting<TimeValue> SEMANTIC_TEXT_INFERENCE_TIMEOUT = Setting.timeSetting(
48-
"index.semantic_text.inference_timeout",
49-
DEFAULT_SEMANTIC_TEXT_INFERENCE_TIMEOUT,
50-
Setting.Property.IndexScope,
51-
Setting.Property.Dynamic
52-
);
5344

5445
// Check index version SOURCE_MAPPER_MODE_ATTRIBUTE_NOOP because that index version was added in the same serverless promotion
5546
// where the new format was enabled by default

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.elasticsearch.core.IOUtils;
2626
import org.elasticsearch.core.TimeValue;
2727
import org.elasticsearch.features.NodeFeature;
28-
import org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper;
2928
import org.elasticsearch.index.mapper.Mapper;
3029
import org.elasticsearch.index.mapper.MetadataFieldMapper;
3130
import org.elasticsearch.indices.SystemIndexDescriptor;
@@ -148,6 +147,7 @@
148147
import java.util.List;
149148
import java.util.Map;
150149
import java.util.Set;
150+
import java.util.concurrent.TimeUnit;
151151
import java.util.function.Predicate;
152152
import java.util.function.Supplier;
153153

@@ -180,6 +180,13 @@ public class InferencePlugin extends Plugin
180180
Setting.Property.NodeScope,
181181
Setting.Property.Dynamic
182182
);
183+
public static final TimeValue DEFAULT_SEMANTIC_TEXT_INFERENCE_TIMEOUT = TimeValue.timeValueSeconds(TimeUnit.SECONDS.toSeconds(10));
184+
public static final Setting<TimeValue> SEMANTIC_TEXT_INFERENCE_TIMEOUT = Setting.timeSetting(
185+
"xpack.inference.semantic_text.inference_timeout",
186+
DEFAULT_SEMANTIC_TEXT_INFERENCE_TIMEOUT,
187+
Setting.Property.NodeScope,
188+
Setting.Property.Dynamic
189+
);
183190

184191
public static final LicensedFeature.Momentary INFERENCE_API_FEATURE = LicensedFeature.momentary(
185192
"inference",
@@ -496,7 +503,7 @@ public List<Setting<?>> getSettings() {
496503
settings.add(SKIP_VALIDATE_AND_START);
497504
settings.add(INDICES_INFERENCE_BATCH_SIZE);
498505
settings.addAll(ElasticInferenceServiceSettings.getSettingsDefinitions());
499-
settings.add(InferenceMetadataFieldsMapper.SEMANTIC_TEXT_INFERENCE_TIMEOUT);
506+
settings.add(SEMANTIC_TEXT_INFERENCE_TIMEOUT);
500507
return settings;
501508
}
502509

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportInferenceAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ protected void doInference(
7474
InferenceService service,
7575
ActionListener<InferenceServiceResults> listener
7676
) {
77+
7778
service.infer(
7879
model,
7980
request.getQuery(),

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/queries/SemanticQueryBuilder.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ private SemanticQueryBuilder doRewriteGetInferenceResults(QueryRewriteContext qu
226226
}
227227

228228
String inferenceId = getInferenceIdForForField(resolvedIndices.getConcreteLocalIndicesMetadata().values(), fieldName);
229-
TimeValue inferenceTimeout = getInferenceTimeeoutForSemanticField(
230-
resolvedIndices.getConcreteLocalIndicesMetadata().values(),
231-
fieldName
232-
);
233229
SetOnce<InferenceServiceResults> inferenceResultsSupplier = new SetOnce<>();
234230
boolean noInferenceResults = false;
235231
if (inferenceId != null) {
@@ -242,7 +238,7 @@ private SemanticQueryBuilder doRewriteGetInferenceResults(QueryRewriteContext qu
242238
List.of(query),
243239
Map.of(),
244240
InputType.INTERNAL_SEARCH,
245-
inferenceTimeout,
241+
null,
246242
false
247243
);
248244

@@ -269,33 +265,6 @@ private SemanticQueryBuilder doRewriteGetInferenceResults(QueryRewriteContext qu
269265
return new SemanticQueryBuilder(this, noInferenceResults ? null : inferenceResultsSupplier, null, noInferenceResults);
270266
}
271267

272-
@SuppressWarnings("unchecked")
273-
private TimeValue getInferenceTimeeoutForSemanticField(Collection<IndexMetadata> indexMetadataCollection, String fieldName) {
274-
TimeValue inferenceTimeout = InferenceMetadataFieldsMapper.DEFAULT_SEMANTIC_TEXT_INFERENCE_TIMEOUT;
275-
for (IndexMetadata indexMetadata : indexMetadataCollection) {
276-
boolean fieldExistsInIndex = indexMetadata.mapping()
277-
.getSourceAsMap()
278-
.values()
279-
.stream()
280-
.filter(v -> v instanceof Map)
281-
.map(v -> (Map<String, Object>) v)
282-
.anyMatch(m -> m.containsKey(fieldName));
283-
284-
if (fieldExistsInIndex == false) {
285-
continue;
286-
}
287-
288-
TimeValue currentInferenceTimeout = indexMetadata.getSettings()
289-
.getAsTime("index.semantic_text.inference_timeout", InferenceMetadataFieldsMapper.DEFAULT_SEMANTIC_TEXT_INFERENCE_TIMEOUT);
290-
291-
if (currentInferenceTimeout.compareTo(inferenceTimeout) < 0) {
292-
inferenceTimeout = currentInferenceTimeout;
293-
}
294-
}
295-
296-
return inferenceTimeout;
297-
}
298-
299268
private static InferenceResults validateAndConvertInferenceResults(
300269
SetOnce<InferenceServiceResults> inferenceResultsSupplier,
301270
String fieldName

0 commit comments

Comments
 (0)