Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Add prefix strings option to trained models #101978

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9ed028f
Prefix strings
davidkyle Nov 9, 2023
2d4dc4c
fix the tests
davidkyle Nov 9, 2023
c4d3327
prefix type in the request
davidkyle Nov 10, 2023
f8936fa
Update docs/changelog/101978.yaml
davidkyle Nov 10, 2023
14a58ab
docs
davidkyle Nov 10, 2023
36fa520
Update docs/reference/ml/trained-models/apis/put-trained-models.asciidoc
davidkyle Nov 13, 2023
7189fc0
Update docs/reference/ml/trained-models/apis/put-trained-models.asciidoc
davidkyle Nov 13, 2023
b7f19ad
Avoid negative DesiredBalanceStats#lastConvergedIndex (#101998)
DaveCTurner Nov 10, 2023
df91976
[DOCS] DISSECT does not support reference keys (#102002)
abdonpijpelink Nov 10, 2023
898676b
Corrected the expansion of overlapping terms in the unified highlight…
jimczi Nov 10, 2023
1d77446
Mute tests for #102000 (#102006)
original-brownbear Nov 10, 2023
aaded1b
Mute test for #102010 (#102011)
original-brownbear Nov 10, 2023
1f9b9fb
Remove some more explicit SearchResponse use in tests (#102003)
piergm Nov 10, 2023
a4de390
Allowing non-dynamic index settings to be updated by automatically un…
masseyke Nov 10, 2023
3639787
ES-6566: Move the calculation of data tier usage stats to individual …
gmarouli Nov 10, 2023
1c09614
[ci] Fix build scan annotations on Windows (#101990)
brianseeders Nov 10, 2023
5e3f814
Remove all SearchResponse direct references from tests (#102024)
benwtrent Nov 10, 2023
8009557
Revert "Keep old plugin name for build complete plugin (#101995)" (#1…
breskeby Nov 10, 2023
9ef2514
Remove explicit SearchResponse references from server metrics aggs IT…
original-brownbear Nov 10, 2023
6426cf1
Fix a few more explicit SearchResponse uses in the server package (#1…
original-brownbear Nov 10, 2023
cf55c12
Revert "ES-6566: Move the calculation of data tier usage stats to ind…
gmarouli Nov 10, 2023
395dd6b
Fix caching for StandaloneRestIntegTest tasks (#102043)
breskeby Nov 10, 2023
14e7635
Mute UpgradeClusterClientYamlTestSuiteIT
mark-vieira Nov 10, 2023
fba946c
Revert "Mute UpgradeClusterClientYamlTestSuiteIT"
mark-vieira Nov 10, 2023
8693c79
Remove explicit search responses from IndexAliasIT (#101996)
original-brownbear Nov 10, 2023
f5ac741
Removing the use of Version.CURRENT from watcher (#102045)
masseyke Nov 10, 2023
e18d126
null check on searchResponse (#102017)
piergm Nov 10, 2023
0e5d09e
Update tests to decrement ref count (#102044)
JVerwolf Nov 10, 2023
62a5a09
Remove explicit SearchResponse references from server bucket aggs (pa…
iverase Nov 11, 2023
2058d22
Remove explicit SearchResponse references from server bucket aggs (pa…
iverase Nov 12, 2023
9e9b42e
Remove explicit SearchResponse references from server bucket aggs (pa…
iverase Nov 12, 2023
f481bad
Remove explicit SearchResponse references from server bucket aggs (pa…
iverase Nov 12, 2023
b22b42b
Repo analysis: verify empty register (#102048)
DaveCTurner Nov 13, 2023
74d9593
Repo analysis: allow configuration of register ops (#102051)
DaveCTurner Nov 13, 2023
3d2e0ce
Add stats by model to the machine learning usage stats. (#101915)
jan-elastic Nov 13, 2023
9281730
Using VersionInformation explicitly (#101962)
ldematte Nov 13, 2023
1280662
Remove some more explicit SearchResponse use in tests Pt2 (#102029)
piergm Nov 13, 2023
4f91fb1
[DOCS] Clarify ES|QL grok escaping (#102059)
abdonpijpelink Nov 13, 2023
b9f8b89
[DOCS] Fix typo (#101791)
andreidan Nov 13, 2023
35631ae
Remove obsolete version check for autoid creates (#101623)
thecoop Nov 13, 2023
27080db
Update connector templates to use a historical feature (#101531)
thecoop Nov 13, 2023
baa3aa9
Removing explicit SearchResponse usages in tests - v3 (#102019)
pmpailis Nov 13, 2023
86d1a95
AwaitsFix for #102070
DaveCTurner Nov 13, 2023
0da28fd
Removing explicit SearchResponse usages in tests (#102008)
pmpailis Nov 13, 2023
97d6325
Prefix strings
davidkyle Nov 9, 2023
99fbdbf
Add prefix strings to model package config
davidkyle Nov 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/101978.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 101978
summary: Add prefix strings option to trained models
area: Machine Learning
type: enhancement
issues: []
44 changes: 35 additions & 9 deletions docs/reference/ml/trained-models/apis/put-trained-models.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====

Expand All @@ -469,7 +469,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the
Refer to <<tokenization-properties>> to review the
properties of the `tokenization` object.
=====

Expand All @@ -488,7 +488,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====

Expand All @@ -514,7 +514,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenizati
Recommended to set `max_sentence_length` to `386` with `128` of `span` and set
`truncate` to `none`.
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====

Expand Down Expand Up @@ -546,7 +546,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-classific

`num_top_classes`::::
(Optional, integer)
Specifies the number of top class predictions to return. Defaults to all classes
Specifies the number of top class predictions to return. Defaults to all classes
(-1).

`results_field`::::
Expand All @@ -557,7 +557,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====

Expand All @@ -580,7 +580,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====

Expand All @@ -599,7 +599,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-text-similarit
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====

Expand Down Expand Up @@ -634,7 +634,7 @@ include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-results-field]
(Optional, object)
include::{es-repo-dir}/ml/ml-shared.asciidoc[tag=inference-config-nlp-tokenization]
+
Refer to <<tokenization-properties>> to review the properties of the
Refer to <<tokenization-properties>> to review the properties of the
`tokenization` object.
=====
====
Expand Down Expand Up @@ -701,6 +701,32 @@ the platform identifiers used by Elasticsearch, so one of, `linux-x86_64`,
For portable models (those that work independent of processor architecture or
OS features), leave this field unset.

//Begin prefix_strings
`prefix_strings`::
(Optional, object)
Certain NLP models are trained in such a way that a prefix string should
be applied to the input text before the input is evaluated. The prefix
may be different depending on the intention. For asymmetric tasks such
as infromation retrieval the prefix applied to a passage as it is indexed
can be different to the prefix applied when searching those passages.

`prefix_strings` has 2 options, a prefix string that is always applied
in the search context and one that is always applied when ingesting the
docs. Both are optional.
+
.Properties of `prefix_strings`
[%collapsible%open]
====
`search`:::
(Optional, string)
The prefix string to prepend to the input text for requests
originating from a search query.
davidkyle marked this conversation as resolved.
Show resolved Hide resolved
`ingest`:::
(Optional, string)
The prefix string to prepend to the input text for requests
at ingest where the Inference ingest processor is used. // TODO is there a shortcut for Inference ingest processor?
davidkyle marked this conversation as resolved.
Show resolved Hide resolved
====
//End prefix_strings

`tags`::
(Optional, string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static TransportVersion def(int id) {
public static final TransportVersion UNDESIRED_SHARD_ALLOCATIONS_COUNT_ADDED = def(8_530_00_0);
public static final TransportVersion ML_INFERENCE_TASK_SETTINGS_OPTIONAL_ADDED = def(8_531_00_0);
public static final TransportVersion DEPRECATED_COMPONENT_TEMPLATES_ADDED = def(8_532_00_0);

public static final TransportVersion ML_TRAINED_MODEL_PREFIX_STRINGS_ADDED = def(8_533_00_0);
/*
* STOP! READ THIS FIRST! No, really,
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ private static void checkUniqueness(int id, String uniqueId) {

public static final MlConfigVersion V_10 = registerMlConfigVersion(10_00_00_99, "4B940FD9-BEDD-4589-8E08-02D9B480B22D");
// V_11 is used in ELSER v2 package configs
public static final MlConfigVersion V_11 = registerMlConfigVersion(11_00_00_99, "79CB2950-57C7-11EE-AE5D-0800200C9A66");
public static final MlConfigVersion V_11 = registerMlConfigVersion(11_00_0_0_99, "79CB2950-57C7-11EE-AE5D-0800200C9A66");
public static final MlConfigVersion V_12 = registerMlConfigVersion(12_00_0_0_99, "Trained model config prefix strings added");

/**
* Reference to the most recent Ml config version.
* This should be the Ml config version with the highest id.
*/
public static final MlConfigVersion CURRENT = V_11;
public static final MlConfigVersion CURRENT = V_12;

/**
* Reference to the first MlConfigVersion that is detached from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelPrefixStrings;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.EmptyConfigUpdate;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfigUpdate;
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
Expand Down Expand Up @@ -88,6 +89,7 @@ public static Builder parseRequest(String id, XContentParser parser) {
// input and so cannot construct a document.
private final List<String> textInput;
private boolean highPriority;
private TrainedModelPrefixStrings.PrefixType prefixType = TrainedModelPrefixStrings.PrefixType.NONE;

/**
* Build a request from a list of documents as maps.
Expand Down Expand Up @@ -190,6 +192,11 @@ public Request(StreamInput in) throws IOException {
if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) {
highPriority = in.readBoolean();
}
if (in.getTransportVersion().onOrAfter(TransportVersions.ML_TRAINED_MODEL_PREFIX_STRINGS_ADDED)) {
prefixType = in.readEnum(TrainedModelPrefixStrings.PrefixType.class);
} else {
prefixType = TrainedModelPrefixStrings.PrefixType.NONE;
}
}

public int numberOfDocuments() {
Expand Down Expand Up @@ -232,6 +239,14 @@ public void setHighPriority(boolean highPriority) {
this.highPriority = highPriority;
}

public void setPrefixType(TrainedModelPrefixStrings.PrefixType prefixType) {
this.prefixType = prefixType;
}

public TrainedModelPrefixStrings.PrefixType getPrefixType() {
return prefixType;
}

@Override
public ActionRequestValidationException validate() {
return null;
Expand All @@ -253,6 +268,9 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_8_0)) {
out.writeBoolean(highPriority);
}
if (out.getTransportVersion().onOrAfter(TransportVersions.ML_TRAINED_MODEL_PREFIX_STRINGS_ADDED)) {
out.writeEnum(prefixType);
}
}

@Override
Expand All @@ -266,7 +284,8 @@ public boolean equals(Object o) {
&& Objects.equals(inferenceTimeout, that.inferenceTimeout)
&& Objects.equals(objectsToInfer, that.objectsToInfer)
&& Objects.equals(textInput, that.textInput)
&& (highPriority == that.highPriority);
&& (highPriority == that.highPriority)
&& (prefixType == that.prefixType);
}

@Override
Expand All @@ -276,7 +295,7 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,

@Override
public int hashCode() {
return Objects.hash(id, objectsToInfer, update, previouslyLicensed, inferenceTimeout, textInput, highPriority);
return Objects.hash(id, objectsToInfer, update, previouslyLicensed, inferenceTimeout, textInput, highPriority, prefixType);
}

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.core.ml.inference.TrainedModelPrefixStrings;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.EmptyConfigUpdate;
import org.elasticsearch.xpack.core.ml.inference.trainedmodel.InferenceConfigUpdate;
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
Expand Down Expand Up @@ -102,6 +103,7 @@ public static Request.Builder parseRequest(String id, XContentParser parser) {
// and do know which field the model expects to find its
// input and so cannot construct a document.
private final List<String> textInput;
private TrainedModelPrefixStrings.PrefixType prefixType = TrainedModelPrefixStrings.PrefixType.NONE;

public static Request forDocs(String id, InferenceConfigUpdate update, List<Map<String, Object>> docs, TimeValue inferenceTimeout) {
return new Request(
Expand Down Expand Up @@ -156,6 +158,11 @@ public Request(StreamInput in) throws IOException {
} else {
textInput = null;
}
if (in.getTransportVersion().onOrAfter(TransportVersions.ML_TRAINED_MODEL_PREFIX_STRINGS_ADDED)) {
prefixType = in.readEnum(TrainedModelPrefixStrings.PrefixType.class);
} else {
prefixType = TrainedModelPrefixStrings.PrefixType.NONE;
}
}

public String getId() {
Expand Down Expand Up @@ -200,6 +207,14 @@ public boolean isHighPriority() {
return highPriority;
}

public void setPrefixType(TrainedModelPrefixStrings.PrefixType prefixType) {
this.prefixType = prefixType;
}

public TrainedModelPrefixStrings.PrefixType getPrefixType() {
return prefixType;
}

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = super.validate();
Expand All @@ -226,6 +241,9 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_7_0)) {
out.writeOptionalStringCollection(textInput);
}
if (out.getTransportVersion().onOrAfter(TransportVersions.ML_TRAINED_MODEL_PREFIX_STRINGS_ADDED)) {
out.writeEnum(prefixType);
}
}

@Override
Expand All @@ -243,12 +261,13 @@ public boolean equals(Object o) {
&& Objects.equals(update, that.update)
&& Objects.equals(inferenceTimeout, that.inferenceTimeout)
&& Objects.equals(highPriority, that.highPriority)
&& Objects.equals(textInput, that.textInput);
&& Objects.equals(textInput, that.textInput)
&& (prefixType == that.prefixType);
}

@Override
public int hashCode() {
return Objects.hash(id, update, docs, inferenceTimeout, highPriority, textInput);
return Objects.hash(id, update, docs, inferenceTimeout, highPriority, textInput, prefixType);
}

@Override
Expand Down
Loading