Skip to content

Commit b83f43f

Browse files
author
afoucret
committed
Add settings to control rerank and completion command.
1 parent 83330cd commit b83f43f

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.esql.inference;
9+
10+
import org.elasticsearch.common.settings.Setting;
11+
import org.elasticsearch.common.settings.Settings;
12+
13+
import java.util.Map;
14+
15+
public record InferenceCommandConfig(boolean enabled, int rowLimit) {
16+
17+
public static final Setting<Boolean> COMPLETION_ENABLED_SETTING = commandEnabledSetting("completion");
18+
public static final Setting<Integer> COMPLETION_ROW_LIMIT_SETTING = rowLimitSetting("completion", 100);
19+
public static final Setting<Boolean> RERANK_ENABLED_SETTING = commandEnabledSetting("rerank");
20+
public static final Setting<Integer> RERANK_ROW_LIMIT_SETTING = rowLimitSetting("rerank", 1000);
21+
22+
public static InferenceCommandConfig completionCommandConfig(Settings settings) {
23+
return new InferenceCommandConfig(COMPLETION_ENABLED_SETTING.get(settings), COMPLETION_ROW_LIMIT_SETTING.get(settings));
24+
}
25+
26+
public static InferenceCommandConfig rerankCommandConfig(Settings settings) {
27+
return new InferenceCommandConfig(RERANK_ENABLED_SETTING.get(settings), RERANK_ROW_LIMIT_SETTING.get(settings));
28+
}
29+
30+
public static Map<String, InferenceCommandConfig> fromSettings(Settings settings) {
31+
return Map.of("completion", completionCommandConfig(settings), "rerank", rerankCommandConfig(settings));
32+
}
33+
34+
private static final String ENABLED_SETTING_PATTERN = "inference.command.%s.enabled";
35+
private static final String ROW_LIMIT_PATTERN = "inference.command.%s.row_limit";
36+
37+
private static Setting<Boolean> commandEnabledSetting(String commandName) {
38+
return Setting.boolSetting(
39+
String.format(ENABLED_SETTING_PATTERN, commandName),
40+
true,
41+
Setting.Property.NodeScope,
42+
Setting.Property.Dynamic
43+
);
44+
}
45+
46+
private static Setting<Integer> rowLimitSetting(String commandName, int defaultValue) {
47+
return Setting.intSetting(
48+
String.format(ROW_LIMIT_PATTERN, commandName),
49+
defaultValue,
50+
-1,
51+
Setting.Property.NodeScope,
52+
Setting.Property.Dynamic
53+
);
54+
}
55+
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlConfig.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
package org.elasticsearch.xpack.esql.parser;
99

1010
import org.elasticsearch.Build;
11+
import org.elasticsearch.common.settings.Settings;
12+
import org.elasticsearch.xpack.esql.inference.InferenceCommandConfig;
13+
14+
import java.util.Locale;
15+
import java.util.Map;
1116

1217
class EsqlConfig {
1318

19+
private final Map<String, InferenceCommandConfig> inferenceCommandConfigs;
20+
1421
// versioning information
1522
boolean devVersion = Build.current().isSnapshot();
1623

@@ -25,4 +32,18 @@ boolean isReleaseVersion() {
2532
public void setDevVersion(boolean dev) {
2633
this.devVersion = dev;
2734
}
35+
36+
EsqlConfig(Settings settings) {
37+
inferenceCommandConfigs = InferenceCommandConfig.fromSettings(settings);
38+
}
39+
40+
public InferenceCommandConfig inferenceCommandConfig(String commandName) {
41+
InferenceCommandConfig config = inferenceCommandConfigs.get(commandName.toLowerCase(Locale.ROOT));
42+
43+
if (config == null) {
44+
throw new IllegalArgumentException("Unknown inference command: " + commandName);
45+
}
46+
47+
return config;
48+
}
2849
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.antlr.v4.runtime.TokenSource;
1717
import org.antlr.v4.runtime.VocabularyImpl;
1818
import org.antlr.v4.runtime.atn.PredictionMode;
19+
import org.elasticsearch.common.settings.Settings;
1920
import org.elasticsearch.logging.LogManager;
2021
import org.elasticsearch.logging.Logger;
2122
import org.elasticsearch.xpack.esql.core.util.StringUtils;
@@ -88,14 +89,19 @@ private static void replaceSymbolWithLiteral(Map<String, String> symbolReplaceme
8889
replaceSymbolWithLiteral(symbolReplacements, lexerVocab.getLiteralNames(), lexerVocab.getSymbolicNames());
8990
}
9091

91-
private EsqlConfig config = new EsqlConfig();
92+
private final EsqlConfig config;
9293

93-
public EsqlConfig config() {
94-
return config;
94+
public EsqlParser() {
95+
config = new EsqlConfig(Settings.EMPTY);
9596
}
9697

97-
public void setEsqlConfig(EsqlConfig config) {
98-
this.config = config;
98+
public EsqlParser(Settings settings) {
99+
config = new EsqlConfig(settings);
100+
101+
}
102+
103+
public EsqlConfig config() {
104+
return config;
99105
}
100106

101107
// testing utility

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/EsqlPlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.elasticsearch.xpack.esql.enrich.LookupFromIndexOperator;
7575
import org.elasticsearch.xpack.esql.execution.PlanExecutor;
7676
import org.elasticsearch.xpack.esql.expression.ExpressionWritables;
77+
import org.elasticsearch.xpack.esql.inference.InferenceCommandConfig;
7778
import org.elasticsearch.xpack.esql.io.stream.ExpressionQueryBuilder;
7879
import org.elasticsearch.xpack.esql.io.stream.PlanStreamWrapperQueryBuilder;
7980
import org.elasticsearch.xpack.esql.plan.PlanWritables;
@@ -248,7 +249,11 @@ public List<Setting<?>> getSettings() {
248249
PlannerSettings.REDUCTION_LATE_MATERIALIZATION,
249250
STORED_FIELDS_SEQUENTIAL_PROPORTION,
250251
EsqlFlags.ESQL_STRING_LIKE_ON_INDEX,
251-
EsqlFlags.ESQL_ROUNDTO_PUSHDOWN_THRESHOLD
252+
EsqlFlags.ESQL_ROUNDTO_PUSHDOWN_THRESHOLD,
253+
InferenceCommandConfig.COMPLETION_ENABLED_SETTING,
254+
InferenceCommandConfig.COMPLETION_ROW_LIMIT_SETTING,
255+
InferenceCommandConfig.RERANK_ENABLED_SETTING,
256+
InferenceCommandConfig.RERANK_ROW_LIMIT_SETTING
252257
);
253258
}
254259

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import java.util.Map;
9898
import java.util.Set;
9999
import java.util.concurrent.atomic.AtomicReference;
100+
import java.util.function.Supplier;
100101

101102
import static java.util.stream.Collectors.joining;
102103
import static java.util.stream.Collectors.toSet;
@@ -142,6 +143,7 @@ public interface PlanRunner {
142143
private boolean explainMode;
143144
private String parsedPlanString;
144145
private String optimizedLogicalPlanString;
146+
private Supplier<EsqlParser> parserSupplier;
145147

146148
public EsqlSession(
147149
String sessionId,
@@ -173,6 +175,7 @@ public EsqlSession(
173175
this.intermediateLocalRelationMaxSize = services.plannerSettings().intermediateLocalRelationMaxSize();
174176
this.crossProjectModeDecider = services.crossProjectModeDecider();
175177
this.clusterName = services.clusterService().getClusterName().value();
178+
this.parserSupplier = () -> new EsqlParser(services.clusterService().getSettings());
176179
}
177180

178181
public String sessionId() {
@@ -451,7 +454,7 @@ private static void releaseLocalRelationBlocks(AtomicReference<Page> localRelati
451454
}
452455

453456
private EsqlStatement parse(String query, QueryParams params) {
454-
var parsed = new EsqlParser().createQuery(query, params, planTelemetry);
457+
var parsed = parserSupplier.get().createQuery(query, params, planTelemetry);
455458
if (LOGGER.isDebugEnabled()) {
456459
LOGGER.debug("Parsed logical plan:\n{}", parsed.plan());
457460
LOGGER.debug("Parsed settings:\n[{}]", parsed.settings().stream().map(QuerySetting::toString).collect(joining("; ")));

0 commit comments

Comments
 (0)