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.
- checksums.yaml +4 -4
- data/.yardopts +2 -1
- data/README.md +28 -10
- data/Rakefile +56 -0
- data/containers/Dockerfile.opensearch +4 -3
- data/docker-compose.yml +32 -19
- data/docs/.nojekyll +0 -0
- data/docs/README.md +147 -0
- data/docs/_coverpage.md +14 -0
- data/docs/_sidebar.md +14 -0
- data/docs/examples/_sidebar.md +15 -0
- data/docs/examples/data_analysis.md +216 -0
- data/docs/examples/semantic_search_with_llm.md +83 -0
- data/docs/examples/simple-ingest-pipeline.md +326 -0
- data/docs/guides/_sidebar.md +14 -0
- data/docs/guides/aggregations.md +142 -0
- data/docs/guides/machine-learning.md +154 -0
- data/docs/guides/models.md +372 -0
- data/docs/guides/pipelines.md +151 -0
- data/docs/guides/querying.md +361 -0
- data/docs/guides/quick-start.md +72 -0
- data/docs/guides/scopes.md +125 -0
- data/docs/index.html +113 -0
- data/docs/stretchy.cover.png +0 -0
- data/docs/stretchy.logo.png +0 -0
- data/docs/styles.css +90 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/delete_model.rb +33 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/deploy.rb +31 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/get_model.rb +43 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/get_status.rb +31 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/params_registry.rb +45 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/register.rb +45 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/undeploy.rb +32 -0
- data/lib/elasticsearch/api/actions/machine_learning/models/update_model.rb +39 -0
- data/lib/elasticsearch/api/namespace/machine_learning/model.rb +27 -0
- data/lib/opensearch/api/actions/machine_learning/models/delete_model.rb +33 -0
- data/lib/opensearch/api/actions/machine_learning/models/deploy.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/get_model.rb +44 -0
- data/lib/opensearch/api/actions/machine_learning/models/get_status.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/params_registry.rb +45 -0
- data/lib/opensearch/api/actions/machine_learning/models/register.rb +45 -0
- data/lib/opensearch/api/actions/machine_learning/models/undeploy.rb +31 -0
- data/lib/opensearch/api/actions/machine_learning/models/update_model.rb +39 -0
- data/lib/opensearch/api/namespace/machine_learning/model.rb +27 -0
- data/lib/stretchy/attributes/transformers/keyword_transformer.rb +41 -35
- data/lib/stretchy/attributes/type/array.rb +24 -1
- data/lib/stretchy/attributes/type/base.rb +6 -2
- data/lib/stretchy/attributes/type/binary.rb +24 -17
- data/lib/stretchy/attributes/type/boolean.rb +29 -22
- data/lib/stretchy/attributes/type/completion.rb +18 -10
- data/lib/stretchy/attributes/type/constant_keyword.rb +35 -26
- data/lib/stretchy/attributes/type/date_time.rb +81 -20
- data/lib/stretchy/attributes/type/dense_vector.rb +46 -49
- data/lib/stretchy/attributes/type/flattened.rb +28 -19
- data/lib/stretchy/attributes/type/geo_point.rb +21 -12
- data/lib/stretchy/attributes/type/geo_shape.rb +21 -12
- data/lib/stretchy/attributes/type/hash.rb +24 -10
- data/lib/stretchy/attributes/type/histogram.rb +25 -0
- data/lib/stretchy/attributes/type/ip.rb +26 -17
- data/lib/stretchy/attributes/type/join.rb +16 -7
- data/lib/stretchy/attributes/type/keyword.rb +21 -26
- data/lib/stretchy/attributes/type/knn_vector.rb +47 -0
- data/lib/stretchy/attributes/type/match_only_text.rb +22 -1
- data/lib/stretchy/attributes/type/nested.rb +16 -11
- data/lib/stretchy/attributes/type/numeric/base.rb +30 -22
- data/lib/stretchy/attributes/type/numeric/byte.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/double.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/half_float.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/integer.rb +21 -1
- data/lib/stretchy/attributes/type/numeric/long.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/scaled_float.rb +16 -7
- data/lib/stretchy/attributes/type/numeric/short.rb +20 -0
- data/lib/stretchy/attributes/type/numeric/unsigned_long.rb +21 -1
- data/lib/stretchy/attributes/type/percolator.rb +16 -4
- data/lib/stretchy/attributes/type/point.rb +19 -9
- data/lib/stretchy/attributes/type/range/base.rb +24 -1
- data/lib/stretchy/attributes/type/range/date_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/double_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/float_range.rb +21 -5
- data/lib/stretchy/attributes/type/range/integer_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/ip_range.rb +20 -4
- data/lib/stretchy/attributes/type/range/long_range.rb +20 -4
- data/lib/stretchy/attributes/type/rank_feature.rb +16 -6
- data/lib/stretchy/attributes/type/rank_features.rb +27 -10
- data/lib/stretchy/attributes/type/search_as_you_type.rb +28 -18
- data/lib/stretchy/attributes/type/shape.rb +19 -9
- data/lib/stretchy/attributes/type/sparse_vector.rb +25 -21
- data/lib/stretchy/attributes/type/string.rb +42 -1
- data/lib/stretchy/attributes/type/text.rb +53 -28
- data/lib/stretchy/attributes/type/token_count.rb +21 -11
- data/lib/stretchy/attributes/type/version.rb +16 -6
- data/lib/stretchy/attributes/type/wildcard.rb +36 -25
- data/lib/stretchy/attributes.rb +30 -0
- data/lib/stretchy/delegation/gateway_delegation.rb +86 -2
- data/lib/stretchy/index_setting.rb +94 -0
- data/lib/stretchy/indexing/bulk.rb +75 -3
- data/lib/stretchy/machine_learning/model.rb +192 -0
- data/lib/stretchy/model/callbacks.rb +1 -0
- data/lib/stretchy/model/common.rb +157 -0
- data/lib/stretchy/model/persistence.rb +144 -0
- data/lib/stretchy/model/refreshable.rb +26 -0
- data/lib/stretchy/open_search_compatibility.rb +4 -0
- data/lib/stretchy/pipeline.rb +124 -0
- data/lib/stretchy/pipelines/processor.rb +57 -0
- data/lib/stretchy/querying.rb +7 -7
- data/lib/stretchy/rails/instrumentation/publishers.rb +31 -0
- data/lib/{rails → stretchy/rails}/instrumentation/railtie.rb +11 -6
- data/lib/stretchy/record.rb +5 -4
- data/lib/stretchy/relation.rb +230 -28
- data/lib/stretchy/relations/aggregation_methods/aggregation.rb +59 -0
- data/lib/stretchy/relations/aggregation_methods/avg.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_script.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_selector.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/bucket_sort.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/cardinality.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/children.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/composite.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/date_histogram.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/date_range.rb +53 -0
- data/lib/stretchy/relations/aggregation_methods/extended_stats.rb +48 -0
- data/lib/stretchy/relations/aggregation_methods/filter.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/filters.rb +47 -0
- data/lib/stretchy/relations/aggregation_methods/geo_bounds.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/geo_centroid.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/global.rb +39 -0
- data/lib/stretchy/relations/aggregation_methods/histogram.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/ip_range.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/max.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/min.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/missing.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/percentile_ranks.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/percentiles.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/range.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/reverse_nested.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/sampler.rb +40 -0
- data/lib/stretchy/relations/aggregation_methods/scripted_metric.rb +43 -0
- data/lib/stretchy/relations/aggregation_methods/significant_terms.rb +45 -0
- data/lib/stretchy/relations/aggregation_methods/stats.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/sum.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/terms.rb +46 -0
- data/lib/stretchy/relations/aggregation_methods/top_hits.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods/top_metrics.rb +44 -0
- data/lib/stretchy/relations/aggregation_methods/value_count.rb +41 -0
- data/lib/stretchy/relations/aggregation_methods/weighted_avg.rb +42 -0
- data/lib/stretchy/relations/aggregation_methods.rb +20 -749
- data/lib/stretchy/relations/finder_methods.rb +2 -18
- data/lib/stretchy/relations/null_relation.rb +55 -0
- data/lib/stretchy/relations/query_builder.rb +139 -23
- data/lib/stretchy/relations/query_methods/bind.rb +19 -0
- data/lib/stretchy/relations/query_methods/extending.rb +29 -0
- data/lib/stretchy/relations/query_methods/fields.rb +70 -0
- data/lib/stretchy/relations/query_methods/filter_query.rb +53 -0
- data/lib/stretchy/relations/query_methods/has_field.rb +40 -0
- data/lib/stretchy/relations/query_methods/highlight.rb +75 -0
- data/lib/stretchy/relations/query_methods/hybrid.rb +60 -0
- data/lib/stretchy/relations/query_methods/ids.rb +40 -0
- data/lib/stretchy/relations/query_methods/match.rb +52 -0
- data/lib/stretchy/relations/query_methods/must_not.rb +54 -0
- data/lib/stretchy/relations/query_methods/neural.rb +58 -0
- data/lib/stretchy/relations/query_methods/neural_sparse.rb +43 -0
- data/lib/stretchy/relations/query_methods/none.rb +21 -0
- data/lib/stretchy/relations/query_methods/or_filter.rb +21 -0
- data/lib/stretchy/relations/query_methods/order.rb +63 -0
- data/lib/stretchy/relations/query_methods/query_string.rb +44 -0
- data/lib/stretchy/relations/query_methods/regexp.rb +61 -0
- data/lib/stretchy/relations/query_methods/should.rb +51 -0
- data/lib/stretchy/relations/query_methods/size.rb +44 -0
- data/lib/stretchy/relations/query_methods/skip_callbacks.rb +47 -0
- data/lib/stretchy/relations/query_methods/source.rb +59 -0
- data/lib/stretchy/relations/query_methods/where.rb +113 -0
- data/lib/stretchy/relations/query_methods.rb +51 -540
- data/lib/stretchy/relations/scoping/default.rb +136 -0
- data/lib/stretchy/relations/scoping/named.rb +70 -0
- data/lib/stretchy/relations/scoping/scope_registry.rb +36 -0
- data/lib/stretchy/relations/scoping.rb +30 -0
- data/lib/stretchy/relations/search_option_methods.rb +2 -0
- data/lib/stretchy/shared_scopes.rb +6 -1
- data/lib/stretchy/version.rb +1 -1
- data/lib/stretchy.rb +23 -11
- metadata +147 -18
- data/lib/rails/instrumentation/publishers.rb +0 -29
- data/lib/stretchy/common.rb +0 -33
- data/lib/stretchy/null_relation.rb +0 -53
- data/lib/stretchy/persistence.rb +0 -43
- data/lib/stretchy/refreshable.rb +0 -15
- data/lib/stretchy/scoping/default.rb +0 -134
- data/lib/stretchy/scoping/named.rb +0 -68
- data/lib/stretchy/scoping/scope_registry.rb +0 -34
- 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
|