diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/chat_completion_unified.rb similarity index 66% rename from elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb rename to elasticsearch-api/lib/elasticsearch/api/actions/inference/chat_completion_unified.rb index 1e7fd39d7c..003f1240ba 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/chat_completion_unified.rb @@ -15,27 +15,28 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API module Inference module Actions - # Perform inference + # Perform chat completion inference # - # @option arguments [String] :inference_id The inference Id - # @option arguments [String] :task_type The task type + # @option arguments [String] :inference_id The inference Id (*Required*) + # @option arguments [Time] :timeout Specifies the amount of time to wait for the inference request to complete. Server default: 30s. # @option arguments [Hash] :headers Custom HTTP headers - # @option arguments [Hash] :body The inference payload + # @option arguments [Hash] :body request body # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/post-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-unified-inference # - def inference(arguments = {}) - request_opts = { endpoint: arguments[:endpoint] || 'inference.inference' } + def chat_completion_unified(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.chat_completion_unified' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? @@ -48,15 +49,9 @@ def inference(arguments = {}) _inference_id = arguments.delete(:inference_id) - _task_type = arguments.delete(:task_type) - method = Elasticsearch::API::HTTP_POST - path = if _task_type && _inference_id - "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}" - else - "_inference/#{Utils.__listify(_inference_id)}" - end - params = {} + path = "_inference/chat_completion/#{Utils.__listify(_inference_id)}/_stream" + params = Utils.process_params(arguments) Elasticsearch::API::Response.new( perform_request(method, path, params, body, headers, request_opts) diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_inference.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/completion.rb similarity index 65% rename from elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_inference.rb rename to elasticsearch-api/lib/elasticsearch/api/actions/inference/completion.rb index 539b4922a1..d32172bcd4 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_inference.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/completion.rb @@ -15,27 +15,28 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API module Inference module Actions - # Perform streaming inference + # Perform completion inference on the service # - # @option arguments [String] :inference_id The inference Id - # @option arguments [String] :task_type The task type + # @option arguments [String] :inference_id The inference Id (*Required*) + # @option arguments [Time] :timeout Specifies the amount of time to wait for the inference request to complete. Server default: 30s. # @option arguments [Hash] :headers Custom HTTP headers - # @option arguments [Hash] :body The inference payload + # @option arguments [Hash] :body request body # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/post-stream-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference # - def stream_inference(arguments = {}) - request_opts = { endpoint: arguments[:endpoint] || 'inference.stream_inference' } + def completion(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.completion' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? @@ -48,15 +49,9 @@ def stream_inference(arguments = {}) _inference_id = arguments.delete(:inference_id) - _task_type = arguments.delete(:task_type) - method = Elasticsearch::API::HTTP_POST - path = if _task_type && _inference_id - "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_stream" - else - "_inference/#{Utils.__listify(_inference_id)}/_stream" - end - params = {} + path = "_inference/completion/#{Utils.__listify(_inference_id)}" + params = Utils.process_params(arguments) Elasticsearch::API::Response.new( perform_request(method, path, params, body, headers, request_opts) diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/delete.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/delete.rb index 02d5f328cd..5e9e570d6e 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/delete.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/delete.rb @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API @@ -24,19 +24,20 @@ module Inference module Actions # Delete an inference endpoint # - # @option arguments [String] :inference_id The inference Id # @option arguments [String] :task_type The task type - # @option arguments [Boolean] :dry_run If true the endpoint will not be deleted and a list of ingest processors which reference this endpoint will be returned. - # @option arguments [Boolean] :force If true the endpoint will be forcefully stopped (regardless of whether or not it is referenced by any ingest processors or semantic text fields). + # @option arguments [String] :inference_id The inference identifier. (*Required*) + # @option arguments [Boolean] :dry_run When true, the endpoint is not deleted and a list of ingest processors which reference this endpoint is returned. + # @option arguments [Boolean] :force When true, the inference endpoint is forcefully deleted even if it is still being used by ingest processors or semantic text fields. # @option arguments [Hash] :headers Custom HTTP headers # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-delete # def delete(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.delete' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id, :task_type].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? @@ -47,10 +48,10 @@ def delete(arguments = {}) body = nil - _inference_id = arguments.delete(:inference_id) - _task_type = arguments.delete(:task_type) + _inference_id = arguments.delete(:inference_id) + method = Elasticsearch::API::HTTP_DELETE path = if _task_type && _inference_id "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}" diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/get.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/get.rb index a3fec86adb..8c419cb1c5 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/get.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/get.rb @@ -15,8 +15,8 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API @@ -24,17 +24,18 @@ module Inference module Actions # Get an inference endpoint # - # @option arguments [String] :inference_id The inference Id # @option arguments [String] :task_type The task type + # @option arguments [String] :inference_id The inference Id # @option arguments [Hash] :headers Custom HTTP headers # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/get-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-get # def get(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.get' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id, :task_type].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? @@ -43,17 +44,17 @@ def get(arguments = {}) body = nil - _inference_id = arguments.delete(:inference_id) - _task_type = arguments.delete(:task_type) + _inference_id = arguments.delete(:inference_id) + method = Elasticsearch::API::HTTP_GET path = if _task_type && _inference_id "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}" elsif _inference_id "_inference/#{Utils.__listify(_inference_id)}" else - '_inference' + "_inference" end params = {} diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/put.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/put.rb index aabcd25a4e..20a984dd46 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/put.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/put.rb @@ -15,30 +15,40 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API module Inference module Actions - # Configure an inference endpoint for use in the Inference API + # 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. # - # @option arguments [String] :inference_id The inference Id # @option arguments [String] :task_type The task type + # @option arguments [String] :inference_id The inference Id (*Required*) # @option arguments [Hash] :headers Custom HTTP headers - # @option arguments [Hash] :body The inference endpoint's task and service settings + # @option arguments [Hash] :body inference_config # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/put-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-put # def put(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.put' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id, :task_type].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id] arguments = arguments.clone @@ -46,10 +56,10 @@ def put(arguments = {}) body = arguments.delete(:body) - _inference_id = arguments.delete(:inference_id) - _task_type = arguments.delete(:task_type) + _inference_id = arguments.delete(:inference_id) + method = Elasticsearch::API::HTTP_PUT path = if _task_type && _inference_id "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}" diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/put_watsonx.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/put_watsonx.rb new file mode 100644 index 0000000000..255ff5de0a --- /dev/null +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/put_watsonx.rb @@ -0,0 +1,77 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification +# +module Elasticsearch + module API + module Inference + module Actions + # Create a Watsonx inference endpoint. + # Creates an inference endpoint to perform an inference task with the +watsonxai+ service. + # You need an IBM Cloud Databases for Elasticsearch deployment to use the +watsonxai+ inference service. + # You can provision one through the IBM catalog, the Cloud Databases CLI plug-in, the Cloud Databases API, or Terraform. + # 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. + # + # @option arguments [String] :task_type The task type. + # The only valid task type for the model to perform is +text_embedding+. (*Required*) + # @option arguments [String] :watsonx_inference_id The unique identifier of the inference endpoint. (*Required*) + # @option arguments [Hash] :headers Custom HTTP headers + # @option arguments [Hash] :body request body + # + # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/infer-service-watsonx-ai.html + # + def put_watsonx(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.put_watsonx' } + + defined_params = [:task_type, :watsonx_inference_id].inject({}) do |set_variables, variable| + set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables + end + request_opts[:defined_params] = defined_params unless defined_params.empty? + + raise ArgumentError, "Required argument 'task_type' missing" unless arguments[:task_type] + + raise ArgumentError, + "Required argument 'watsonx_inference_id' missing" unless arguments[:watsonx_inference_id] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + body = arguments.delete(:body) + + _task_type = arguments.delete(:task_type) + + _watsonx_inference_id = arguments.delete(:watsonx_inference_id) + + method = Elasticsearch::API::HTTP_PUT + path = "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_watsonx_inference_id)}" + params = {} + + Elasticsearch::API::Response.new( + perform_request(method, path, params, body, headers, request_opts) + ) + end + end + end + end +end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/rerank.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/rerank.rb new file mode 100644 index 0000000000..065fc63a49 --- /dev/null +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/rerank.rb @@ -0,0 +1,63 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification +# +module Elasticsearch + module API + module Inference + module Actions + # Perform rereanking inference on the service + # + # @option arguments [String] :inference_id The unique identifier for the inference endpoint. (*Required*) + # @option arguments [Time] :timeout The amount of time to wait for the inference request to complete. Server default: 30s. + # @option arguments [Hash] :headers Custom HTTP headers + # @option arguments [Hash] :body request body + # + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference + # + def rerank(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.rerank' } + + defined_params = [:inference_id].inject({}) do |set_variables, variable| + set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables + end + request_opts[:defined_params] = defined_params unless defined_params.empty? + + raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + body = arguments.delete(:body) + + _inference_id = arguments.delete(:inference_id) + + method = Elasticsearch::API::HTTP_POST + path = "_inference/rerank/#{Utils.__listify(_inference_id)}" + params = Utils.process_params(arguments) + + Elasticsearch::API::Response.new( + perform_request(method, path, params, body, headers, request_opts) + ) + end + end + end + end +end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/unified_inference.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/sparse_embedding.rb similarity index 64% rename from elasticsearch-api/lib/elasticsearch/api/actions/inference/unified_inference.rb rename to elasticsearch-api/lib/elasticsearch/api/actions/inference/sparse_embedding.rb index f06a42fbef..76acbf89e9 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/unified_inference.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/sparse_embedding.rb @@ -15,27 +15,28 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API module Inference module Actions - # Perform inference using the Unified Schema + # Perform sparse embedding inference on the service # - # @option arguments [String] :inference_id The inference Id - # @option arguments [String] :task_type The task type + # @option arguments [String] :inference_id The inference Id (*Required*) + # @option arguments [Time] :timeout Specifies the amount of time to wait for the inference request to complete. Server default: 30s. # @option arguments [Hash] :headers Custom HTTP headers - # @option arguments [Hash] :body The inference payload + # @option arguments [Hash] :body request body # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/unified-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference # - def unified_inference(arguments = {}) - request_opts = { endpoint: arguments[:endpoint] || 'inference.unified_inference' } + def sparse_embedding(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.sparse_embedding' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? @@ -48,15 +49,9 @@ def unified_inference(arguments = {}) _inference_id = arguments.delete(:inference_id) - _task_type = arguments.delete(:task_type) - method = Elasticsearch::API::HTTP_POST - path = if _task_type && _inference_id - "_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_unified" - else - "_inference/#{Utils.__listify(_inference_id)}/_unified" - end - params = {} + path = "_inference/sparse_embedding/#{Utils.__listify(_inference_id)}" + params = Utils.process_params(arguments) Elasticsearch::API::Response.new( perform_request(method, path, params, body, headers, request_opts) diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_completion.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_completion.rb new file mode 100644 index 0000000000..bd13f1624b --- /dev/null +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_completion.rb @@ -0,0 +1,66 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification +# +module Elasticsearch + module API + module Inference + module Actions + # Perform streaming inference. + # Get real-time responses for completion tasks by delivering answers incrementally, reducing response times during computation. + # This API works only with the completion 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. + # This API requires the +monitor_inference+ cluster privilege (the built-in +inference_admin+ and +inference_user+ roles grant this privilege). You must use a client that supports streaming. + # + # @option arguments [String] :inference_id The unique identifier for the inference endpoint. (*Required*) + # @option arguments [Hash] :headers Custom HTTP headers + # @option arguments [Hash] :body request body + # + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-stream-inference + # + def stream_completion(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.stream_completion' } + + defined_params = [:inference_id].inject({}) do |set_variables, variable| + set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables + end + request_opts[:defined_params] = defined_params unless defined_params.empty? + + raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + body = arguments.delete(:body) + + _inference_id = arguments.delete(:inference_id) + + method = Elasticsearch::API::HTTP_POST + path = "_inference/completion/#{Utils.__listify(_inference_id)}/_stream" + params = {} + + Elasticsearch::API::Response.new( + perform_request(method, path, params, body, headers, request_opts) + ) + end + end + end + end +end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/text_embedding.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/text_embedding.rb new file mode 100644 index 0000000000..6ad374db68 --- /dev/null +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/text_embedding.rb @@ -0,0 +1,63 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification +# +module Elasticsearch + module API + module Inference + module Actions + # Perform text embedding inference on the service + # + # @option arguments [String] :inference_id The inference Id (*Required*) + # @option arguments [Time] :timeout Specifies the amount of time to wait for the inference request to complete. Server default: 30s. + # @option arguments [Hash] :headers Custom HTTP headers + # @option arguments [Hash] :body request body + # + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-inference + # + def text_embedding(arguments = {}) + request_opts = { endpoint: arguments[:endpoint] || 'inference.text_embedding' } + + defined_params = [:inference_id].inject({}) do |set_variables, variable| + set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables + end + request_opts[:defined_params] = defined_params unless defined_params.empty? + + raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id] + + arguments = arguments.clone + headers = arguments.delete(:headers) || {} + + body = arguments.delete(:body) + + _inference_id = arguments.delete(:inference_id) + + method = Elasticsearch::API::HTTP_POST + path = "_inference/text_embedding/#{Utils.__listify(_inference_id)}" + params = Utils.process_params(arguments) + + Elasticsearch::API::Response.new( + perform_request(method, path, params, body, headers, request_opts) + ) + end + end + end + end +end diff --git a/elasticsearch-api/lib/elasticsearch/api/actions/inference/update.rb b/elasticsearch-api/lib/elasticsearch/api/actions/inference/update.rb index 00bb270ee5..19b82dedbb 100644 --- a/elasticsearch-api/lib/elasticsearch/api/actions/inference/update.rb +++ b/elasticsearch-api/lib/elasticsearch/api/actions/inference/update.rb @@ -15,30 +15,36 @@ # specific language governing permissions and limitations # under the License. # -# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80 -# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec +# Auto generated from commit f284cc16f4d4b4289bc679aa1529bb504190fe80 +# @see https://github.com/elastic/elasticsearch-specification # module Elasticsearch module API module Inference module Actions - # Update inference + # 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. # - # @option arguments [String] :inference_id The inference Id - # @option arguments [String] :task_type The task type + # @option arguments [String] :inference_id The unique identifier of the inference endpoint. (*Required*) + # @option arguments [String] :task_type The type of inference task that the model performs. # @option arguments [Hash] :headers Custom HTTP headers - # @option arguments [Hash] :body The inference endpoint's task and service settings + # @option arguments [Hash] :body inference_config # - # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/update-inference-api.html + # @see https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-update # def update(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.update' } - defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables| + defined_params = [:inference_id, :task_type].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) + set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? + raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id] arguments = arguments.clone diff --git a/elasticsearch-api/spec/unit/actions/inference/unified_inference_spec.rb b/elasticsearch-api/spec/unit/actions/inference/chat_completion_unified_spec.rb similarity index 73% rename from elasticsearch-api/spec/unit/actions/inference/unified_inference_spec.rb rename to elasticsearch-api/spec/unit/actions/inference/chat_completion_unified_spec.rb index daed8332d7..6abc29076e 100644 --- a/elasticsearch-api/spec/unit/actions/inference/unified_inference_spec.rb +++ b/elasticsearch-api/spec/unit/actions/inference/chat_completion_unified_spec.rb @@ -17,20 +17,20 @@ require 'spec_helper' -describe 'client#inference.unified_inference' do +describe 'client#inference.chat_completion_unified' do let(:expected_args) do [ 'POST', - '_inference/foo/bar/_unified', + '_inference/chat_completion/bar/_stream', {}, nil, {}, - { defined_params: { inference_id: 'bar', task_type: 'foo' }, - endpoint: 'inference.unified_inference' } + { defined_params: { inference_id: 'bar' }, + endpoint: 'inference.chat_completion_unified' } ] end it 'performs the request' do - expect(client_double.inference.unified_inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response + expect(client_double.inference.chat_completion_unified(inference_id: 'bar')).to be_a Elasticsearch::API::Response end end diff --git a/elasticsearch-api/spec/unit/actions/inference/inference_spec.rb b/elasticsearch-api/spec/unit/actions/inference/completion_spec.rb similarity index 75% rename from elasticsearch-api/spec/unit/actions/inference/inference_spec.rb rename to elasticsearch-api/spec/unit/actions/inference/completion_spec.rb index c87efa07b4..8817e72a32 100644 --- a/elasticsearch-api/spec/unit/actions/inference/inference_spec.rb +++ b/elasticsearch-api/spec/unit/actions/inference/completion_spec.rb @@ -17,20 +17,20 @@ require 'spec_helper' -describe 'client#inference.inference' do +describe 'client#inference.completion' do let(:expected_args) do [ 'POST', - '_inference/foo/bar', + '_inference/completion/bar', {}, nil, {}, - { defined_params: { inference_id: 'bar', task_type: 'foo' }, - endpoint: 'inference.inference' } + { defined_params: { inference_id: 'bar' }, + endpoint: 'inference.completion' } ] end it 'performs the request' do - expect(client_double.inference.inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response + expect(client_double.inference.completion(inference_id: 'bar')).to be_a Elasticsearch::API::Response end end diff --git a/elasticsearch-api/spec/unit/actions/inference/put_spec.rb b/elasticsearch-api/spec/unit/actions/inference/put_spec.rb index e06f205437..bdd6393727 100644 --- a/elasticsearch-api/spec/unit/actions/inference/put_spec.rb +++ b/elasticsearch-api/spec/unit/actions/inference/put_spec.rb @@ -21,16 +21,16 @@ let(:expected_args) do [ 'PUT', - '_inference/foo/bar', + '_inference/bar', {}, - nil, {}, - { defined_params: { inference_id: 'bar', task_type: 'foo' }, + {}, + { defined_params: { inference_id: 'bar' }, endpoint: 'inference.put' } ] end it 'performs the request' do - expect(client_double.inference.put(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response + expect(client_double.inference.put(body: {}, inference_id: 'bar')).to be_a Elasticsearch::API::Response end end diff --git a/elasticsearch-api/spec/unit/actions/inference/put_watsonx_spec.rb b/elasticsearch-api/spec/unit/actions/inference/put_watsonx_spec.rb new file mode 100644 index 0000000000..44245b8b02 --- /dev/null +++ b/elasticsearch-api/spec/unit/actions/inference/put_watsonx_spec.rb @@ -0,0 +1,36 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require 'spec_helper' + +describe 'client#inference.put_watsonx' do + let(:expected_args) do + [ + 'PUT', + '_inference/foo/bar', + {}, + nil, + {}, + { defined_params: { watsonx_inference_id: 'bar', task_type: 'foo' }, + endpoint: 'inference.put_watsonx' } + ] + end + + it 'performs the request' do + expect(client_double.inference.put_watsonx(task_type: 'foo', watsonx_inference_id: 'bar')).to be_a Elasticsearch::API::Response + end +end diff --git a/elasticsearch-api/spec/unit/actions/inference/rerank_spec.rb b/elasticsearch-api/spec/unit/actions/inference/rerank_spec.rb new file mode 100644 index 0000000000..7417cd74fa --- /dev/null +++ b/elasticsearch-api/spec/unit/actions/inference/rerank_spec.rb @@ -0,0 +1,35 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require 'spec_helper' + +describe 'client#inference.rerank' do + let(:expected_args) do + [ + 'POST', + '_inference/rerank/foo', + {}, + nil, + {}, + { defined_params: { inference_id: 'foo' }, endpoint: 'inference.rerank' } + ] + end + + it 'performs the request' do + expect(client_double.inference.rerank(inference_id: 'foo')).to be_a Elasticsearch::API::Response + end +end diff --git a/elasticsearch-api/spec/unit/actions/inference/stream_inference_spec.rb b/elasticsearch-api/spec/unit/actions/inference/sparse_embedding_spec.rb similarity index 85% rename from elasticsearch-api/spec/unit/actions/inference/stream_inference_spec.rb rename to elasticsearch-api/spec/unit/actions/inference/sparse_embedding_spec.rb index 191ad643d5..856dface5a 100644 --- a/elasticsearch-api/spec/unit/actions/inference/stream_inference_spec.rb +++ b/elasticsearch-api/spec/unit/actions/inference/sparse_embedding_spec.rb @@ -17,19 +17,19 @@ require 'spec_helper' -describe 'client#inference.stream_inference' do +describe 'client#inference.sparse_embedding' do let(:expected_args) do [ 'POST', - '_inference/foo/_stream', + '_inference/sparse_embedding/foo', {}, nil, {}, - { defined_params: { inference_id: 'foo' }, endpoint: 'inference.stream_inference' } + { defined_params: { inference_id: 'foo' }, endpoint: 'inference.sparse_embedding' } ] end it 'performs the request' do - expect(client_double.inference.stream_inference(inference_id: 'foo')).to be_a Elasticsearch::API::Response + expect(client_double.inference.sparse_embedding(inference_id: 'foo')).to be_a Elasticsearch::API::Response end end diff --git a/elasticsearch-api/spec/unit/actions/inference/stream_completion_spec.rb b/elasticsearch-api/spec/unit/actions/inference/stream_completion_spec.rb new file mode 100644 index 0000000000..542b1d9941 --- /dev/null +++ b/elasticsearch-api/spec/unit/actions/inference/stream_completion_spec.rb @@ -0,0 +1,35 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require 'spec_helper' + +describe 'client#inference.stream_completion' do + let(:expected_args) do + [ + 'POST', + '_inference/completion/foo/_stream', + {}, + nil, + {}, + { defined_params: { inference_id: 'foo' }, endpoint: 'inference.stream_completion' } + ] + end + + it 'performs the request' do + expect(client_double.inference.stream_completion(inference_id: 'foo')).to be_a Elasticsearch::API::Response + end +end diff --git a/elasticsearch-api/spec/unit/actions/inference/text_embedding_spec.rb b/elasticsearch-api/spec/unit/actions/inference/text_embedding_spec.rb new file mode 100644 index 0000000000..e97fda5865 --- /dev/null +++ b/elasticsearch-api/spec/unit/actions/inference/text_embedding_spec.rb @@ -0,0 +1,35 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +require 'spec_helper' + +describe 'client#inference.text_embedding' do + let(:expected_args) do + [ + 'POST', + '_inference/text_embedding/foo', + {}, + nil, + {}, + { defined_params: { inference_id: 'foo' }, endpoint: 'inference.text_embedding' } + ] + end + + it 'performs the request' do + expect(client_double.inference.text_embedding(inference_id: 'foo')).to be_a Elasticsearch::API::Response + end +end diff --git a/elasticsearch-api/spec/unit/actions/inference/update_spec.rb b/elasticsearch-api/spec/unit/actions/inference/update_spec.rb index 6f29cd0b58..0ee998ee5b 100644 --- a/elasticsearch-api/spec/unit/actions/inference/update_spec.rb +++ b/elasticsearch-api/spec/unit/actions/inference/update_spec.rb @@ -23,7 +23,7 @@ 'PUT', '_inference/foo/bar/_update', {}, - nil, + {}, {}, { defined_params: { inference_id: 'bar', task_type: 'foo' }, endpoint: 'inference.update' } @@ -31,6 +31,6 @@ end it 'performs the request' do - expect(client_double.inference.update(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response + expect(client_double.inference.update(task_type: 'foo', body: {}, inference_id: 'bar')).to be_a Elasticsearch::API::Response end end diff --git a/elasticsearch-api/spec/unit/perform_request_spec.rb b/elasticsearch-api/spec/unit/perform_request_spec.rb index 154e19bd90..6fb47ae02a 100644 --- a/elasticsearch-api/spec/unit/perform_request_spec.rb +++ b/elasticsearch-api/spec/unit/perform_request_spec.rb @@ -35,6 +35,8 @@ params.merge(part.to_sym => 'testing') end + required_params.merge!(body: {}) if ['inference.put', 'inference.update'].include? spec.endpoint_name + let(:client_double) do Class.new { include Elasticsearch::API }.new.tap do |client| expect(client).to receive(:perform_request) do |_, _, _, _, _, request_params| diff --git a/elasticsearch-api/spec/yaml-test-runner/run.rb b/elasticsearch-api/spec/yaml-test-runner/run.rb index 701d26b801..9d39880517 100644 --- a/elasticsearch-api/spec/yaml-test-runner/run.rb +++ b/elasticsearch-api/spec/yaml-test-runner/run.rb @@ -86,4 +86,5 @@ def serverless? runner = Elasticsearch::Tests::TestRunner.new(CLIENT, tests_path, logger) runner.add_tests_to_skip('knn_search.yml') # TODO: Extract into file +runner.add_tests_to_skip('inference/10_basic.yml') runner.run(ENV['SINGLE_TEST'] || [])