Skip to content

Commit b149728

Browse files
committed
[API] Updates inference APIs
* Promotes inference delete, get and put from experimental to stable * Removes inference.unified_inference * Adds inference.chat_completion_unified * Removes inference.inference * Adds inference.completion * Removes inference.stream_inference * Adds inference.stream_completion * Adds inference.rerank * Adds inference.sparse_embedding * Adds inference.text_embedding
1 parent 31210b6 commit b149728

15 files changed

+318
-71
lines changed

elasticsearch-api/lib/elasticsearch/api/actions/inference/unified_inference.rb renamed to elasticsearch-api/lib/elasticsearch/api/actions/inference/chat_completion_unified.rb

+6-13
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ module Elasticsearch
2222
module API
2323
module Inference
2424
module Actions
25-
# Perform inference using the Unified Schema
25+
# Perform chat completion inference
2626
#
2727
# @option arguments [String] :inference_id The inference Id
28-
# @option arguments [String] :task_type The task type
2928
# @option arguments [Hash] :headers Custom HTTP headers
3029
# @option arguments [Hash] :body The inference payload
3130
#
32-
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/unified-inference-api.html
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/chat-completion-inference.html
3332
#
34-
def unified_inference(arguments = {})
35-
request_opts = { endpoint: arguments[:endpoint] || 'inference.unified_inference' }
33+
def chat_completion_unified(arguments = {})
34+
request_opts = { endpoint: arguments[:endpoint] || 'inference.chat_completion_unified' }
3635

37-
defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
36+
defined_params = [:inference_id].each_with_object({}) do |variable, set_variables|
3837
set_variables[variable] = arguments[variable] if arguments.key?(variable)
3938
end
4039
request_opts[:defined_params] = defined_params unless defined_params.empty?
@@ -48,14 +47,8 @@ def unified_inference(arguments = {})
4847

4948
_inference_id = arguments.delete(:inference_id)
5049

51-
_task_type = arguments.delete(:task_type)
52-
5350
method = Elasticsearch::API::HTTP_POST
54-
path = if _task_type && _inference_id
55-
"_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_unified"
56-
else
57-
"_inference/#{Utils.__listify(_inference_id)}/_unified"
58-
end
51+
path = "_inference/chat_completion/#{Utils.__listify(_inference_id)}/_stream"
5952
params = {}
6053

6154
Elasticsearch::API::Response.new(

elasticsearch-api/lib/elasticsearch/api/actions/inference/inference.rb renamed to elasticsearch-api/lib/elasticsearch/api/actions/inference/completion.rb

+5-16
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,18 @@ module Elasticsearch
2222
module API
2323
module Inference
2424
module Actions
25-
# Perform inference
26-
# This functionality is Experimental and may be changed or removed
27-
# completely in a future release. Elastic will take a best effort approach
28-
# to fix any issues, but experimental features are not subject to the
29-
# support SLA of official GA features.
25+
# Perform completion inference
3026
#
3127
# @option arguments [String] :inference_id The inference Id
32-
# @option arguments [String] :task_type The task type
3328
# @option arguments [Hash] :headers Custom HTTP headers
3429
# @option arguments [Hash] :body The inference payload
3530
#
3631
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
3732
#
38-
def inference(arguments = {})
39-
request_opts = { endpoint: arguments[:endpoint] || 'inference.inference' }
33+
def completion(arguments = {})
34+
request_opts = { endpoint: arguments[:endpoint] || 'inference.completion' }
4035

41-
defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
36+
defined_params = [:inference_id].each_with_object({}) do |variable, set_variables|
4237
set_variables[variable] = arguments[variable] if arguments.key?(variable)
4338
end
4439
request_opts[:defined_params] = defined_params unless defined_params.empty?
@@ -52,14 +47,8 @@ def inference(arguments = {})
5247

5348
_inference_id = arguments.delete(:inference_id)
5449

55-
_task_type = arguments.delete(:task_type)
56-
5750
method = Elasticsearch::API::HTTP_POST
58-
path = if _task_type && _inference_id
59-
"_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}"
60-
else
61-
"_inference/#{Utils.__listify(_inference_id)}"
62-
end
51+
path = "_inference/completion/#{Utils.__listify(_inference_id)}"
6352
params = {}
6453

6554
Elasticsearch::API::Response.new(

elasticsearch-api/lib/elasticsearch/api/actions/inference/delete.rb

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ module API
2323
module Inference
2424
module Actions
2525
# Delete an inference endpoint
26-
# This functionality is Experimental and may be changed or removed
27-
# completely in a future release. Elastic will take a best effort approach
28-
# to fix any issues, but experimental features are not subject to the
29-
# support SLA of official GA features.
3026
#
3127
# @option arguments [String] :inference_id The inference Id
3228
# @option arguments [String] :task_type The task type

elasticsearch-api/lib/elasticsearch/api/actions/inference/get.rb

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ module API
2323
module Inference
2424
module Actions
2525
# Get an inference endpoint
26-
# This functionality is Experimental and may be changed or removed
27-
# completely in a future release. Elastic will take a best effort approach
28-
# to fix any issues, but experimental features are not subject to the
29-
# support SLA of official GA features.
3026
#
3127
# @option arguments [String] :inference_id The inference Id
3228
# @option arguments [String] :task_type The task type

elasticsearch-api/lib/elasticsearch/api/actions/inference/put.rb

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ module API
2323
module Inference
2424
module Actions
2525
# Configure an inference endpoint for use in the Inference API
26-
# This functionality is Experimental and may be changed or removed
27-
# completely in a future release. Elastic will take a best effort approach
28-
# to fix any issues, but experimental features are not subject to the
29-
# support SLA of official GA features.
3026
#
3127
# @option arguments [String] :inference_id The inference Id
3228
# @option arguments [String] :task_type The task type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
19+
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
20+
#
21+
module Elasticsearch
22+
module API
23+
module Inference
24+
module Actions
25+
# Perform reranking inference
26+
#
27+
# @option arguments [String] :inference_id The inference Id
28+
# @option arguments [Hash] :headers Custom HTTP headers
29+
# @option arguments [Hash] :body The inference payload
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
32+
#
33+
def rerank(arguments = {})
34+
request_opts = { endpoint: arguments[:endpoint] || 'inference.rerank' }
35+
36+
defined_params = [:inference_id].each_with_object({}) do |variable, set_variables|
37+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
38+
end
39+
request_opts[:defined_params] = defined_params unless defined_params.empty?
40+
41+
raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id]
42+
43+
arguments = arguments.clone
44+
headers = arguments.delete(:headers) || {}
45+
46+
body = arguments.delete(:body)
47+
48+
_inference_id = arguments.delete(:inference_id)
49+
50+
method = Elasticsearch::API::HTTP_POST
51+
path = "_inference/rerank/#{Utils.__listify(_inference_id)}"
52+
params = {}
53+
54+
Elasticsearch::API::Response.new(
55+
perform_request(method, path, params, body, headers, request_opts)
56+
)
57+
end
58+
end
59+
end
60+
end
61+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
19+
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
20+
#
21+
module Elasticsearch
22+
module API
23+
module Inference
24+
module Actions
25+
# Perform sparse embedding inference
26+
#
27+
# @option arguments [String] :inference_id The inference Id
28+
# @option arguments [Hash] :headers Custom HTTP headers
29+
# @option arguments [Hash] :body The inference payload
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
32+
#
33+
def sparse_embedding(arguments = {})
34+
request_opts = { endpoint: arguments[:endpoint] || 'inference.sparse_embedding' }
35+
36+
defined_params = [:inference_id].each_with_object({}) do |variable, set_variables|
37+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
38+
end
39+
request_opts[:defined_params] = defined_params unless defined_params.empty?
40+
41+
raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id]
42+
43+
arguments = arguments.clone
44+
headers = arguments.delete(:headers) || {}
45+
46+
body = arguments.delete(:body)
47+
48+
_inference_id = arguments.delete(:inference_id)
49+
50+
method = Elasticsearch::API::HTTP_POST
51+
path = "_inference/sparse_embedding/#{Utils.__listify(_inference_id)}"
52+
params = {}
53+
54+
Elasticsearch::API::Response.new(
55+
perform_request(method, path, params, body, headers, request_opts)
56+
)
57+
end
58+
end
59+
end
60+
end
61+
end

elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_inference.rb renamed to elasticsearch-api/lib/elasticsearch/api/actions/inference/stream_completion.rb

+5-16
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,18 @@ module Elasticsearch
2222
module API
2323
module Inference
2424
module Actions
25-
# Perform streaming inference
26-
# This functionality is Experimental and may be changed or removed
27-
# completely in a future release. Elastic will take a best effort approach
28-
# to fix any issues, but experimental features are not subject to the
29-
# support SLA of official GA features.
25+
# Perform streaming completion inference
3026
#
3127
# @option arguments [String] :inference_id The inference Id
32-
# @option arguments [String] :task_type The task type
3328
# @option arguments [Hash] :headers Custom HTTP headers
3429
# @option arguments [Hash] :body The inference payload
3530
#
3631
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-stream-inference-api.html
3732
#
38-
def stream_inference(arguments = {})
39-
request_opts = { endpoint: arguments[:endpoint] || 'inference.stream_inference' }
33+
def stream_completion(arguments = {})
34+
request_opts = { endpoint: arguments[:endpoint] || 'inference.stream_completion' }
4035

41-
defined_params = %i[inference_id task_type].each_with_object({}) do |variable, set_variables|
36+
defined_params = [:inference_id].each_with_object({}) do |variable, set_variables|
4237
set_variables[variable] = arguments[variable] if arguments.key?(variable)
4338
end
4439
request_opts[:defined_params] = defined_params unless defined_params.empty?
@@ -52,14 +47,8 @@ def stream_inference(arguments = {})
5247

5348
_inference_id = arguments.delete(:inference_id)
5449

55-
_task_type = arguments.delete(:task_type)
56-
5750
method = Elasticsearch::API::HTTP_POST
58-
path = if _task_type && _inference_id
59-
"_inference/#{Utils.__listify(_task_type)}/#{Utils.__listify(_inference_id)}/_stream"
60-
else
61-
"_inference/#{Utils.__listify(_inference_id)}/_stream"
62-
end
51+
path = "_inference/completion/#{Utils.__listify(_inference_id)}/_stream"
6352
params = {}
6453

6554
Elasticsearch::API::Response.new(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Auto generated from build hash f284cc16f4d4b4289bc679aa1529bb504190fe80
19+
# @see https://github.com/elastic/elasticsearch/tree/main/rest-api-spec
20+
#
21+
module Elasticsearch
22+
module API
23+
module Inference
24+
module Actions
25+
# Perform text embedding inference
26+
#
27+
# @option arguments [String] :inference_id The inference Id
28+
# @option arguments [Hash] :headers Custom HTTP headers
29+
# @option arguments [Hash] :body The inference payload
30+
#
31+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/8.17/post-inference-api.html
32+
#
33+
def text_embedding(arguments = {})
34+
request_opts = { endpoint: arguments[:endpoint] || 'inference.text_embedding' }
35+
36+
defined_params = [:inference_id].each_with_object({}) do |variable, set_variables|
37+
set_variables[variable] = arguments[variable] if arguments.key?(variable)
38+
end
39+
request_opts[:defined_params] = defined_params unless defined_params.empty?
40+
41+
raise ArgumentError, "Required argument 'inference_id' missing" unless arguments[:inference_id]
42+
43+
arguments = arguments.clone
44+
headers = arguments.delete(:headers) || {}
45+
46+
body = arguments.delete(:body)
47+
48+
_inference_id = arguments.delete(:inference_id)
49+
50+
method = Elasticsearch::API::HTTP_POST
51+
path = "_inference/text_embedding/#{Utils.__listify(_inference_id)}"
52+
params = {}
53+
54+
Elasticsearch::API::Response.new(
55+
perform_request(method, path, params, body, headers, request_opts)
56+
)
57+
end
58+
end
59+
end
60+
end
61+
end

elasticsearch-api/spec/elasticsearch/api/actions/inference/unified_inference_spec.rb renamed to elasticsearch-api/spec/elasticsearch/api/actions/inference/chat_completion_unified_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
require 'spec_helper'
1919

20-
describe 'client#inference.unified_inference' do
20+
describe 'client#inference.chat_completion_unified' do
2121
let(:expected_args) do
2222
[
2323
'POST',
24-
'_inference/foo/bar/_unified',
24+
'_inference/chat_completion/bar/_stream',
2525
{},
2626
nil,
2727
{},
28-
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
29-
endpoint: 'inference.unified_inference' }
28+
{ defined_params: { inference_id: 'bar' },
29+
endpoint: 'inference.chat_completion_unified' }
3030
]
3131
end
3232

3333
it 'performs the request' do
34-
expect(client_double.inference.unified_inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
34+
expect(client_double.inference.chat_completion_unified(inference_id: 'bar')).to be_a Elasticsearch::API::Response
3535
end
3636
end

elasticsearch-api/spec/elasticsearch/api/actions/inference/inference_spec.rb renamed to elasticsearch-api/spec/elasticsearch/api/actions/inference/completion_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717

1818
require 'spec_helper'
1919

20-
describe 'client#inference.inference' do
20+
describe 'client#inference.completion' do
2121
let(:expected_args) do
2222
[
2323
'POST',
24-
'_inference/foo/bar',
24+
'_inference/completion/bar',
2525
{},
2626
nil,
2727
{},
28-
{ defined_params: { inference_id: 'bar', task_type: 'foo' },
29-
endpoint: 'inference.inference' }
28+
{ defined_params: { inference_id: 'bar' },
29+
endpoint: 'inference.completion' }
3030
]
3131
end
3232

3333
it 'performs the request' do
34-
expect(client_double.inference.inference(task_type: 'foo', inference_id: 'bar')).to be_a Elasticsearch::API::Response
34+
expect(client_double.inference.completion(inference_id: 'bar')).to be_a Elasticsearch::API::Response
3535
end
3636
end

0 commit comments

Comments
 (0)