stretchy-model 0.6.6 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/_sidebar.md +2 -1
- data/docs/examples/_sidebar.md +1 -1
- data/docs/examples/neural_search_with_llm.md +381 -0
- data/docs/guides/_sidebar.md +2 -1
- data/lib/elasticsearch/api/actions/connector/check_in.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/delete.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/get.rb +64 -0
- data/lib/elasticsearch/api/actions/connector/last_sync.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/list.rb +60 -0
- data/lib/elasticsearch/api/actions/connector/post.rb +57 -0
- data/lib/elasticsearch/api/actions/connector/put.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_api_key_id.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_configuration.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_error.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_filtering.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_index_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_name.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_native.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_pipeline.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_scheduling.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_service_type.rb +66 -0
- data/lib/elasticsearch/api/actions/connector/update_status.rb +66 -0
- data/lib/elasticsearch/api/namespace/connector.rb +36 -0
- data/lib/opensearch/api/actions/machine_learning/connector/delete.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/get.rb +42 -0
- data/lib/opensearch/api/actions/machine_learning/connector/list.rb +38 -0
- data/lib/opensearch/api/actions/machine_learning/connector/post.rb +35 -0
- data/lib/opensearch/api/actions/machine_learning/connector/put.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/predict.rb +32 -0
- data/lib/opensearch/api/namespace/connector.rb +19 -0
- data/lib/stretchy/machine_learning/connector.rb +130 -0
- data/lib/stretchy/machine_learning/errors.rb +25 -0
- data/lib/stretchy/machine_learning/model.rb +162 -109
- data/lib/stretchy/machine_learning/registry.rb +19 -0
- data/lib/stretchy/open_search_compatibility.rb +2 -0
- data/lib/stretchy/pipelines/processor.rb +2 -0
- data/lib/stretchy/rails/railtie.rb +11 -0
- data/lib/stretchy/rails/tasks/connector/create.rake +32 -0
- data/lib/stretchy/rails/tasks/connector/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/connector/status.rake +31 -0
- data/lib/stretchy/rails/tasks/connector/update.rake +32 -0
- data/lib/stretchy/rails/tasks/index/create.rake +28 -0
- data/lib/stretchy/rails/tasks/index/delete.rake +27 -0
- data/lib/stretchy/rails/tasks/index/status.rake +23 -0
- data/lib/stretchy/rails/tasks/ml/delete.rake +25 -0
- data/lib/stretchy/rails/tasks/ml/deploy.rake +78 -0
- data/lib/stretchy/rails/tasks/ml/status.rake +31 -0
- data/lib/stretchy/rails/tasks/pipeline/create.rake +27 -0
- data/lib/stretchy/rails/tasks/pipeline/delete.rake +26 -0
- data/lib/stretchy/rails/tasks/pipeline/status.rake +25 -0
- data/lib/stretchy/rails/tasks/status.rake +15 -0
- data/lib/stretchy/rails/tasks/stretchy.rake +42 -0
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +7 -0
- metadata +62 -3
- data/docs/examples/semantic_search_with_llm.md +0 -83
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :index do
|
3
|
+
desc "Check the status of all indexes"
|
4
|
+
task status: :environment do
|
5
|
+
klass = ENV['MODEL']
|
6
|
+
|
7
|
+
Rails.application.eager_load!
|
8
|
+
models = klass.nil? ? StretchyModel.descendants : [klass.constantize]
|
9
|
+
|
10
|
+
puts Rainbow("Indexes").color :gray
|
11
|
+
models.each do |model|
|
12
|
+
response = model.index_exists?
|
13
|
+
status = if response
|
14
|
+
Rainbow("[CREATED]").green.bright
|
15
|
+
else
|
16
|
+
Rainbow("[MISSING]").white
|
17
|
+
end
|
18
|
+
puts "#{model.index_name}".ljust(JUSTIFICATION) + status
|
19
|
+
end
|
20
|
+
puts "\n\n"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :ml do
|
3
|
+
|
4
|
+
desc "Delete the model ENV['MODEL']"
|
5
|
+
task delete: :environment do
|
6
|
+
klass = ENV['MODEL']
|
7
|
+
Rails.application.eager_load!
|
8
|
+
models = klass.nil? ? Stretchy::MachineLearning::Model.descendants : [klass.constantize]
|
9
|
+
|
10
|
+
models.each do |model|
|
11
|
+
spinner = TTY::Spinner.new(("Deleting #{model} ".ljust(JUSTIFICATION) + ":spinner"), format: :dots)
|
12
|
+
spinner.auto_spin
|
13
|
+
unless model.registered?
|
14
|
+
spinner.stop(Rainbow("[MISSING]").white)
|
15
|
+
next
|
16
|
+
end
|
17
|
+
|
18
|
+
model.delete
|
19
|
+
|
20
|
+
status = !model.registered? ? Rainbow("[DELETED]").green : Rainbow("[NOT DELETED]").yellow
|
21
|
+
spinner.stop(status)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :ml do
|
3
|
+
|
4
|
+
desc "Register the model ENV['MODEL']"
|
5
|
+
task register: :environment do
|
6
|
+
klass = ENV['MODEL']
|
7
|
+
Rails.application.eager_load!
|
8
|
+
models = klass.nil? ? Stretchy::MachineLearning::Model.descendants : [klass.constantize]
|
9
|
+
|
10
|
+
models.each do |model|
|
11
|
+
spinner = TTY::Spinner.new(("Registering #{model} ".ljust(JUSTIFICATION) + ":spinner"), format: :dots)
|
12
|
+
spinner.auto_spin
|
13
|
+
if model.registered?
|
14
|
+
spinner.stop(Rainbow("[SUCCESS]").green)
|
15
|
+
next
|
16
|
+
end
|
17
|
+
|
18
|
+
model.register do |m|
|
19
|
+
m.wait_until_complete do
|
20
|
+
m.registered?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
status = model.registered? ? Rainbow("[SUCCESS]").green : Rainbow("[FAILED]").red
|
25
|
+
spinner.stop(status)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Undeploy the model ENV['MODEL']"
|
30
|
+
task undeploy: :environment do
|
31
|
+
klass = ENV['MODEL']
|
32
|
+
Rails.application.eager_load!
|
33
|
+
models = klass.nil? ? Stretchy::MachineLearning::Model.descendants : [klass.constantize]
|
34
|
+
models.each do |model|
|
35
|
+
spinner = TTY::Spinner.new("Undeploying #{model} ". ljust(JUSTIFICATION) + ":spinner", format: :dots)
|
36
|
+
spinner.auto_spin
|
37
|
+
|
38
|
+
unless model.deployed?
|
39
|
+
spinner.stop(Rainbow("[NOT DEPLOYED]").white)
|
40
|
+
next
|
41
|
+
end
|
42
|
+
|
43
|
+
model.undeploy do |m|
|
44
|
+
m.wait_until_complete do
|
45
|
+
!m.deployed?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
status = !model.deployed? ? Rainbow("[SUCCESS]").green : Rainbow("[DEPLOYED]").yellow
|
49
|
+
spinner.stop(status)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Deploy the model ENV['MODEL']"
|
54
|
+
task deploy: :environment do
|
55
|
+
klass = ENV['MODEL']
|
56
|
+
Rails.application.eager_load!
|
57
|
+
models = klass.nil? ? Stretchy::MachineLearning::Model.descendants : [klass.constantize]
|
58
|
+
models.each do |model|
|
59
|
+
spinner = TTY::Spinner.new("Deploying #{model} ".ljust(JUSTIFICATION) + ":spinner", format: :dots)
|
60
|
+
spinner.auto_spin
|
61
|
+
|
62
|
+
if model.deployed?
|
63
|
+
spinner.stop(Rainbow("[SUCCESS]").green)
|
64
|
+
next
|
65
|
+
end
|
66
|
+
|
67
|
+
model.deploy do |m|
|
68
|
+
m.wait_until_complete do
|
69
|
+
m.deployed?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
status = model.deployed? ? Rainbow("[SUCCESS]").green : Rainbow("[FAILED]").red
|
73
|
+
spinner.stop(status)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :ml do
|
3
|
+
|
4
|
+
desc "Check the status of all ml models"
|
5
|
+
task status: :environment do
|
6
|
+
klass = ENV['MODEL']
|
7
|
+
|
8
|
+
Rails.application.eager_load!
|
9
|
+
models = klass.nil? ? Stretchy::MachineLearning::Model.descendants : [klass.constantize]
|
10
|
+
|
11
|
+
puts Rainbow("Machine Learning").color :gray
|
12
|
+
models.each do |model|
|
13
|
+
|
14
|
+
response = model.find['model_state']
|
15
|
+
status = case response
|
16
|
+
when 'DEPLOYED'
|
17
|
+
Rainbow("[#{response}]").green.bright
|
18
|
+
when 'DEPLOY_FAILED'
|
19
|
+
Rainbow("[#{response}]").red.bright
|
20
|
+
when 'CREATED'
|
21
|
+
Rainbow("[#{response}]").yellow.bright
|
22
|
+
else
|
23
|
+
Rainbow("[MISSING]").white
|
24
|
+
end
|
25
|
+
puts "#{model}".ljust(JUSTIFICATION) + status
|
26
|
+
end
|
27
|
+
puts "\n\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :pipeline do
|
3
|
+
desc "Create pipeline"
|
4
|
+
task create: :environment do
|
5
|
+
klass = ENV['MODEL']
|
6
|
+
Rails.application.eager_load!
|
7
|
+
models = klass.nil? ? Stretchy::Pipeline.descendants : [klass.constantize]
|
8
|
+
models.each do |model|
|
9
|
+
spinner = TTY::Spinner.new("Creating Pipeline #{model} ".ljust(JUSTIFICATION) + ":spinner", format: :dots)
|
10
|
+
spinner.auto_spin
|
11
|
+
|
12
|
+
begin
|
13
|
+
response = model.create!
|
14
|
+
rescue => e
|
15
|
+
spinner.stop(Rainbow("[FAILED]").red)
|
16
|
+
next
|
17
|
+
end
|
18
|
+
status = if response['acknowledged']
|
19
|
+
Rainbow("[SUCCESS]").green
|
20
|
+
else
|
21
|
+
Rainbow("[FAILED]").red
|
22
|
+
end
|
23
|
+
spinner.stop(status)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :pipeline do
|
3
|
+
desc "Delete pipeline"
|
4
|
+
task delete: :environment do
|
5
|
+
klass = ENV['MODEL']
|
6
|
+
models = klass.nil? ? Stretchy::Pipeline.descendants : [klass.constantize]
|
7
|
+
models.each do |model|
|
8
|
+
spinner = TTY::Spinner.new("Deleting Pipeline #{model} ".ljust(JUSTIFICATION) + ":spinner", format: :dots)
|
9
|
+
spinner.auto_spin
|
10
|
+
|
11
|
+
unless model.exists?
|
12
|
+
spinner.stop(Rainbow("[MISSING]").white)
|
13
|
+
next
|
14
|
+
end
|
15
|
+
|
16
|
+
response = model.delete!
|
17
|
+
status = if response['acknowledged']
|
18
|
+
Rainbow("[SUCCESS]").green
|
19
|
+
else
|
20
|
+
Rainbow("[FAILED]").red
|
21
|
+
end
|
22
|
+
spinner.stop(status)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :pipeline do
|
3
|
+
|
4
|
+
desc "Check the status of all pipelines"
|
5
|
+
task status: :environment do
|
6
|
+
klass = ENV['MODEL']
|
7
|
+
|
8
|
+
Rails.application.eager_load!
|
9
|
+
models = klass.nil? ? Stretchy::Pipeline.descendants : [klass.constantize]
|
10
|
+
|
11
|
+
puts Rainbow("Pipelines").color :gray
|
12
|
+
models.each do |model|
|
13
|
+
response = model.exists?
|
14
|
+
status = if response
|
15
|
+
Rainbow("[CREATED]").green.bright
|
16
|
+
else
|
17
|
+
Rainbow("[MISSING]").white
|
18
|
+
end
|
19
|
+
puts "#{model.pipeline_name}".ljust(JUSTIFICATION) + status
|
20
|
+
end
|
21
|
+
puts "\n\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :stretchy do
|
2
|
+
namespace :status do
|
3
|
+
desc "Check the status of all indexes"
|
4
|
+
task all: :environment do
|
5
|
+
Rake::Task['stretchy:index:status'].invoke
|
6
|
+
Rake::Task['stretchy:pipeline:status'].invoke
|
7
|
+
Rake::Task['stretchy:ml:status'].invoke
|
8
|
+
Rake::Task['stretchy:connector:status'].invoke
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Check the status of all indexes, pipelines and ml models"
|
13
|
+
task status: 'stretchy:status:all' do
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'stretchy-model'
|
2
|
+
require 'tty-spinner'
|
3
|
+
|
4
|
+
JUSTIFICATION = 90 unless defined?(JUSTIFICATION)
|
5
|
+
|
6
|
+
path = File.expand_path(__dir__)
|
7
|
+
Dir.glob("#{path}/**/*.rake").each do |f|
|
8
|
+
import f unless f == __FILE__
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :stretchy do
|
12
|
+
desc "Create all indexes, pipelines and deploy all models"
|
13
|
+
task up: :environment do
|
14
|
+
Rake::Task['stretchy:connector:create'].invoke
|
15
|
+
Rake::Task['stretchy:ml:register'].invoke
|
16
|
+
Rake::Task['stretchy:ml:deploy'].invoke
|
17
|
+
Rake::Task['stretchy:pipeline:create'].invoke
|
18
|
+
Rake::Task['stretchy:index:create'].invoke
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Delete all indexes, pipelines and undeploy all models"
|
22
|
+
task down: :environment do
|
23
|
+
Rake::Task['stretchy:ml:undeploy'].invoke
|
24
|
+
Rake::Task['stretchy:ml:delete'].invoke
|
25
|
+
Rake::Task['stretchy:connector:delete'].invoke
|
26
|
+
Rake::Task['stretchy:pipeline:delete'].invoke
|
27
|
+
Rake::Task['stretchy:index:delete'].invoke
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Enable Machine Learning on all nodes"
|
31
|
+
task ml_on_all_nodes: :environment do
|
32
|
+
puts "Enabling Machine Learning on all nodes..."
|
33
|
+
puts Stretchy::MachineLearning::Model.ml_on_all_nodes!
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Machine Learning on ML nodes only"
|
37
|
+
task ml_on_ml_nodes: :environment do
|
38
|
+
puts "Enabling Machine Learning on ML nodes only..."
|
39
|
+
puts Stretchy::MachineLearning::Model.ml_on_ml_nodes!
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/stretchy/version.rb
CHANGED
data/lib/stretchy.rb
CHANGED
@@ -10,7 +10,9 @@ require 'active_support/all'
|
|
10
10
|
|
11
11
|
require_relative "stretchy/version"
|
12
12
|
require_relative "stretchy/rails/instrumentation/railtie" if defined?(Rails)
|
13
|
+
require_relative "stretchy/rails/railtie" if defined?(Rails)
|
13
14
|
require_relative 'elasticsearch/api/namespace/machine_learning/model'
|
15
|
+
require_relative 'elasticsearch/api/namespace/connector'
|
14
16
|
|
15
17
|
module Stretchy
|
16
18
|
|
@@ -27,6 +29,7 @@ module Stretchy
|
|
27
29
|
|
28
30
|
def self.boot!
|
29
31
|
loader.setup
|
32
|
+
Elasticsearch::API.send(:include, Elasticsearch::API::Connector)
|
30
33
|
Elasticsearch::API.send(:include, Elasticsearch::API::MachineLearning::Models)
|
31
34
|
Stretchy::Attributes.register!
|
32
35
|
end
|
@@ -35,6 +38,10 @@ module Stretchy
|
|
35
38
|
Stretchy::Delegation::GatewayDelegation.send(:include, Rails::Instrumentation::Publishers::Record)
|
36
39
|
end
|
37
40
|
|
41
|
+
def self.env
|
42
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
|
43
|
+
end
|
44
|
+
|
38
45
|
module Errors
|
39
46
|
class QueryOptionMissing < StandardError; end
|
40
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stretchy-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spencer Markowski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: tty-spinner
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rspec
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -258,7 +272,7 @@ files:
|
|
258
272
|
- docs/_sidebar.md
|
259
273
|
- docs/examples/_sidebar.md
|
260
274
|
- docs/examples/data_analysis.md
|
261
|
-
- docs/examples/
|
275
|
+
- docs/examples/neural_search_with_llm.md
|
262
276
|
- docs/examples/simple-ingest-pipeline.md
|
263
277
|
- docs/guides/_sidebar.md
|
264
278
|
- docs/guides/aggregations.md
|
@@ -272,6 +286,24 @@ files:
|
|
272
286
|
- docs/stretchy.cover.png
|
273
287
|
- docs/stretchy.logo.png
|
274
288
|
- docs/styles.css
|
289
|
+
- lib/elasticsearch/api/actions/connector/check_in.rb
|
290
|
+
- lib/elasticsearch/api/actions/connector/delete.rb
|
291
|
+
- lib/elasticsearch/api/actions/connector/get.rb
|
292
|
+
- lib/elasticsearch/api/actions/connector/last_sync.rb
|
293
|
+
- lib/elasticsearch/api/actions/connector/list.rb
|
294
|
+
- lib/elasticsearch/api/actions/connector/post.rb
|
295
|
+
- lib/elasticsearch/api/actions/connector/put.rb
|
296
|
+
- lib/elasticsearch/api/actions/connector/update_api_key_id.rb
|
297
|
+
- lib/elasticsearch/api/actions/connector/update_configuration.rb
|
298
|
+
- lib/elasticsearch/api/actions/connector/update_error.rb
|
299
|
+
- lib/elasticsearch/api/actions/connector/update_filtering.rb
|
300
|
+
- lib/elasticsearch/api/actions/connector/update_index_name.rb
|
301
|
+
- lib/elasticsearch/api/actions/connector/update_name.rb
|
302
|
+
- lib/elasticsearch/api/actions/connector/update_native.rb
|
303
|
+
- lib/elasticsearch/api/actions/connector/update_pipeline.rb
|
304
|
+
- lib/elasticsearch/api/actions/connector/update_scheduling.rb
|
305
|
+
- lib/elasticsearch/api/actions/connector/update_service_type.rb
|
306
|
+
- lib/elasticsearch/api/actions/connector/update_status.rb
|
275
307
|
- lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb
|
276
308
|
- lib/elasticsearch/api/actions/machine_learning/models/deploy.rb
|
277
309
|
- lib/elasticsearch/api/actions/machine_learning/models/get_model.rb
|
@@ -280,15 +312,23 @@ files:
|
|
280
312
|
- lib/elasticsearch/api/actions/machine_learning/models/register.rb
|
281
313
|
- lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb
|
282
314
|
- lib/elasticsearch/api/actions/machine_learning/models/update_model.rb
|
315
|
+
- lib/elasticsearch/api/namespace/connector.rb
|
283
316
|
- lib/elasticsearch/api/namespace/machine_learning/model.rb
|
317
|
+
- lib/opensearch/api/actions/machine_learning/connector/delete.rb
|
318
|
+
- lib/opensearch/api/actions/machine_learning/connector/get.rb
|
319
|
+
- lib/opensearch/api/actions/machine_learning/connector/list.rb
|
320
|
+
- lib/opensearch/api/actions/machine_learning/connector/post.rb
|
321
|
+
- lib/opensearch/api/actions/machine_learning/connector/put.rb
|
284
322
|
- lib/opensearch/api/actions/machine_learning/models/delete_model.rb
|
285
323
|
- lib/opensearch/api/actions/machine_learning/models/deploy.rb
|
286
324
|
- lib/opensearch/api/actions/machine_learning/models/get_model.rb
|
287
325
|
- lib/opensearch/api/actions/machine_learning/models/get_status.rb
|
288
326
|
- lib/opensearch/api/actions/machine_learning/models/params_registry.rb
|
327
|
+
- lib/opensearch/api/actions/machine_learning/models/predict.rb
|
289
328
|
- lib/opensearch/api/actions/machine_learning/models/register.rb
|
290
329
|
- lib/opensearch/api/actions/machine_learning/models/undeploy.rb
|
291
330
|
- lib/opensearch/api/actions/machine_learning/models/update_model.rb
|
331
|
+
- lib/opensearch/api/namespace/connector.rb
|
292
332
|
- lib/opensearch/api/namespace/machine_learning/model.rb
|
293
333
|
- lib/stretchy.rb
|
294
334
|
- lib/stretchy/associations.rb
|
@@ -348,7 +388,10 @@ files:
|
|
348
388
|
- lib/stretchy/delegation/gateway_delegation.rb
|
349
389
|
- lib/stretchy/index_setting.rb
|
350
390
|
- lib/stretchy/indexing/bulk.rb
|
391
|
+
- lib/stretchy/machine_learning/connector.rb
|
392
|
+
- lib/stretchy/machine_learning/errors.rb
|
351
393
|
- lib/stretchy/machine_learning/model.rb
|
394
|
+
- lib/stretchy/machine_learning/registry.rb
|
352
395
|
- lib/stretchy/model/callbacks.rb
|
353
396
|
- lib/stretchy/model/common.rb
|
354
397
|
- lib/stretchy/model/persistence.rb
|
@@ -360,6 +403,22 @@ files:
|
|
360
403
|
- lib/stretchy/querying.rb
|
361
404
|
- lib/stretchy/rails/instrumentation/publishers.rb
|
362
405
|
- lib/stretchy/rails/instrumentation/railtie.rb
|
406
|
+
- lib/stretchy/rails/railtie.rb
|
407
|
+
- lib/stretchy/rails/tasks/connector/create.rake
|
408
|
+
- lib/stretchy/rails/tasks/connector/delete.rake
|
409
|
+
- lib/stretchy/rails/tasks/connector/status.rake
|
410
|
+
- lib/stretchy/rails/tasks/connector/update.rake
|
411
|
+
- lib/stretchy/rails/tasks/index/create.rake
|
412
|
+
- lib/stretchy/rails/tasks/index/delete.rake
|
413
|
+
- lib/stretchy/rails/tasks/index/status.rake
|
414
|
+
- lib/stretchy/rails/tasks/ml/delete.rake
|
415
|
+
- lib/stretchy/rails/tasks/ml/deploy.rake
|
416
|
+
- lib/stretchy/rails/tasks/ml/status.rake
|
417
|
+
- lib/stretchy/rails/tasks/pipeline/create.rake
|
418
|
+
- lib/stretchy/rails/tasks/pipeline/delete.rake
|
419
|
+
- lib/stretchy/rails/tasks/pipeline/status.rake
|
420
|
+
- lib/stretchy/rails/tasks/status.rake
|
421
|
+
- lib/stretchy/rails/tasks/stretchy.rake
|
363
422
|
- lib/stretchy/record.rb
|
364
423
|
- lib/stretchy/relation.rb
|
365
424
|
- lib/stretchy/relations/aggregation_methods.rb
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# Semantic Search with LLMs
|
2
|
-
|
3
|
-
>[!INFO|style:flat|label:OpenSearch Only]
|
4
|
-
> This guide only works with features found in Opensearch 2.12+
|
5
|
-
|
6
|
-
**Prerequisites:**
|
7
|
-
|
8
|
-
- Opensearch installed and running
|
9
|
-
- Ruby on Rails or stretchy-model's `bin/console`
|
10
|
-
|
11
|
-
Follow the [Quick Start](guides/quick-start) for detailed steps.
|
12
|
-
|
13
|
-
## Text Embeddings
|
14
|
-
|
15
|
-
* OpenAI embeddings
|
16
|
-
|
17
|
-
## Ingest Pipeline
|
18
|
-
|
19
|
-
_Set up ingest pipeline with inference model_
|
20
|
-
|
21
|
-
## Define Models
|
22
|
-
```ruby
|
23
|
-
class Repo < StretchyModel
|
24
|
-
attribute :name, :string
|
25
|
-
attribute :meta, :hash
|
26
|
-
attribute :files, :nested
|
27
|
-
has_many :files
|
28
|
-
end
|
29
|
-
```
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
class RepoFile < StretchyModel
|
33
|
-
attribute :name, :string
|
34
|
-
attribute :path, :string
|
35
|
-
attribute :content, :text
|
36
|
-
attribute :file_embeddings, :dense_vector
|
37
|
-
attribute :method_definitions, :array
|
38
|
-
attribute :language, :string
|
39
|
-
end
|
40
|
-
```
|
41
|
-
|
42
|
-
## Controller
|
43
|
-
```ruby
|
44
|
-
def search
|
45
|
-
query_text = params[:query_text]
|
46
|
-
|
47
|
-
response = RepoFile.where(content: query_text)
|
48
|
-
.exists?(field: :file_embeddings)
|
49
|
-
.knn(
|
50
|
-
field: :file_embeddings,
|
51
|
-
k: 1,
|
52
|
-
num_candidates: 20,
|
53
|
-
query_vector_builder: {
|
54
|
-
text_embedding: {
|
55
|
-
model_id: :sentence_transformers,
|
56
|
-
model_text: query_text
|
57
|
-
}
|
58
|
-
},
|
59
|
-
boost: 24
|
60
|
-
)
|
61
|
-
.fields(:content, :name, :path)
|
62
|
-
|
63
|
-
|
64
|
-
negative_response = "Unable to find the answer to your question given the provided context."
|
65
|
-
|
66
|
-
prompt = "Answer this question: #{query_text}\nUsing only the information from this Elastic Doc: #{response}\nIf the answer is not contained in the supplied doc reply '#{negative_response}' and nothing else"
|
67
|
-
|
68
|
-
@answer = LLM.chat(prompt)
|
69
|
-
end
|
70
|
-
```
|
71
|
-
|
72
|
-
## Views
|
73
|
-
|
74
|
-
```slim
|
75
|
-
|
76
|
-
div[data-controller="search"]
|
77
|
-
= simple_form :search do |f|
|
78
|
-
= f.input :query_text
|
79
|
-
= f.submit
|
80
|
-
|
81
|
-
#responses data-controller="response"
|
82
|
-
|
83
|
-
```
|