|
| 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 | +# Modifications Copyright OpenSearch Contributors. See |
| 8 | +# GitHub history for details. |
| 9 | + |
| 10 | +# ------------------------------------------------------------------------------------------ |
| 11 | +# THIS CODE IS AUTOMATICALLY GENERATED AND MANUAL EDITS WILL BE LOST |
| 12 | +# |
| 13 | +# To contribute, kindly make modifications in the opensearch-py client generator |
| 14 | +# or in the OpenSearch API specification, and run `nox -rs generate`. See DEVELOPER_GUIDE.md |
| 15 | +# and https://github.com/opensearch-project/opensearch-api-specification for details. |
| 16 | +# -----------------------------------------------------------------------------------------+ |
| 17 | + |
| 18 | + |
| 19 | +from typing import Any |
| 20 | + |
| 21 | +from ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params |
| 22 | + |
| 23 | + |
| 24 | +class KnnClient(NamespacedClient): |
| 25 | + @query_params() |
| 26 | + async def delete_model( |
| 27 | + self, |
| 28 | + model_id: Any, |
| 29 | + params: Any = None, |
| 30 | + headers: Any = None, |
| 31 | + ) -> Any: |
| 32 | + """ |
| 33 | + Used to delete a particular model in the cluster. |
| 34 | +
|
| 35 | +
|
| 36 | + :arg model_id: The id of the model. |
| 37 | + """ |
| 38 | + if model_id in SKIP_IN_PATH: |
| 39 | + raise ValueError("Empty value passed for a required argument 'model_id'.") |
| 40 | + |
| 41 | + return await self.transport.perform_request( |
| 42 | + "DELETE", |
| 43 | + _make_path("_plugins", "_knn", "models", model_id), |
| 44 | + params=params, |
| 45 | + headers=headers, |
| 46 | + ) |
| 47 | + |
| 48 | + @query_params() |
| 49 | + async def get_model( |
| 50 | + self, |
| 51 | + model_id: Any, |
| 52 | + params: Any = None, |
| 53 | + headers: Any = None, |
| 54 | + ) -> Any: |
| 55 | + """ |
| 56 | + Used to retrieve information about models present in the cluster. |
| 57 | +
|
| 58 | +
|
| 59 | + :arg model_id: The id of the model. |
| 60 | + """ |
| 61 | + if model_id in SKIP_IN_PATH: |
| 62 | + raise ValueError("Empty value passed for a required argument 'model_id'.") |
| 63 | + |
| 64 | + return await self.transport.perform_request( |
| 65 | + "GET", |
| 66 | + _make_path("_plugins", "_knn", "models", model_id), |
| 67 | + params=params, |
| 68 | + headers=headers, |
| 69 | + ) |
| 70 | + |
| 71 | + @query_params( |
| 72 | + "_source", |
| 73 | + "_source_excludes", |
| 74 | + "_source_includes", |
| 75 | + "allow_no_indices", |
| 76 | + "allow_partial_search_results", |
| 77 | + "analyze_wildcard", |
| 78 | + "analyzer", |
| 79 | + "batched_reduce_size", |
| 80 | + "ccs_minimize_roundtrips", |
| 81 | + "default_operator", |
| 82 | + "df", |
| 83 | + "docvalue_fields", |
| 84 | + "expand_wildcards", |
| 85 | + "explain", |
| 86 | + "from_", |
| 87 | + "ignore_throttled", |
| 88 | + "ignore_unavailable", |
| 89 | + "lenient", |
| 90 | + "max_concurrent_shard_requests", |
| 91 | + "pre_filter_shard_size", |
| 92 | + "preference", |
| 93 | + "q", |
| 94 | + "request_cache", |
| 95 | + "rest_total_hits_as_int", |
| 96 | + "routing", |
| 97 | + "scroll", |
| 98 | + "search_type", |
| 99 | + "seq_no_primary_term", |
| 100 | + "size", |
| 101 | + "sort", |
| 102 | + "stats", |
| 103 | + "stored_fields", |
| 104 | + "suggest_field", |
| 105 | + "suggest_mode", |
| 106 | + "suggest_size", |
| 107 | + "suggest_text", |
| 108 | + "terminate_after", |
| 109 | + "timeout", |
| 110 | + "track_scores", |
| 111 | + "track_total_hits", |
| 112 | + "typed_keys", |
| 113 | + "version", |
| 114 | + ) |
| 115 | + async def search_models( |
| 116 | + self, |
| 117 | + body: Any = None, |
| 118 | + params: Any = None, |
| 119 | + headers: Any = None, |
| 120 | + ) -> Any: |
| 121 | + """ |
| 122 | + Use an OpenSearch query to search for models in the index. |
| 123 | +
|
| 124 | +
|
| 125 | + :arg _source: True or false to return the _source field or not, |
| 126 | + or a list of fields to return. |
| 127 | + :arg _source_excludes: List of fields to exclude from the |
| 128 | + returned _source field. |
| 129 | + :arg _source_includes: List of fields to extract and return from |
| 130 | + the _source field. |
| 131 | + :arg allow_no_indices: Whether to ignore if a wildcard indices |
| 132 | + expression resolves into no concrete indices. (This includes `_all` |
| 133 | + string or when no indices have been specified). |
| 134 | + :arg allow_partial_search_results: Indicate if an error should |
| 135 | + be returned if there is a partial search failure or timeout. Default is |
| 136 | + True. |
| 137 | + :arg analyze_wildcard: Specify whether wildcard and prefix |
| 138 | + queries should be analyzed. Default is false. |
| 139 | + :arg analyzer: The analyzer to use for the query string. |
| 140 | + :arg batched_reduce_size: The number of shard results that |
| 141 | + should be reduced at once on the coordinating node. This value should be |
| 142 | + used as a protection mechanism to reduce the memory overhead per search |
| 143 | + request if the potential number of shards in the request can be large. |
| 144 | + Default is 512. |
| 145 | + :arg ccs_minimize_roundtrips: Indicates whether network round- |
| 146 | + trips should be minimized as part of cross-cluster search requests |
| 147 | + execution. Default is True. |
| 148 | + :arg default_operator: The default operator for query string |
| 149 | + query (AND or OR). Valid choices are AND, OR. |
| 150 | + :arg df: The field to use as default where no field prefix is |
| 151 | + given in the query string. |
| 152 | + :arg docvalue_fields: Comma-separated list of fields to return |
| 153 | + as the docvalue representation of a field for each hit. |
| 154 | + :arg expand_wildcards: Whether to expand wildcard expression to |
| 155 | + concrete indices that are open, closed or both. Valid choices are all, |
| 156 | + open, closed, hidden, none. |
| 157 | + :arg explain: Specify whether to return detailed information |
| 158 | + about score computation as part of a hit. |
| 159 | + :arg from_: Starting offset. Default is 0. |
| 160 | + :arg ignore_throttled: Whether specified concrete, expanded or |
| 161 | + aliased indices should be ignored when throttled. |
| 162 | + :arg ignore_unavailable: Whether specified concrete indices |
| 163 | + should be ignored when unavailable (missing or closed). |
| 164 | + :arg lenient: Specify whether format-based query failures (such |
| 165 | + as providing text to a numeric field) should be ignored. |
| 166 | + :arg max_concurrent_shard_requests: The number of concurrent |
| 167 | + shard requests per node this search executes concurrently. This value |
| 168 | + should be used to limit the impact of the search on the cluster in order |
| 169 | + to limit the number of concurrent shard requests. Default is 5. |
| 170 | + :arg pre_filter_shard_size: Threshold that enforces a pre-filter |
| 171 | + round-trip to prefilter search shards based on query rewriting if the |
| 172 | + number of shards the search request expands to exceeds the threshold. |
| 173 | + This filter round-trip can limit the number of shards significantly if |
| 174 | + for instance a shard can not match any documents based on its rewrite |
| 175 | + method ie. if date filters are mandatory to match but the shard bounds |
| 176 | + and the query are disjoint. |
| 177 | + :arg preference: Specify the node or shard the operation should |
| 178 | + be performed on. Default is random. |
| 179 | + :arg q: Query in the Lucene query string syntax. |
| 180 | + :arg request_cache: Specify if request cache should be used for |
| 181 | + this request or not, defaults to index level setting. |
| 182 | + :arg rest_total_hits_as_int: Indicates whether hits.total should |
| 183 | + be rendered as an integer or an object in the rest search response. |
| 184 | + Default is false. |
| 185 | + :arg routing: Comma-separated list of specific routing values. |
| 186 | + :arg scroll: Specify how long a consistent view of the index |
| 187 | + should be maintained for scrolled search. |
| 188 | + :arg search_type: Search operation type. Valid choices are |
| 189 | + query_then_fetch, dfs_query_then_fetch. |
| 190 | + :arg seq_no_primary_term: Specify whether to return sequence |
| 191 | + number and primary term of the last modification of each hit. |
| 192 | + :arg size: Number of hits to return. Default is 10. |
| 193 | + :arg sort: Comma-separated list of <field>:<direction> pairs. |
| 194 | + :arg stats: Specific 'tag' of the request for logging and |
| 195 | + statistical purposes. |
| 196 | + :arg stored_fields: Comma-separated list of stored fields to |
| 197 | + return. |
| 198 | + :arg suggest_field: Specify which field to use for suggestions. |
| 199 | + :arg suggest_mode: Specify suggest mode. Valid choices are |
| 200 | + missing, popular, always. |
| 201 | + :arg suggest_size: How many suggestions to return in response. |
| 202 | + :arg suggest_text: The source text for which the suggestions |
| 203 | + should be returned. |
| 204 | + :arg terminate_after: The maximum number of documents to collect |
| 205 | + for each shard, upon reaching which the query execution will terminate |
| 206 | + early. |
| 207 | + :arg timeout: Operation timeout. |
| 208 | + :arg track_scores: Whether to calculate and return scores even |
| 209 | + if they are not used for sorting. |
| 210 | + :arg track_total_hits: Indicate if the number of documents that |
| 211 | + match the query should be tracked. |
| 212 | + :arg typed_keys: Specify whether aggregation and suggester names |
| 213 | + should be prefixed by their respective types in the response. |
| 214 | + :arg version: Whether to return document version as part of a |
| 215 | + hit. |
| 216 | + """ |
| 217 | + # from is a reserved word so it cannot be used, use from_ instead |
| 218 | + if "from_" in params: |
| 219 | + params["from"] = params.pop("from_") |
| 220 | + |
| 221 | + return await self.transport.perform_request( |
| 222 | + "POST", |
| 223 | + "/_plugins/_knn/models/_search", |
| 224 | + params=params, |
| 225 | + headers=headers, |
| 226 | + body=body, |
| 227 | + ) |
| 228 | + |
| 229 | + @query_params("timeout") |
| 230 | + async def stats( |
| 231 | + self, |
| 232 | + node_id: Any = None, |
| 233 | + stat: Any = None, |
| 234 | + params: Any = None, |
| 235 | + headers: Any = None, |
| 236 | + ) -> Any: |
| 237 | + """ |
| 238 | + Provides information about the current status of the k-NN plugin. |
| 239 | +
|
| 240 | +
|
| 241 | + :arg node_id: Comma-separated list of node IDs or names to limit |
| 242 | + the returned information; use `_local` to return information from the |
| 243 | + node you're connecting to, leave empty to get information from all |
| 244 | + nodes. |
| 245 | + :arg stat: Comma-separated list of stats to retrieve; use `_all` |
| 246 | + or empty string to retrieve all stats. Valid choices are |
| 247 | + circuit_breaker_triggered, total_load_time, eviction_count, hit_count, |
| 248 | + miss_count, graph_memory_usage, graph_memory_usage_percentage, |
| 249 | + graph_index_requests, graph_index_errors, graph_query_requests, |
| 250 | + graph_query_errors, knn_query_requests, cache_capacity_reached, |
| 251 | + load_success_count, load_exception_count, indices_in_cache, |
| 252 | + script_compilations, script_compilation_errors, script_query_requests, |
| 253 | + script_query_errors, nmslib_initialized, faiss_initialized, |
| 254 | + model_index_status, indexing_from_model_degraded, training_requests, |
| 255 | + training_errors, training_memory_usage, |
| 256 | + training_memory_usage_percentage. |
| 257 | + :arg timeout: Operation timeout. |
| 258 | + """ |
| 259 | + return await self.transport.perform_request( |
| 260 | + "GET", |
| 261 | + _make_path("_plugins", "_knn", node_id, "stats", stat), |
| 262 | + params=params, |
| 263 | + headers=headers, |
| 264 | + ) |
| 265 | + |
| 266 | + @query_params("preference") |
| 267 | + async def train_model( |
| 268 | + self, |
| 269 | + body: Any, |
| 270 | + model_id: Any = None, |
| 271 | + params: Any = None, |
| 272 | + headers: Any = None, |
| 273 | + ) -> Any: |
| 274 | + """ |
| 275 | + Create and train a model that can be used for initializing k-NN native library |
| 276 | + indexes during indexing. |
| 277 | +
|
| 278 | +
|
| 279 | + :arg model_id: The id of the model. |
| 280 | + :arg preference: Preferred node to execute training. |
| 281 | + """ |
| 282 | + if body in SKIP_IN_PATH: |
| 283 | + raise ValueError("Empty value passed for a required argument 'body'.") |
| 284 | + |
| 285 | + return await self.transport.perform_request( |
| 286 | + "POST", |
| 287 | + _make_path("_plugins", "_knn", "models", model_id, "_train"), |
| 288 | + params=params, |
| 289 | + headers=headers, |
| 290 | + body=body, |
| 291 | + ) |
| 292 | + |
| 293 | + @query_params() |
| 294 | + async def warmup( |
| 295 | + self, |
| 296 | + index: Any, |
| 297 | + params: Any = None, |
| 298 | + headers: Any = None, |
| 299 | + ) -> Any: |
| 300 | + """ |
| 301 | + Preloads native library files into memory, reducing initial search latency for |
| 302 | + specified indexes |
| 303 | +
|
| 304 | +
|
| 305 | + :arg index: Comma-separated list of indices; use `_all` or empty |
| 306 | + string to perform the operation on all indices. |
| 307 | + """ |
| 308 | + if index in SKIP_IN_PATH: |
| 309 | + raise ValueError("Empty value passed for a required argument 'index'.") |
| 310 | + |
| 311 | + return await self.transport.perform_request( |
| 312 | + "GET", |
| 313 | + _make_path("_plugins", "_knn", "warmup", index), |
| 314 | + params=params, |
| 315 | + headers=headers, |
| 316 | + ) |
0 commit comments