Perform inference APIedit

This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.

Performs an inference task on an input text by using an inference model.

The inference APIs enable you to use certain services, such as ELSER, OpenAI, or Hugging Face, in your cluster. This is not the same feature that you can use on an ML node with custom machine learning models. If you want to train and use your own model, use the Machine learning trained model APIs.

Requestedit

POST /_inference/<task_type>/<model_id>

Prerequisitesedit

Descriptionedit

The perform inference API enables you to use inference models to perform specific tasks on data that you provide as an input. The API returns a response with the resutls of the tasks. The inference model you use can perform one specific task that has been defined when the model was created with the Create inference API.

Path parametersedit

<model_id>
(Required, string) The unique identifier of the inference model.
<task_type>
(Required, string) The type of inference task that the model performs.

Request bodyedit

input
(Required, array of strings) The text on which you want to perform the inference task. input can be a single string or an array.

Examplesedit

The following example performs sparse embedding on the example sentence.

response = client.inference.inference(
  task_type: 'sparse_embedding',
  model_id: 'my-elser-model',
  body: {
    input: 'The sky above the port was the color of television tuned to a dead channel.'
  }
)
puts response
POST _inference/sparse_embedding/my-elser-model
{
  "input": "The sky above the port was the color of television tuned to a dead channel."
}

The API returns the following response:

{
  "sparse_embedding": [
    {
      "port": 2.1259406,
      "sky": 1.7073475,
      "color": 1.6922266,
      "dead": 1.6247464,
      "television": 1.3525393,
      "above": 1.2425821,
      "tuned": 1.1440028,
      "colors": 1.1218185,
      "tv": 1.0111054,
      "ports": 1.0067928,
      "poem": 1.0042328,
      "channel": 0.99471164,
      "tune": 0.96235967,
      "scene": 0.9020516,
      (...)
    },
    (...)
  ]
}