stretchy-model 0.6.0 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -1
  3. data/README.md +28 -10
  4. data/Rakefile +56 -0
  5. data/containers/Dockerfile.opensearch +4 -3
  6. data/docker-compose.yml +32 -19
  7. data/docs/.nojekyll +0 -0
  8. data/docs/README.md +147 -0
  9. data/docs/_coverpage.md +14 -0
  10. data/docs/_sidebar.md +14 -0
  11. data/docs/examples/_sidebar.md +15 -0
  12. data/docs/examples/data_analysis.md +216 -0
  13. data/docs/examples/semantic_search_with_llm.md +83 -0
  14. data/docs/examples/simple-ingest-pipeline.md +326 -0
  15. data/docs/guides/_sidebar.md +14 -0
  16. data/docs/guides/aggregations.md +142 -0
  17. data/docs/guides/machine-learning.md +154 -0
  18. data/docs/guides/models.md +372 -0
  19. data/docs/guides/pipelines.md +151 -0
  20. data/docs/guides/querying.md +361 -0
  21. data/docs/guides/quick-start.md +72 -0
  22. data/docs/guides/scopes.md +125 -0
  23. data/docs/index.html +113 -0
  24. data/docs/stretchy.cover.png +0 -0
  25. data/docs/stretchy.logo.png +0 -0
  26. data/docs/styles.css +90 -0
  27. data/lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb +33 -0
  28. data/lib/elasticsearch/api/actions/machine_learning/models/deploy.rb +31 -0
  29. data/lib/elasticsearch/api/actions/machine_learning/models/get_model.rb +43 -0
  30. data/lib/elasticsearch/api/actions/machine_learning/models/get_status.rb +31 -0
  31. data/lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb +45 -0
  32. data/lib/elasticsearch/api/actions/machine_learning/models/register.rb +45 -0
  33. data/lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb +32 -0
  34. data/lib/elasticsearch/api/actions/machine_learning/models/update_model.rb +39 -0
  35. data/lib/elasticsearch/api/namespace/machine_learning/model.rb +27 -0
  36. data/lib/opensearch/api/actions/machine_learning/models/delete_model.rb +33 -0
  37. data/lib/opensearch/api/actions/machine_learning/models/deploy.rb +31 -0
  38. data/lib/opensearch/api/actions/machine_learning/models/get_model.rb +44 -0
  39. data/lib/opensearch/api/actions/machine_learning/models/get_status.rb +31 -0
  40. data/lib/opensearch/api/actions/machine_learning/models/params_registry.rb +45 -0
  41. data/lib/opensearch/api/actions/machine_learning/models/register.rb +45 -0
  42. data/lib/opensearch/api/actions/machine_learning/models/undeploy.rb +31 -0
  43. data/lib/opensearch/api/actions/machine_learning/models/update_model.rb +39 -0
  44. data/lib/opensearch/api/namespace/machine_learning/model.rb +27 -0
  45. data/lib/stretchy/attributes/transformers/keyword_transformer.rb +41 -35
  46. data/lib/stretchy/attributes/type/array.rb +24 -1
  47. data/lib/stretchy/attributes/type/base.rb +6 -2
  48. data/lib/stretchy/attributes/type/binary.rb +24 -17
  49. data/lib/stretchy/attributes/type/boolean.rb +29 -22
  50. data/lib/stretchy/attributes/type/completion.rb +18 -10
  51. data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
  52. data/lib/stretchy/attributes/type/date_time.rb +81 -20
  53. data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
  54. data/lib/stretchy/attributes/type/flattened.rb +28 -19
  55. data/lib/stretchy/attributes/type/geo_point.rb +21 -12
  56. data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
  57. data/lib/stretchy/attributes/type/hash.rb +24 -10
  58. data/lib/stretchy/attributes/type/histogram.rb +25 -0
  59. data/lib/stretchy/attributes/type/ip.rb +26 -17
  60. data/lib/stretchy/attributes/type/join.rb +16 -7
  61. data/lib/stretchy/attributes/type/keyword.rb +21 -26
  62. data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
  63. data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
  64. data/lib/stretchy/attributes/type/nested.rb +16 -11
  65. data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
  66. data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
  67. data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
  68. data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
  69. data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
  70. data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
  71. data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
  72. data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
  73. data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
  74. data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
  75. data/lib/stretchy/attributes/type/percolator.rb +16 -4
  76. data/lib/stretchy/attributes/type/point.rb +19 -9
  77. data/lib/stretchy/attributes/type/range/base.rb +24 -1
  78. data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
  79. data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
  80. data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
  81. data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
  82. data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
  83. data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
  84. data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
  85. data/lib/stretchy/attributes/type/rank_features.rb +27 -10
  86. data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
  87. data/lib/stretchy/attributes/type/shape.rb +19 -9
  88. data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
  89. data/lib/stretchy/attributes/type/string.rb +42 -1
  90. data/lib/stretchy/attributes/type/text.rb +53 -28
  91. data/lib/stretchy/attributes/type/token_count.rb +21 -11
  92. data/lib/stretchy/attributes/type/version.rb +16 -6
  93. data/lib/stretchy/attributes/type/wildcard.rb +36 -25
  94. data/lib/stretchy/attributes.rb +30 -0
  95. data/lib/stretchy/delegation/gateway_delegation.rb +86 -2
  96. data/lib/stretchy/index_setting.rb +94 -0
  97. data/lib/stretchy/indexing/bulk.rb +75 -3
  98. data/lib/stretchy/machine_learning/model.rb +192 -0
  99. data/lib/stretchy/model/callbacks.rb +1 -0
  100. data/lib/stretchy/model/common.rb +157 -0
  101. data/lib/stretchy/model/persistence.rb +144 -0
  102. data/lib/stretchy/model/refreshable.rb +26 -0
  103. data/lib/stretchy/open_search_compatibility.rb +4 -0
  104. data/lib/stretchy/pipeline.rb +124 -0
  105. data/lib/stretchy/pipelines/processor.rb +57 -0
  106. data/lib/stretchy/querying.rb +7 -7
  107. data/lib/stretchy/rails/instrumentation/publishers.rb +31 -0
  108. data/lib/{rails → stretchy/rails}/instrumentation/railtie.rb +11 -6
  109. data/lib/stretchy/record.rb +5 -4
  110. data/lib/stretchy/relation.rb +230 -28
  111. data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
  112. data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
  113. data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
  114. data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
  115. data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
  116. data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
  117. data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
  118. data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
  119. data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
  120. data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
  121. data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
  122. data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
  123. data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
  124. data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
  125. data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
  126. data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
  127. data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
  128. data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
  129. data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
  130. data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
  131. data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
  132. data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
  133. data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
  134. data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
  135. data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
  136. data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
  137. data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
  138. data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
  139. data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
  140. data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
  141. data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
  142. data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
  143. data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
  144. data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
  145. data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
  146. data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
  147. data/lib/stretchy/relations/aggregation_methods.rb +20 -749
  148. data/lib/stretchy/relations/finder_methods.rb +2 -18
  149. data/lib/stretchy/relations/null_relation.rb +55 -0
  150. data/lib/stretchy/relations/query_builder.rb +139 -23
  151. data/lib/stretchy/relations/query_methods/bind.rb +19 -0
  152. data/lib/stretchy/relations/query_methods/extending.rb +29 -0
  153. data/lib/stretchy/relations/query_methods/fields.rb +70 -0
  154. data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
  155. data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
  156. data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
  157. data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
  158. data/lib/stretchy/relations/query_methods/ids.rb +40 -0
  159. data/lib/stretchy/relations/query_methods/match.rb +52 -0
  160. data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
  161. data/lib/stretchy/relations/query_methods/neural.rb +58 -0
  162. data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
  163. data/lib/stretchy/relations/query_methods/none.rb +21 -0
  164. data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
  165. data/lib/stretchy/relations/query_methods/order.rb +63 -0
  166. data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
  167. data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
  168. data/lib/stretchy/relations/query_methods/should.rb +51 -0
  169. data/lib/stretchy/relations/query_methods/size.rb +44 -0
  170. data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
  171. data/lib/stretchy/relations/query_methods/source.rb +59 -0
  172. data/lib/stretchy/relations/query_methods/where.rb +113 -0
  173. data/lib/stretchy/relations/query_methods.rb +51 -540
  174. data/lib/stretchy/relations/scoping/default.rb +136 -0
  175. data/lib/stretchy/relations/scoping/named.rb +70 -0
  176. data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
  177. data/lib/stretchy/relations/scoping.rb +30 -0
  178. data/lib/stretchy/relations/search_option_methods.rb +2 -0
  179. data/lib/stretchy/shared_scopes.rb +6 -1
  180. data/lib/stretchy/version.rb +1 -1
  181. data/lib/stretchy.rb +23 -11
  182. metadata +147 -18
  183. data/lib/rails/instrumentation/publishers.rb +0 -29
  184. data/lib/stretchy/common.rb +0 -33
  185. data/lib/stretchy/null_relation.rb +0 -53
  186. data/lib/stretchy/persistence.rb +0 -43
  187. data/lib/stretchy/refreshable.rb +0 -15
  188. data/lib/stretchy/scoping/default.rb +0 -134
  189. data/lib/stretchy/scoping/named.rb +0 -68
  190. data/lib/stretchy/scoping/scope_registry.rb +0 -34
  191. data/lib/stretchy/scoping.rb +0 -28
data/docs/styles.css ADDED
@@ -0,0 +1,90 @@
1
+ :root {
2
+ --theme-color: #F9448F;
3
+ --theme-color-light: #f79fc4;
4
+ --secondary-color: #8E4EB0;
5
+ }
6
+
7
+
8
+ section.cover .cover-main>p:last-child a {
9
+ border-radius: 2rem;
10
+ border: 1px solid #F9448F;
11
+ border-color: var(--theme-color,#F9448F);
12
+ box-sizing: border-box;
13
+ color: #F9448F;
14
+ color: var(--theme-color,#F9448F);
15
+ display: inline-block;
16
+ font-size: 1.05rem;
17
+ letter-spacing: .1rem;
18
+ margin: .5rem 1rem;
19
+ padding: .75em 2rem;
20
+ text-decoration: none;
21
+ transition: all .15s ease;
22
+ }
23
+
24
+ section.cover .cover-main>p:last-child a:last-child {
25
+ background-color: #F9448F;
26
+ background-color: var(--theme-color,#F9448F);
27
+ color: #fff;
28
+ }
29
+
30
+ section.cover .cover-main>p:last-child a:hover {
31
+ color: #fff !important;
32
+ border-color: var(--secondary-color, #8E4EB0);
33
+ background-color: var(--secondary-color, #8E4EB0);
34
+ /* opacity: .8; */
35
+ }
36
+
37
+ .docsify-hide a:first-child>img{ display: none;}
38
+
39
+ .app-sub-sidebar li:before {
40
+ content: "";
41
+ padding-right: 4px;
42
+ float: left;
43
+ }
44
+
45
+ .sidebar h3 {
46
+ text-align: center;
47
+ }
48
+
49
+
50
+ pre {
51
+ position: relative;
52
+ }
53
+ pre .clipboard-copy {
54
+ position: absolute;
55
+ right: 15px;
56
+ opacity: 1;
57
+ top: 20px;
58
+ color: var(--theme-color, #F9448F);
59
+ background-color: transparent;
60
+
61
+ }
62
+ pre .clipboard-copy:hover {
63
+ cursor: pointer;
64
+ transition: opacity 0.3s ease;
65
+ opacity: 1;
66
+ }
67
+
68
+ pre .clipboard-copy .copy-text {
69
+ position: absolute;
70
+ opacity: 0;
71
+ left: -70px;
72
+ top: 15px;
73
+ }
74
+
75
+ pre .clipboard-copy .copy-text.show {
76
+ transition: top 0.3s ease, opacity 0.3s ease;
77
+ opacity: 1;
78
+ color: #8E4EB0;
79
+ top: 0px;
80
+ }
81
+
82
+ .show {
83
+ display: block;
84
+ }
85
+
86
+
87
+
88
+ /*dt,dd {
89
+ display: flex;
90
+ } */
@@ -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
@@ -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>/_undeploy
13
+ def undeploy(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)}/_undeploy"
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