Closed davidkyle closed 5 months ago
Pinging @elastic/ml-core (Team:ML)
I'd like to take this if possible.
@AllyKaz I think this is one we'll handle internally, as it could need a lot of discussion and we might decide to do some bits but not others.
@droberts195 Understood. I had a quick look over it regardless, and the first part, at least, seems a pretty straight forward matter of a few changes in the InferenceProcessor.Factory
. Seems like it should fit quite neatly into the current tests too.
Description
Early in the development process there was a design decision that NLP models and Boosted Tree models should use the same APIs, both for convenience and so that users don't have to learn new APIs. However, Boosted tree models are different in that they take any number of inputs and that requires extra configuration. Configuring NLP models in ingest pipelines has inherited a complexity from Boosted tree models that is redundant and difficult to get started with.
Any changes must be backwards compatible, the current configuration options would still be supported along with any enhancements.
Ingest Pipelines
Take an ingest pipeline configured for ELSER
1. field_map
The NLP model is configured with an input field name when it is created. This cannot be changed at inference so the user must map the name of the field in the input document to the expected input field name. Conventionally this is named
text_field
if Eland is used to upload the model but it may be something else in which case the model configuration must be checked to figure out what the field should be called.field_map
makes more sense for boosted tree models where there are multiple inputs. For NLP the input is a single field which could be set simply with:Users often get the map the wrong way round as there is poor intuition about which way the mapping goes.
2. target_field
It is not obvious that the results will be written to the concatenation of
target_field
andresults_field
wheretarget_field
is the top level object.target_field
cannot be null or empty so there is no way to put the results in the root of the document. The default value isml.inference
so the results will be written toml.inference.<results_field>
if not set.Add the ability to set a null or empty
target_field
so that results can go into the root of the document.3. results_field
The
results_fields
is specified 2 levels down inside 2 nested objects:If the task type (in this case
text_expansion
) is wrong an error will be returned. This makes it hard to reuse configurations as the correct task type must be found just to setresults_field
. This setting that is common to both Boosted tree and NLP models and could be lifted out of theinference_config
.The default value of
results_field
ispredicted_value
so setting this field is not strictly required.A Simpler Option
Applying these ideas the config would be less verbose and less error prone. Reusing this config in many cases would be a matter of changing the
model_id
orinput_field
.Or if the user is happy with the default target & result field names:
Which would write results to
ml.inference.predicted_value
._infer API
The _infer API accepts an array of docs, each doc should contain a field named the same as the expected input field, as above conventionally this is
text_field
.The example for ELSER is:
If the correct input field is missing a helpful error is returned:
returns:
NLP Models expect one input not a document. Instead of extracting the field from the docs a simpler option is to specify the input without consideration of the name of the field the model expects in a document.
Or for multiple requests: