Inference

class elasticsearch.client.InferenceClient(client)
Parameters:

client (BaseClient)

delete(*, inference_id, task_type=None, dry_run=None, error_trace=None, filter_path=None, force=None, human=None, pretty=None)

Delete an inference endpoint

https://www.elastic.co/guide/en/elasticsearch/reference/8.17/delete-inference-api.html

Parameters:
  • inference_id (str) – The inference Id

  • task_type (str | Literal['completion', 'rerank', 'sparse_embedding', 'text_embedding'] | None) – The task type

  • dry_run (bool | None) – When true, the endpoint is not deleted, and a list of ingest processors which reference this endpoint is returned

  • force (bool | None) – When true, the inference endpoint is forcefully deleted even if it is still being used by ingest processors or semantic text fields

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

get(*, task_type=None, inference_id=None, error_trace=None, filter_path=None, human=None, pretty=None)

Get an inference endpoint

https://www.elastic.co/guide/en/elasticsearch/reference/8.17/get-inference-api.html

Parameters:
  • task_type (str | Literal['completion', 'rerank', 'sparse_embedding', 'text_embedding'] | None) – The task type

  • inference_id (str | None) – The inference Id

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

inference(*, inference_id, input=None, task_type=None, error_trace=None, filter_path=None, human=None, pretty=None, query=None, task_settings=None, timeout=None, body=None)

Perform inference on the service

https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html

Parameters:
  • inference_id (str) – The inference Id

  • input (str | Sequence[str] | None) – Inference input. Either a string or an array of strings.

  • task_type (str | Literal['completion', 'rerank', 'sparse_embedding', 'text_embedding'] | None) – The task type

  • query (str | None) – Query input, required for rerank task. Not required for other tasks.

  • task_settings (Any | None) – Optional task settings

  • timeout (str | Literal[-1] | ~typing.Literal[0] | None) – Specifies the amount of time to wait for the inference request to complete.

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

  • body (Dict[str, Any] | None)

Return type:

ObjectApiResponse[Any]

put(*, inference_id, inference_config=None, body=None, task_type=None, error_trace=None, filter_path=None, human=None, pretty=None)

Create an inference endpoint. When you create an inference endpoint, the associated machine learning model is automatically deployed if it is not already running. After creating the endpoint, wait for the model deployment to complete before using it. To verify the deployment status, use the get trained model statistics API. Look for “state”: “fully_allocated” in the response and ensure that the “allocation_count” matches the “target_allocation_count”. Avoid creating multiple endpoints for the same model unless required, as each endpoint consumes significant resources. IMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Mistral, Azure OpenAI, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. However, if you do not plan to use the inference APIs to use these models or if you want to use non-NLP models, use the machine learning trained model APIs.

https://www.elastic.co/guide/en/elasticsearch/reference/8.17/put-inference-api.html

Parameters:
  • inference_id (str) – The inference Id

  • inference_config (Mapping[str, Any] | None)

  • task_type (str | Literal['completion', 'rerank', 'sparse_embedding', 'text_embedding'] | None) – The task type

  • body (Mapping[str, Any] | None)

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

update(*, inference_id, inference_config=None, body=None, task_type=None, error_trace=None, filter_path=None, human=None, pretty=None)

Update an inference endpoint. Modify task_settings, secrets (within service_settings), or num_allocations for an inference endpoint, depending on the specific endpoint service and task_type. IMPORTANT: The inference APIs enable you to use certain services, such as built-in machine learning models (ELSER, E5), models uploaded through Eland, Cohere, OpenAI, Azure, Google AI Studio, Google Vertex AI, Anthropic, Watsonx.ai, or Hugging Face. For built-in models and models uploaded through Eland, the inference APIs offer an alternative way to use and manage trained models. However, if you do not plan to use the inference APIs to use these models or if you want to use non-NLP models, use the machine learning trained model APIs.

https://www.elastic.co/guide/en/elasticsearch/reference/8.17/update-inference-api.html

Parameters:
  • inference_id (str) – The unique identifier of the inference endpoint.

  • inference_config (Mapping[str, Any] | None)

  • task_type (str | Literal['completion', 'rerank', 'sparse_embedding', 'text_embedding'] | None) – The type of inference task that the model performs.

  • body (Mapping[str, Any] | None)

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]