Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added K-NN APIs get_model, search_model, delete_model, train_model #192

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions model/common_strings.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ string PathTaskId
@documentation("The name of the template.")
string PathTemplateName

@pattern("^(?!_|template|query|field|point|clear|usage|stats|hot|reload|painless).+$")
@documentation("The id of the model.")
string PathModelId

@documentation("The analyzer to use for the query string.")
string Analyzer

Expand Down Expand Up @@ -281,6 +285,9 @@ string Lang
@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.")
string NodeIds

@documentation("Preferred node to execute training.")
string NodeId

@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.")
string NodeNames

Expand Down
23 changes: 23 additions & 0 deletions model/knn/delete_model/operations.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@externalDocumentation(
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#delete-model"
)

@xOperationGroup("knn.delete_model")
@xVersionAdded("1.0")
@suppress(["HttpMethodSemantics.UnexpectedPayload"])
@suppress(["HttpUriConflict"])
@http(method: "DELETE", uri: "/_plugins/_knn/models/{model_id}")
@documentation("Used to delete a particular model in the cluster.")
operation KNNDeleteModel {
input: KNNDeleteModel_Input,
output: KNNDeleteModel_Output
}
18 changes: 18 additions & 0 deletions model/knn/delete_model/structures.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@input
structure KNNDeleteModel_Input {
@required
@httpLabel
model_id: PathModelId,
}

// TODO: Fill in Output Structure
structure KNNDeleteModel_Output {}
23 changes: 23 additions & 0 deletions model/knn/get_model/operations.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@externalDocumentation(
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#get-model"
)

@xOperationGroup("knn.get_model")
@xVersionAdded("1.0")
@readonly
@suppress(["HttpUriConflict"])
@http(method: "GET", uri: "/_plugins/_knn/models/{model_id}")
@documentation("Used to retrieve information about models present in the cluster.")
operation KNNGetModel {
input: KNNGetModel_Input,
output: KNNGetModel_Output
}
18 changes: 18 additions & 0 deletions model/knn/get_model/structures.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@input
structure KNNGetModel_Input {
@required
@httpLabel
model_id: PathModelId,
}

// TODO: Fill in Output Structure
structure KNNGetModel_Output {}
33 changes: 33 additions & 0 deletions model/knn/search_model/operations.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@externalDocumentation(
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#search-model"
)

@xOperationGroup("knn.search_models")
@xVersionAdded("1.0")
@readonly
@suppress(["HttpUriConflict"])
@http(method: "GET", uri: "/_plugins/_knn/models/_search")
@documentation("Use an OpenSearch query to search for models in the index.")
operation KNNSearchModels_Get {
input: KNNSearchModels_Get_Input,
output: KNNSearchModels_Output
}

@xOperationGroup("knn.search_models")
@xVersionAdded("1.0")
@suppress(["HttpUriConflict"])
@http(method: "POST", uri: "/_plugins/_knn/models/_search")
@documentation("Use an OpenSearch query to search for models in the index.")
operation KNNSearchModels_Post {
input: KNNSearchModels_Post_Input,
output: KNNSearchModels_Output
}
167 changes: 167 additions & 0 deletions model/knn/search_model/structures.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@mixin
structure KNNSearchModels_QueryParams {
@httpQuery("analyzer")
analyzer: Analyzer,

@httpQuery("analyze_wildcard")
@default(false)
analyze_wildcard: AnalyzeWildcard,

@httpQuery("ccs_minimize_roundtrips")
@default(true)
ccs_minimize_roundtrips: CcsMinimizeRoundtrips,

@httpQuery("default_operator")
@default("OR")
default_operator: DefaultOperator,

@httpQuery("df")
df: Df,

@httpQuery("explain")
@documentation("Specify whether to return detailed information about score computation as part of a hit.")
explain: Explain,

@httpQuery("stored_fields")
stored_fields: StoredFields,

@httpQuery("docvalue_fields")
docvalue_fields: DocvalueFields,

@httpQuery("from")
@default(0)
from: From,

@httpQuery("ignore_unavailable")
ignore_unavailable: IgnoreUnavailable,

@httpQuery("ignore_throttled")
ignore_throttled: IgnoreThrottled,

@httpQuery("allow_no_indices")
allow_no_indices: AllowNoIndices,

@httpQuery("expand_wildcards")
@default("open")
expand_wildcards: ExpandWildcards,

@httpQuery("lenient")
lenient: Lenient,

@httpQuery("preference")
@default("random")
preference: Preference,

@httpQuery("q")
q: Q,

@httpQuery("routing")
routing: Routings,

@httpQuery("scroll")
scroll: Scroll,

@httpQuery("search_type")
search_type: SearchType,

@httpQuery("size")
@documentation("Number of hits to return.")
@default(10)
size: Size,

@httpQuery("sort")
sort: Sort,

@httpQuery("_source")
_source: Source,

@httpQuery("_source_excludes")
_source_excludes: SourceExcludes,

@httpQuery("_source_includes")
_source_includes: SourceIncludes,

@httpQuery("terminate_after")
terminate_after: TerminateAfter,

@httpQuery("stats")
stats: Stats,

@httpQuery("suggest_field")
suggest_field: SuggestField,

@httpQuery("suggest_mode")
@default("missing")
suggest_mode: SuggestMode,

@httpQuery("suggest_size")
suggest_size: SuggestSize,

@httpQuery("suggest_text")
suggest_text: SuggestText,

@httpQuery("timeout")
timeout: Timeout,

@httpQuery("track_scores")
track_scores: TrackScores,

@httpQuery("track_total_hits")
track_total_hits: TrackTotalHits,

@httpQuery("allow_partial_search_results")
@default(true)
allow_partial_search_results: AllowPartialSearchResults,

@httpQuery("typed_keys")
typed_keys: TypedKeys,

@httpQuery("version")
version: WithVersion,

@httpQuery("seq_no_primary_term")
seq_no_primary_term: SeqNoPrimaryTerm,

@httpQuery("request_cache")
request_cache: RequestCache,

@httpQuery("batched_reduce_size")
@default(512)
batched_reduce_size: BatchedReduceSize,

@httpQuery("max_concurrent_shard_requests")
@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.")
@default(5)
max_concurrent_shard_requests: MaxConcurrentShardRequests,

@httpQuery("pre_filter_shard_size")
pre_filter_shard_size: PreFilterShardSize,

@httpQuery("rest_total_hits_as_int")
@default(false)
rest_total_hits_as_int: RestTotalHitsAsInt,
}

// TODO: Fill in Body Parameters
structure KNNSearchModels_BodyParams {}

@input
structure KNNSearchModels_Get_Input with [KNNSearchModels_QueryParams] {}

@input
structure KNNSearchModels_Post_Input with [KNNSearchModels_QueryParams] {
@httpPayload
content: KNNSearchModels_BodyParams,
}

// TODO: Fill in Output Structure
structure KNNSearchModels_Output {}
32 changes: 32 additions & 0 deletions model/knn/train_model/operations.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@externalDocumentation(
"API Reference": "https://opensearch.org/docs/latest/search-plugins/knn/api/#train-model"
)

@xOperationGroup("knn.train_model")
@xVersionAdded("1.0")
@suppress(["HttpUriConflict"])
@http(method: "POST", uri: "/_plugins/_knn/models/_train")
@documentation("Create and train a model that can be used for initializing k-NN native library indexes during indexing.")
operation KNNTrainModel {
input: KNNTrainModel_Input,
output: KNNTrainModel_Output
}

@xOperationGroup("knn.train_model")
@xVersionAdded("1.0")
@suppress(["HttpUriConflict"])
@http(method: "POST", uri: "/_plugins/_knn/models/{model_id}/_train")
@documentation("Create and train a model that can be used for initializing k-NN native library indexes during indexing.")
operation KNNTrainModel_WithModelId {
input: KNNTrainModel_WithModelId_Input,
output: KNNTrainModel_Output
}
55 changes: 55 additions & 0 deletions model/knn/train_model/structures.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: Apache-2.0
//
// The OpenSearch Contributors require contributions made to
// this file be licensed under the Apache-2.0 license or a
// compatible open source license.

$version: "2"
namespace OpenSearch

@mixin
structure KNNTrainModel_QueryParams {
@httpQuery("preference")
preference: NodeId,
}

structure KNNTrainModel_BodyParams {
@required
training_index: String,

@required
training_field: String,

@required
dimension: Integer,

max_training_vector_count: Integer,

search_size: Integer,

description: String,

@required
method: String,
}

@input
structure KNNTrainModel_Input with [KNNTrainModel_QueryParams] {
@required
@httpPayload
content: KNNTrainModel_BodyParams,
}

@input
structure KNNTrainModel_WithModelId_Input with [KNNTrainModel_QueryParams] {
@required
@httpPayload
content: KNNTrainModel_BodyParams,

@required
@httpLabel
model_id: PathModelId,
}

// TODO: Fill in Output Structure
structure KNNTrainModel_Output {}
Loading
Loading