Skip to content

Commit 8a169d1

Browse files
[API] Adds semantic_search endpoint
Co-authored-by: Fernando Briano <[email protected]>
1 parent 89a000d commit 8a169d1

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 Actions
24+
# Semantic search API using dense vector similarity
25+
# This functionality is Experimental and may be changed or removed
26+
# completely in a future release. Elastic will take a best effort approach
27+
# to fix any issues, but experimental features are not subject to the
28+
# support SLA of official GA features.
29+
#
30+
# @option arguments [List] :index A comma-separated list of index names to search; use `_all` to perform the operation on all indices
31+
# @option arguments [List] :routing A comma-separated list of specific routing values
32+
# @option arguments [Hash] :headers Custom HTTP headers
33+
# @option arguments [Hash] :body The search definition
34+
#
35+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/current/semantic-search.html
36+
#
37+
def semantic_search(arguments = {})
38+
raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
39+
40+
arguments = arguments.clone
41+
headers = arguments.delete(:headers) || {}
42+
43+
body = arguments.delete(:body)
44+
45+
_index = arguments.delete(:index)
46+
47+
method = if body
48+
Elasticsearch::API::HTTP_POST
49+
else
50+
Elasticsearch::API::HTTP_GET
51+
end
52+
53+
path = "#{Utils.__listify(_index)}/_semantic_search"
54+
params = Utils.process_params(arguments)
55+
56+
Elasticsearch::API::Response.new(
57+
perform_request(method, path, params, body, headers)
58+
)
59+
end
60+
end
61+
end
62+
end
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
require 'spec_helper'
19+
20+
describe 'client#semantic_search' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'foo/_semantic_search',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
it 'performs the request' do
32+
response = client_double.semantic_search(index: 'foo')
33+
expect(response).to be_a Elasticsearch::API::Response
34+
expect(response.status).to eq 200
35+
end
36+
37+
context 'when body is provided' do
38+
let(:expected_args) do
39+
[
40+
'POST',
41+
'foo/_semantic_search',
42+
{},
43+
{},
44+
{}
45+
]
46+
end
47+
48+
it 'performs the request' do
49+
response = client_double.semantic_search(index: 'foo', body: {})
50+
expect(response).to be_a Elasticsearch::API::Response
51+
expect(response.status).to eq 200
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)