stretchy-model 0.6.0 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/containers/Dockerfile.opensearch +4 -3
  3. data/docker-compose.yml +32 -19
  4. data/lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb +33 -0
  5. data/lib/elasticsearch/api/actions/machine_learning/models/deploy.rb +31 -0
  6. data/lib/elasticsearch/api/actions/machine_learning/models/get_model.rb +43 -0
  7. data/lib/elasticsearch/api/actions/machine_learning/models/get_status.rb +31 -0
  8. data/lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb +45 -0
  9. data/lib/elasticsearch/api/actions/machine_learning/models/register.rb +45 -0
  10. data/lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb +32 -0
  11. data/lib/elasticsearch/api/actions/machine_learning/models/update_model.rb +39 -0
  12. data/lib/elasticsearch/api/namespace/machine_learning/model.rb +27 -0
  13. data/lib/opensearch/api/actions/machine_learning/models/delete_model.rb +33 -0
  14. data/lib/opensearch/api/actions/machine_learning/models/deploy.rb +31 -0
  15. data/lib/opensearch/api/actions/machine_learning/models/get_model.rb +44 -0
  16. data/lib/opensearch/api/actions/machine_learning/models/get_status.rb +31 -0
  17. data/lib/opensearch/api/actions/machine_learning/models/params_registry.rb +45 -0
  18. data/lib/opensearch/api/actions/machine_learning/models/register.rb +45 -0
  19. data/lib/opensearch/api/actions/machine_learning/models/undeploy.rb +31 -0
  20. data/lib/opensearch/api/actions/machine_learning/models/update_model.rb +39 -0
  21. data/lib/opensearch/api/namespace/machine_learning/model.rb +27 -0
  22. data/lib/stretchy/attributes/type/date_time.rb +50 -0
  23. data/lib/stretchy/attributes/type/rank_features.rb +11 -1
  24. data/lib/stretchy/attributes.rb +1 -0
  25. data/lib/stretchy/common.rb +5 -0
  26. data/lib/stretchy/delegation/gateway_delegation.rb +8 -2
  27. data/lib/stretchy/machine_learning/model.rb +192 -0
  28. data/lib/stretchy/open_search_compatibility.rb +4 -0
  29. data/lib/stretchy/pipeline.rb +123 -0
  30. data/lib/stretchy/pipelines/processor.rb +55 -0
  31. data/lib/stretchy/querying.rb +1 -0
  32. data/lib/stretchy/rails/instrumentation/publishers.rb +31 -0
  33. data/lib/{rails → stretchy/rails}/instrumentation/railtie.rb +11 -6
  34. data/lib/stretchy/relation.rb +1 -0
  35. data/lib/stretchy/relations/query_builder.rb +73 -3
  36. data/lib/stretchy/relations/query_methods.rb +32 -0
  37. data/lib/stretchy/shared_scopes.rb +6 -1
  38. data/lib/stretchy/version.rb +1 -1
  39. data/lib/stretchy.rb +7 -2
  40. metadata +40 -5
  41. data/lib/rails/instrumentation/publishers.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f23580fe0c8761ced02da75cbc44f16ab7893a559d30d9a5e0de23aa96ed790a
4
- data.tar.gz: 821381d3e9e92822d71aac637d98f8b04a76736a80e421ca7d2c4fd05fd108d8
3
+ metadata.gz: 5de2e134e27640a01cc802b24b139510dacd84b633fe35795ba5215bf620bd5e
4
+ data.tar.gz: ee207f2854bbca7c03dfb104bf8bfe2934072ea578e23e58852f6842bd1e41b6
5
5
  SHA512:
6
- metadata.gz: 99dc36ee6cce021e869a8e1f3e2f005f546b1c50bf973434c624574c1dd601757baf4a1d39562f7ddd05bf4a1e640512111b821d8a70b8d5416bf73701b38f03
7
- data.tar.gz: 4a58307bd7ae5a5781e7462df9c95438f66eecab5d0ae43238878d228e2ca6939a8a7643b70ac3c2586dcae537935206bfb15339415f6b3c3a70ef2518e401b4
6
+ metadata.gz: a4937d127058d0bdaa2eb8d2e7ff6802096aa592ec75672d175475ea317d6794380c072934e0479dc45ca6baf864715be20392b796274bbc07ce31c8b474b2de
7
+ data.tar.gz: f0210926d21762429885e37126d17e7b6d718b4b6cb3ee5bfd2332842a35fb1f446c833854d60062fa423748c3696a8d16da6dcbe9b58fd8c254287ef281661a
@@ -2,7 +2,6 @@
2
2
 
3
3
  # Base image
4
4
  FROM opensearchproject/opensearch:2.12.0
5
-
6
5
  # Environment variables
7
6
  # disables bootstrap checks that are enabled when network.host is set to a non-loopback address
8
7
  ENV discovery.type=single-node
@@ -12,8 +11,10 @@ ENV plugins.security.disabled=true
12
11
  # along with the memlock settings below, disables swapping
13
12
  ENV bootstrap.memory_lock=true
14
13
  # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
15
- ENV OPENSEARCH_JAVA_OPTS="-Xms512m -Xmx512m"
14
+ ENV OPENSEARCH_JAVA_OPTS="-Xms3078m -Xmx3078m"
16
15
  # disables execution of install_demo_configuration.sh bundled with security plugin, which installs demo certificates and security configurations to OpenSearch
17
16
  ENV DISABLE_INSTALL_DEMO_CONFIG=true
18
17
  # disables security plugin entirely in OpenSearch by setting plugins.security.disabled: true in opensearch.yml
19
- ENV DISABLE_SECURITY_PLUGIN=true
18
+ # ENV DISABLE_SECURITY_PLUGIN=true
19
+
20
+
data/docker-compose.yml CHANGED
@@ -10,11 +10,16 @@ services:
10
10
  - "9200:9200"
11
11
  environment:
12
12
  - discovery.type=single-node
13
+ networks:
14
+ - elasticsearch-net
15
+
13
16
 
14
17
  opensearch:
15
- build:
16
- context: .
17
- dockerfile: containers/Dockerfile.opensearch
18
+ image: opensearchproject/opensearch:latest
19
+ container_name: opensearch-node1
20
+ # build:
21
+ # context: .
22
+ # dockerfile: containers/Dockerfile.opensearch
18
23
  ulimits:
19
24
  memlock:
20
25
  soft: -1
@@ -24,29 +29,37 @@ services:
24
29
  hard: 65536
25
30
  environment:
26
31
  - discovery.type=single-node
32
+ - node.name=opensearch-node1
33
+ - plugins.security.disabled=true
34
+ - bootstrap.memory_lock=true
35
+ - "OPENSEARCH_JAVA_OPTS=-Xms3078m -Xmx3078m"
36
+ - OPENSEARCH_INITIAL_ADMIN_PASSWORD=A3s0p3nS3cUr1tY
27
37
  # volumes:
28
38
  # - opensearch-data1:/usr/share/opensearch/data
29
39
  ports:
30
40
  - 9200:9200
31
41
  - 9600:9600 # required for Performance Analyzer
32
- # networks:
33
- # - opensearch-net
42
+ networks:
43
+ - opensearch-net
44
+
45
+ opensearch-dashboards:
46
+ image: opensearch-dashboards-no-security # Make sure the version of opensearch-dashboards matches the version of opensearch installed on other nodes
47
+ container_name: opensearch-dashboards
48
+ ports:
49
+ - 5601:5601 # Map host port 5601 to container port 5601
50
+ expose:
51
+ - "5601" # Expose port 5601 for web access to OpenSearch Dashboards
52
+ environment:
53
+ - OPENSEARCH_HOSTS="http://opensearch-node1:9200"
54
+ - OPENSEARCH_INITIAL_ADMIN_PASSWORD=A3s0p3nS3cUr1tY
55
+ - plugins.security.disabled=true
56
+ networks:
57
+ - opensearch-net
34
58
 
35
- # opensearch-dashboards:
36
- # image: opensearchproject/opensearch-dashboards:1.2.0
37
- # container_name: opensearch-dashboards
38
- # ports:
39
- # - 5601:5601
40
- # expose:
41
- # - "5601"
42
- # environment:
43
- # - 'OPENSEARCH_HOSTS=["http://opensearch-node1:9200"]'
44
- # - "DISABLE_SECURITY_DASHBOARDS_PLUGIN=true" # disables security dashboards plugin in OpenSearch Dashboards
45
- # networks:
46
- # - opensearch-net
47
59
 
48
60
  # volumes:
49
61
  # opensearch-data1:
50
62
 
51
- # networks:
52
- # opensearch-net:
63
+ networks:
64
+ opensearch-net:
65
+ elasticsearch-net:
@@ -0,0 +1,33 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Returns a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :headers Custom HTTP headers
10
+ #
11
+ # Example
12
+ # delete_model(id: 109sdj0asl092)
13
+ #
14
+ # DELETE /_plugins/_ml/models/<model_id>
15
+ def delete_model(arguments = {})
16
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
17
+ headers = arguments.delete(:headers) || {}
18
+
19
+ _id = arguments.delete(:id)
20
+
21
+ method = Elasticsearch::API::HTTP_DELETE
22
+ path = "_plugins/_ml/models/#{Utils.__listify(_id)}"
23
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
24
+
25
+ body = nil
26
+ perform_request(method, path, params, body, headers).body
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :body The deploy options
10
+ #
11
+ #
12
+ # POST /_plugins/_ml/models/<model_id>/_deploy
13
+ def deploy(arguments = {})
14
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
15
+ _id = arguments.delete(:id)
16
+ arguments = arguments.clone
17
+ headers = arguments.delete(:headers) || {}
18
+
19
+ method = Elasticsearch::API::HTTP_POST
20
+ path = "_plugins/_ml/models/#{Utils.__listify(_id)}/_deploy"
21
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
22
+
23
+ body = arguments[:body]
24
+ perform_request(method, path, params, body, headers).body
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Returns a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ #
10
+ # Example
11
+ # get_model(id: 109sdj0asl092)
12
+ #
13
+ # Example
14
+ # # Get all models
15
+ # get_model
16
+ #
17
+ # GET /_plugins/_ml/models/<model_id>
18
+ def get_model(arguments = {})
19
+ _id = arguments.delete(:id)
20
+ headers = arguments.delete(:headers) || {}
21
+ method = Elasticsearch::API::HTTP_GET
22
+ path = if _id
23
+ body = nil
24
+ "_ml/trained_models/#{Utils.__listify(_id)}"
25
+ else
26
+ body = {
27
+ "query": {
28
+ "match_all": {}
29
+ },
30
+ "size": 1000
31
+ }
32
+ '_ml/trained_models'
33
+ end
34
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
35
+
36
+ perform_request(method, path, params, body, headers).body
37
+ end
38
+
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :body The deploy options
10
+ #
11
+ #
12
+ # GET /_plugins/_ml/tasks/<task_id>
13
+ def get_status(arguments = {})
14
+ raise ArgumentError, "Required argument 'task_id' missing" unless arguments[:task_id]
15
+ _id = arguments.delete(:task_id)
16
+ arguments = arguments.clone
17
+ headers = arguments.delete(:headers) || {}
18
+
19
+ method = Elasticsearch::API::HTTP_GET
20
+ path = "_plugins/_ml/tasks/#{Utils.__listify(_id)}"
21
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
22
+
23
+ body = nil
24
+ perform_request(method, path, params, body, headers).body
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ module ParamsRegistry
7
+ extend self
8
+
9
+ # A Mapping of all the actions to their list of valid params.
10
+ #
11
+ # @since 6.1.1
12
+ PARAMS = {}
13
+
14
+ # Register an action with its list of valid params.
15
+ #
16
+ # @example Register the action.
17
+ # ParamsRegistry.register(:benchmark, [ :verbose ])
18
+ #
19
+ # @param [ Symbol ] action The action to register.
20
+ # @param [ Array[Symbol] ] valid_params The list of valid params.
21
+ #
22
+ # @since 6.1.1
23
+ def register(action, valid_params)
24
+ PARAMS[action.to_sym] = valid_params
25
+ end
26
+
27
+ # Get the list of valid params for a given action.
28
+ #
29
+ # @example Get the list of valid params.
30
+ # ParamsRegistry.get(:benchmark)
31
+ #
32
+ # @param [ Symbol ] action The action.
33
+ #
34
+ # @return [ Array<Symbol> ] The list of valid params for the action.
35
+ #
36
+ # @since 6.1.1
37
+ def get(action)
38
+ PARAMS.fetch(action, [])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [Hash] :body The model definition **Required**
9
+ # @option arguments [Boolean] :deploy Whether to deploy the model after registering it. The deploy operation is performed by calling the [Deploy Model API](https://opensearch.org/docs/latest/ml-commons-plugin/api/model-apis/deploy-model/). Default is `false`
10
+ #
11
+ # Example
12
+ # client.machine_learing_model.register(body: {
13
+ # "name": "huggingface/sentence-transformers/msmarco-distilbert-base-tas-b",
14
+ # "version": "1.0.1",
15
+ # "model_group_id": "Z1eQf4oB5Vm0Tdw8EIP2",
16
+ # "model_format": "TORCH_SCRIPT"
17
+ # },
18
+ # deploy: true
19
+ #
20
+ # POST /_plugins/_ml/models/_register
21
+ def register(arguments = {})
22
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
23
+
24
+ arguments = arguments.clone
25
+ headers = arguments.delete(:headers) || {}
26
+
27
+ method = Elasticsearch::API::HTTP_POST
28
+ path = "_plugins/_ml/models/_register"
29
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
30
+
31
+ body = arguments[:body]
32
+ perform_request(method, path, params, body, headers).body
33
+ end
34
+
35
+ # Register this action with its valid params when the module is loaded.
36
+ #
37
+ # @since 6.2.0
38
+ ParamsRegistry.register(:put_pipeline, %i[
39
+ deploy
40
+ ].freeze)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :body The deploy options
10
+ #
11
+ #
12
+ # POST /_plugins/_ml/models/<model_id>/_undeploy
13
+ def undeploy(arguments = {})
14
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
15
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
16
+ _id = arguments.delete(:id)
17
+ arguments = arguments.clone
18
+ headers = arguments.delete(:headers) || {}
19
+
20
+ method = Elasticsearch::API::HTTP_POST
21
+ path = "_plugins/_ml/models/#{Utils.__listify(_id)}/_undeploy"
22
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
23
+
24
+ body = arguments[:body]
25
+ perform_request(method, path, params, body, headers).body
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ module Elasticsearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Returns a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :body The request fields
10
+ #
11
+ # Example
12
+ # update_model(id: 109sdj0asl092, "rate_limiter": {
13
+ # "limit": "4",
14
+ # "unit": "MINUTES"
15
+ # }
16
+ # )
17
+ #
18
+ # PUT /_plugins/_ml/models/<model_id>
19
+ def update_model(arguments = {})
20
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
21
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
22
+
23
+ _id = arguments.delete(:id)
24
+
25
+ headers = arguments.delete(:headers) || {}
26
+
27
+ method = Elasticsearch::API::HTTP_PUT
28
+ path = "_plugins/_ml/models/#{Utils.__listify(_id)}"
29
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
30
+
31
+ body = arguments[:body]
32
+ perform_request(method, path, params, body, headers).body
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ Dir[File.expand_path('../../actions/**/*.rb', __dir__)].sort.each { |f| require f }
2
+
3
+ module Elasticsearch
4
+ module API
5
+ module MachineLearning
6
+ module Models
7
+ module Actions; end
8
+
9
+ # Client for the "machine_learning/models" namespace (includes the {MachineLearning::Models::Actions} methods)
10
+ #
11
+ class MachineLearningClient
12
+ include MachineLearning::Models::Actions
13
+ include Elasticsearch::API::Common::Client::Base
14
+ include Elasticsearch::API::Common::Client
15
+ end
16
+
17
+ # Proxy method for {MachineLearningModel}, available in the receiving object
18
+ #
19
+ def machine_learning
20
+ @machine_learning ||= MachineLearningClient.new(self)
21
+ end
22
+
23
+ alias ml machine_learning
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module OpenSearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Returns a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :headers Custom HTTP headers
10
+ #
11
+ # Example
12
+ # delete_model(id: 109sdj0asl092)
13
+ #
14
+ # DELETE /_plugins/_ml/models/<model_id>
15
+ def delete_model(arguments = {})
16
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
17
+ headers = arguments.delete(:headers) || {}
18
+
19
+ _id = arguments.delete(:id)
20
+
21
+ method = OpenSearch::API::HTTP_DELETE
22
+ path = "_plugins/_ml/models/#{Utils.__listify(_id)}"
23
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
24
+
25
+ body = nil
26
+ perform_request(method, path, params, body, headers).body
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module OpenSearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :body The deploy options
10
+ #
11
+ #
12
+ # POST /_plugins/_ml/models/<model_id>/_deploy
13
+ def deploy(arguments = {})
14
+ raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
15
+ _id = arguments.delete(:id)
16
+ arguments = arguments.clone
17
+ headers = arguments.delete(:headers) || {}
18
+
19
+ method = OpenSearch::API::HTTP_POST
20
+ path = "_plugins/_ml/models/#{Utils.__listify(_id)}/_deploy"
21
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
22
+
23
+ body = arguments[:body]
24
+ perform_request(method, path, params, body, headers).body
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,44 @@
1
+ module OpenSearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Returns a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ #
10
+ # Example
11
+ # get_model(id: 109sdj0asl092)
12
+ #
13
+ # Example
14
+ # # Get all models
15
+ # get_model
16
+ #
17
+ # GET /_plugins/_ml/models/<model_id>
18
+ def get_model(arguments = {})
19
+ _id = arguments.delete(:id)
20
+ headers = arguments.delete(:headers) || {}
21
+ method = OpenSearch::API::HTTP_GET
22
+ path = if _id
23
+ body = nil
24
+ "_plugins/_ml/models/#{Utils.__listify(_id)}"
25
+ else
26
+ body = {
27
+ "query": {
28
+ "match_all": {}
29
+ },
30
+ "size": 1000
31
+ }
32
+ '_plugins/_ml/models/_search'
33
+ end
34
+
35
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
36
+
37
+ perform_request(method, path, params, body, headers).body
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ module OpenSearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [String] :id The model id
9
+ # @option arguments [Hash] :body The deploy options
10
+ #
11
+ #
12
+ # GET /_plugins/_ml/tasks/<task_id>
13
+ def get_status(arguments = {})
14
+ raise ArgumentError, "Required argument 'task_id' missing" unless arguments[:task_id]
15
+ _id = arguments.delete(:task_id)
16
+ arguments = arguments.clone
17
+ headers = arguments.delete(:headers) || {}
18
+
19
+ method = OpenSearch::API::HTTP_GET
20
+ path = "_plugins/_ml/tasks/#{Utils.__listify(_id)}"
21
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
22
+
23
+ body = nil
24
+ perform_request(method, path, params, body, headers).body
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ module OpenSearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ module ParamsRegistry
7
+ extend self
8
+
9
+ # A Mapping of all the actions to their list of valid params.
10
+ #
11
+ # @since 6.1.1
12
+ PARAMS = {}
13
+
14
+ # Register an action with its list of valid params.
15
+ #
16
+ # @example Register the action.
17
+ # ParamsRegistry.register(:benchmark, [ :verbose ])
18
+ #
19
+ # @param [ Symbol ] action The action to register.
20
+ # @param [ Array[Symbol] ] valid_params The list of valid params.
21
+ #
22
+ # @since 6.1.1
23
+ def register(action, valid_params)
24
+ PARAMS[action.to_sym] = valid_params
25
+ end
26
+
27
+ # Get the list of valid params for a given action.
28
+ #
29
+ # @example Get the list of valid params.
30
+ # ParamsRegistry.get(:benchmark)
31
+ #
32
+ # @param [ Symbol ] action The action.
33
+ #
34
+ # @return [ Array<Symbol> ] The list of valid params for the action.
35
+ #
36
+ # @since 6.1.1
37
+ def get(action)
38
+ PARAMS.fetch(action, [])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ module OpenSearch
2
+ module API
3
+ module MachineLearning
4
+ module Models
5
+ module Actions
6
+ # Register a model.
7
+ #
8
+ # @option arguments [Hash] :body The model definition **Required**
9
+ # @option arguments [Boolean] :deploy Whether to deploy the model after registering it. The deploy operation is performed by calling the [Deploy Model API](https://opensearch.org/docs/latest/ml-commons-plugin/api/model-apis/deploy-model/). Default is `false`
10
+ #
11
+ # Example
12
+ # client.machine_learing_model.register(body: {
13
+ # "name": "huggingface/sentence-transformers/msmarco-distilbert-base-tas-b",
14
+ # "version": "1.0.1",
15
+ # "model_group_id": "Z1eQf4oB5Vm0Tdw8EIP2",
16
+ # "model_format": "TORCH_SCRIPT"
17
+ # },
18
+ # deploy: true
19
+ #
20
+ # POST /_plugins/_ml/models/_register
21
+ def register(arguments = {})
22
+ raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
23
+
24
+ arguments = arguments.clone
25
+ headers = arguments.delete(:headers) || {}
26
+
27
+ method = OpenSearch::API::HTTP_POST
28
+ path = "_plugins/_ml/models/_register"
29
+ params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
30
+
31
+ body = arguments[:body]
32
+ perform_request(method, path, params, body, headers).body
33
+ end
34
+
35
+ # Register this action with its valid params when the module is loaded.
36
+ #
37
+ # @since 6.2.0
38
+ ParamsRegistry.register(:register, %i[
39
+ deploy
40
+ ].freeze)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end