Skip to content

Commit 875cad1

Browse files
authored
Added K-NN APIs get_model, search_model, delete_model, train_model (#192)
* Added Knn APIs get_model, search_model, delete_model, train_model Signed-off-by: saimedhi <[email protected]> * Added Knn APIs get_model, search_model, delete_model, train_model Signed-off-by: saimedhi <[email protected]> * Added spec for k-NN apis Signed-off-by: saimedhi <[email protected]> * Added spec for k-NN apis Signed-off-by: saimedhi <[email protected]> --------- Signed-off-by: saimedhi <[email protected]>
1 parent 21b3e2b commit 875cad1

File tree

10 files changed

+382
-0
lines changed

10 files changed

+382
-0
lines changed

model/common_strings.smithy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ string PathTaskId
247247
@documentation("The name of the template.")
248248
string PathTemplateName
249249

250+
@pattern("^(?!_|template|query|field|point|clear|usage|stats|hot|reload|painless).+$")
251+
@documentation("The id of the model.")
252+
string PathModelId
253+
250254
@documentation("The analyzer to use for the query string.")
251255
string Analyzer
252256

@@ -281,6 +285,9 @@ string Lang
281285
@documentation("Comma-separated list of the persistent ids of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_names.")
282286
string NodeIds
283287

288+
@documentation("Preferred node to execute training.")
289+
string NodeId
290+
284291
@documentation("Comma-separated list of the names of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_ids.")
285292
string NodeNames
286293

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@externalDocumentation(
11+
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#delete-model"
12+
)
13+
14+
@xOperationGroup("knn.delete_model")
15+
@xVersionAdded("1.0")
16+
@suppress(["HttpMethodSemantics.UnexpectedPayload"])
17+
@suppress(["HttpUriConflict"])
18+
@http(method: "DELETE", uri: "/_plugins/_knn/models/{model_id}")
19+
@documentation("Used to delete a particular model in the cluster.")
20+
operation KNNDeleteModel {
21+
input: KNNDeleteModel_Input,
22+
output: KNNDeleteModel_Output
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@input
11+
structure KNNDeleteModel_Input {
12+
@required
13+
@httpLabel
14+
model_id: PathModelId,
15+
}
16+
17+
// TODO: Fill in Output Structure
18+
structure KNNDeleteModel_Output {}

model/knn/get_model/operations.smithy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@externalDocumentation(
11+
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#get-model"
12+
)
13+
14+
@xOperationGroup("knn.get_model")
15+
@xVersionAdded("1.0")
16+
@readonly
17+
@suppress(["HttpUriConflict"])
18+
@http(method: "GET", uri: "/_plugins/_knn/models/{model_id}")
19+
@documentation("Used to retrieve information about models present in the cluster.")
20+
operation KNNGetModel {
21+
input: KNNGetModel_Input,
22+
output: KNNGetModel_Output
23+
}

model/knn/get_model/structures.smithy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@input
11+
structure KNNGetModel_Input {
12+
@required
13+
@httpLabel
14+
model_id: PathModelId,
15+
}
16+
17+
// TODO: Fill in Output Structure
18+
structure KNNGetModel_Output {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@externalDocumentation(
11+
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#search-model"
12+
)
13+
14+
@xOperationGroup("knn.search_models")
15+
@xVersionAdded("1.0")
16+
@readonly
17+
@suppress(["HttpUriConflict"])
18+
@http(method: "GET", uri: "/_plugins/_knn/models/_search")
19+
@documentation("Use an OpenSearch query to search for models in the index.")
20+
operation KNNSearchModels_Get {
21+
input: KNNSearchModels_Get_Input,
22+
output: KNNSearchModels_Output
23+
}
24+
25+
@xOperationGroup("knn.search_models")
26+
@xVersionAdded("1.0")
27+
@suppress(["HttpUriConflict"])
28+
@http(method: "POST", uri: "/_plugins/_knn/models/_search")
29+
@documentation("Use an OpenSearch query to search for models in the index.")
30+
operation KNNSearchModels_Post {
31+
input: KNNSearchModels_Post_Input,
32+
output: KNNSearchModels_Output
33+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@mixin
11+
structure KNNSearchModels_QueryParams {
12+
@httpQuery("analyzer")
13+
analyzer: Analyzer,
14+
15+
@httpQuery("analyze_wildcard")
16+
@default(false)
17+
analyze_wildcard: AnalyzeWildcard,
18+
19+
@httpQuery("ccs_minimize_roundtrips")
20+
@default(true)
21+
ccs_minimize_roundtrips: CcsMinimizeRoundtrips,
22+
23+
@httpQuery("default_operator")
24+
@default("OR")
25+
default_operator: DefaultOperator,
26+
27+
@httpQuery("df")
28+
df: Df,
29+
30+
@httpQuery("explain")
31+
@documentation("Specify whether to return detailed information about score computation as part of a hit.")
32+
explain: Explain,
33+
34+
@httpQuery("stored_fields")
35+
stored_fields: StoredFields,
36+
37+
@httpQuery("docvalue_fields")
38+
docvalue_fields: DocvalueFields,
39+
40+
@httpQuery("from")
41+
@default(0)
42+
from: From,
43+
44+
@httpQuery("ignore_unavailable")
45+
ignore_unavailable: IgnoreUnavailable,
46+
47+
@httpQuery("ignore_throttled")
48+
ignore_throttled: IgnoreThrottled,
49+
50+
@httpQuery("allow_no_indices")
51+
allow_no_indices: AllowNoIndices,
52+
53+
@httpQuery("expand_wildcards")
54+
@default("open")
55+
expand_wildcards: ExpandWildcards,
56+
57+
@httpQuery("lenient")
58+
lenient: Lenient,
59+
60+
@httpQuery("preference")
61+
@default("random")
62+
preference: Preference,
63+
64+
@httpQuery("q")
65+
q: Q,
66+
67+
@httpQuery("routing")
68+
routing: Routings,
69+
70+
@httpQuery("scroll")
71+
scroll: Scroll,
72+
73+
@httpQuery("search_type")
74+
search_type: SearchType,
75+
76+
@httpQuery("size")
77+
@documentation("Number of hits to return.")
78+
@default(10)
79+
size: Size,
80+
81+
@httpQuery("sort")
82+
sort: Sort,
83+
84+
@httpQuery("_source")
85+
_source: Source,
86+
87+
@httpQuery("_source_excludes")
88+
_source_excludes: SourceExcludes,
89+
90+
@httpQuery("_source_includes")
91+
_source_includes: SourceIncludes,
92+
93+
@httpQuery("terminate_after")
94+
terminate_after: TerminateAfter,
95+
96+
@httpQuery("stats")
97+
stats: Stats,
98+
99+
@httpQuery("suggest_field")
100+
suggest_field: SuggestField,
101+
102+
@httpQuery("suggest_mode")
103+
@default("missing")
104+
suggest_mode: SuggestMode,
105+
106+
@httpQuery("suggest_size")
107+
suggest_size: SuggestSize,
108+
109+
@httpQuery("suggest_text")
110+
suggest_text: SuggestText,
111+
112+
@httpQuery("timeout")
113+
timeout: Timeout,
114+
115+
@httpQuery("track_scores")
116+
track_scores: TrackScores,
117+
118+
@httpQuery("track_total_hits")
119+
track_total_hits: TrackTotalHits,
120+
121+
@httpQuery("allow_partial_search_results")
122+
@default(true)
123+
allow_partial_search_results: AllowPartialSearchResults,
124+
125+
@httpQuery("typed_keys")
126+
typed_keys: TypedKeys,
127+
128+
@httpQuery("version")
129+
version: WithVersion,
130+
131+
@httpQuery("seq_no_primary_term")
132+
seq_no_primary_term: SeqNoPrimaryTerm,
133+
134+
@httpQuery("request_cache")
135+
request_cache: RequestCache,
136+
137+
@httpQuery("batched_reduce_size")
138+
@default(512)
139+
batched_reduce_size: BatchedReduceSize,
140+
141+
@httpQuery("max_concurrent_shard_requests")
142+
@documentation("The number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests.")
143+
@default(5)
144+
max_concurrent_shard_requests: MaxConcurrentShardRequests,
145+
146+
@httpQuery("pre_filter_shard_size")
147+
pre_filter_shard_size: PreFilterShardSize,
148+
149+
@httpQuery("rest_total_hits_as_int")
150+
@default(false)
151+
rest_total_hits_as_int: RestTotalHitsAsInt,
152+
}
153+
154+
// TODO: Fill in Body Parameters
155+
structure KNNSearchModels_BodyParams {}
156+
157+
@input
158+
structure KNNSearchModels_Get_Input with [KNNSearchModels_QueryParams] {}
159+
160+
@input
161+
structure KNNSearchModels_Post_Input with [KNNSearchModels_QueryParams] {
162+
@httpPayload
163+
content: KNNSearchModels_BodyParams,
164+
}
165+
166+
// TODO: Fill in Output Structure
167+
structure KNNSearchModels_Output {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@externalDocumentation(
11+
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#train-model"
12+
)
13+
14+
@xOperationGroup("knn.train_model")
15+
@xVersionAdded("1.0")
16+
@suppress(["HttpUriConflict"])
17+
@http(method: "POST", uri: "/_plugins/_knn/models/_train")
18+
@documentation("Create and train a model that can be used for initializing k-NN native library indexes during indexing.")
19+
operation KNNTrainModel {
20+
input: KNNTrainModel_Input,
21+
output: KNNTrainModel_Output
22+
}
23+
24+
@xOperationGroup("knn.train_model")
25+
@xVersionAdded("1.0")
26+
@suppress(["HttpUriConflict"])
27+
@http(method: "POST", uri: "/_plugins/_knn/models/{model_id}/_train")
28+
@documentation("Create and train a model that can be used for initializing k-NN native library indexes during indexing.")
29+
operation KNNTrainModel_WithModelId {
30+
input: KNNTrainModel_WithModelId_Input,
31+
output: KNNTrainModel_Output
32+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
//
3+
// The OpenSearch Contributors require contributions made to
4+
// this file be licensed under the Apache-2.0 license or a
5+
// compatible open source license.
6+
7+
$version: "2"
8+
namespace OpenSearch
9+
10+
@mixin
11+
structure KNNTrainModel_QueryParams {
12+
@httpQuery("preference")
13+
preference: NodeId,
14+
}
15+
16+
structure KNNTrainModel_BodyParams {
17+
@required
18+
training_index: String,
19+
20+
@required
21+
training_field: String,
22+
23+
@required
24+
dimension: Integer,
25+
26+
max_training_vector_count: Integer,
27+
28+
search_size: Integer,
29+
30+
description: String,
31+
32+
@required
33+
method: String,
34+
}
35+
36+
@input
37+
structure KNNTrainModel_Input with [KNNTrainModel_QueryParams] {
38+
@required
39+
@httpPayload
40+
content: KNNTrainModel_BodyParams,
41+
}
42+
43+
@input
44+
structure KNNTrainModel_WithModelId_Input with [KNNTrainModel_QueryParams] {
45+
@required
46+
@httpPayload
47+
content: KNNTrainModel_BodyParams,
48+
49+
@required
50+
@httpLabel
51+
model_id: PathModelId,
52+
}
53+
54+
// TODO: Fill in Output Structure
55+
structure KNNTrainModel_Output {}

0 commit comments

Comments
 (0)