Module: ElasticsearchServerless::API::Inference::Actions
- Defined in:
- lib/elasticsearch-serverless/api/inference/get.rb,
lib/elasticsearch-serverless/api/inference/put.rb,
lib/elasticsearch-serverless/api/inference/delete.rb,
lib/elasticsearch-serverless/api/inference/rerank.rb,
lib/elasticsearch-serverless/api/inference/inference.rb,
lib/elasticsearch-serverless/api/inference/completion.rb,
lib/elasticsearch-serverless/api/inference/put_watsonx.rb,
lib/elasticsearch-serverless/api/inference/text_embedding.rb,
lib/elasticsearch-serverless/api/inference/sparse_embedding.rb,
lib/elasticsearch-serverless/api/inference/chat_completion_unified.rb
Instance Method Summary collapse
-
#chat_completion_unified(arguments = {}) ⇒ Object
Perform chat completion inference.
-
#completion(arguments = {}) ⇒ Object
Perform completion inference on the service.
-
#delete(arguments = {}) ⇒ Object
Delete an inference endpoint.
-
#get(arguments = {}) ⇒ Object
Get an inference endpoint.
-
#inference(arguments = {}) ⇒ Object
Perform inference on the service.
-
#put(arguments = {}) ⇒ Object
Create an inference endpoint.
-
#put_watsonx(arguments = {}) ⇒ Object
Create a Watsonx inference endpoint.
-
#rerank(arguments = {}) ⇒ Object
Perform rereanking inference on the service.
-
#sparse_embedding(arguments = {}) ⇒ Object
Perform sparse embedding inference on the service.
-
#text_embedding(arguments = {}) ⇒ Object
Perform text embedding inference on the service.
Instance Method Details
#chat_completion_unified(arguments = {}) ⇒ Object
Perform chat completion inference
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elasticsearch-serverless/api/inference/chat_completion_unified.rb', line 34 def chat_completion_unified(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.chat_completion_unified' } defined_params = [:inference_id].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 = ElasticsearchServerless::API::HTTP_POST path = "_inference/chat_completion/#{Utils.listify(_inference_id)}/_stream" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#completion(arguments = {}) ⇒ Object
Perform completion inference on the service
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elasticsearch-serverless/api/inference/completion.rb', line 34 def completion(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.completion' } defined_params = [:inference_id].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 = ElasticsearchServerless::API::HTTP_POST path = "_inference/completion/#{Utils.listify(_inference_id)}" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#delete(arguments = {}) ⇒ Object
Delete an inference endpoint
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/elasticsearch-serverless/api/inference/delete.rb', line 35 def delete(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.delete' } defined_params = [:inference_id, :task_type].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 = nil _task_type = arguments.delete(:task_type) _inference_id = arguments.delete(:inference_id) method = ElasticsearchServerless::API::HTTP_DELETE path = if _task_type && _inference_id "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_inference_id)}" else "_inference/#{Utils.listify(_inference_id)}" end params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#get(arguments = {}) ⇒ Object
Get an inference endpoint
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/elasticsearch-serverless/api/inference/get.rb', line 33 def get(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.get' } defined_params = [:inference_id, :task_type].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) end request_opts[:defined_params] = defined_params unless defined_params.empty? arguments = arguments.clone headers = arguments.delete(:headers) || {} body = nil _task_type = arguments.delete(:task_type) _inference_id = arguments.delete(:inference_id) method = ElasticsearchServerless::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' end params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#inference(arguments = {}) ⇒ Object
Perform inference on the service
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/elasticsearch-serverless/api/inference/inference.rb', line 35 def inference(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "inference.inference" } 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 'inference_id' missing" unless arguments[:inference_id] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) _task_type = arguments.delete(:task_type) _inference_id = arguments.delete(:inference_id) method = ElasticsearchServerless::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 = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#put(arguments = {}) ⇒ Object
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.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/elasticsearch-serverless/api/inference/put.rb', line 42 def put(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.put' } defined_params = [:inference_id, :task_type].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 headers = arguments.delete(:headers) || {} body = arguments.delete(:body) _task_type = arguments.delete(:task_type) _inference_id = arguments.delete(:inference_id) method = ElasticsearchServerless::API::HTTP_PUT path = if _task_type && _inference_id "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_inference_id)}" else "_inference/#{Utils.listify(_inference_id)}" end params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#put_watsonx(arguments = {}) ⇒ Object
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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/elasticsearch-serverless/api/inference/put_watsonx.rb', line 43 def put_watsonx(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.put_watsonx' } defined_params = [:task_type, :watsonx_inference_id].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) end request_opts[:defined_params] = defined_params unless defined_params.empty? raise ArgumentError, "Required argument 'task_type' missing" unless arguments[:task_type] unless arguments[:watsonx_inference_id] raise ArgumentError, "Required argument 'watsonx_inference_id' missing" end 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 = ElasticsearchServerless::API::HTTP_PUT path = "_inference/#{Utils.listify(_task_type)}/#{Utils.listify(_watsonx_inference_id)}" params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#rerank(arguments = {}) ⇒ Object
Perform rereanking inference on the service
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elasticsearch-serverless/api/inference/rerank.rb', line 34 def rerank(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.rerank' } defined_params = [:inference_id].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 = ElasticsearchServerless::API::HTTP_POST path = "_inference/rerank/#{Utils.listify(_inference_id)}" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#sparse_embedding(arguments = {}) ⇒ Object
Perform sparse embedding inference on the service
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elasticsearch-serverless/api/inference/sparse_embedding.rb', line 34 def (arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.sparse_embedding' } defined_params = [:inference_id].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 = ElasticsearchServerless::API::HTTP_POST path = "_inference/sparse_embedding/#{Utils.listify(_inference_id)}" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#text_embedding(arguments = {}) ⇒ Object
Perform text embedding inference on the service
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elasticsearch-serverless/api/inference/text_embedding.rb', line 34 def (arguments = {}) request_opts = { endpoint: arguments[:endpoint] || 'inference.text_embedding' } defined_params = [:inference_id].each_with_object({}) do |variable, set_variables| set_variables[variable] = arguments[variable] if arguments.key?(variable) 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 = ElasticsearchServerless::API::HTTP_POST path = "_inference/text_embedding/#{Utils.listify(_inference_id)}" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |