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

Updated opensearch-py to reflect the latest OpenSearch API spec #702

Merged
merged 1 commit into from
Mar 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fix KeyError when scroll return no hits ([#616](https://github.com/opensearch-project/opensearch-py/pull/616))
- Fix reuse of `OpenSearch` using `Urllib3HttpConnection` and `AsyncOpenSearch` after calling `close` ([#639](https://github.com/opensearch-project/opensearch-py/pull/639))
### Updated APIs
- Updated opensearch-py APIs to reflect [opensearch-api-specification@3763fdd](https://github.com/opensearch-project/opensearch-api-specification/commit/3763fdd051889c26e4f865734501c483d429de9f)
- Updated opensearch-py APIs to reflect [opensearch-api-specification@1787056](https://github.com/opensearch-project/opensearch-api-specification/commit/178705681e5fd812ab59ad00cefa04146d03d7ad)
### Security
### Dependencies
Expand Down
2 changes: 2 additions & 0 deletions opensearchpy/_async/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ..plugins.alerting import AlertingClient
from ..plugins.index_management import IndexManagementClient
from ..plugins.knn import KnnClient
from .client import Client
from .utils import NamespacedClient

Expand All @@ -22,6 +23,7 @@ class PluginsClient(NamespacedClient):

def __init__(self, client: Client) -> None:
super(PluginsClient, self).__init__(client)
self.knn = KnnClient(client)
# self.query_workbench = QueryWorkbenchClient(client)
# self.reporting = ReportingClient(client)
# self.notebooks = NotebooksClient(client)
Expand Down
316 changes: 316 additions & 0 deletions opensearchpy/_async/plugins/knn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
# 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.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

# ------------------------------------------------------------------------------------------
# THIS CODE IS AUTOMATICALLY GENERATED AND MANUAL EDITS WILL BE LOST
#
# To contribute, kindly make modifications in the opensearch-py client generator
# or in the OpenSearch API specification, and run `nox -rs generate`. See DEVELOPER_GUIDE.md
# and https://github.com/opensearch-project/opensearch-api-specification for details.
# -----------------------------------------------------------------------------------------+


from typing import Any

from ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params


class KnnClient(NamespacedClient):
@query_params()
async def delete_model(
self,
model_id: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Used to delete a particular model in the cluster.


:arg model_id: The id of the model.
"""
if model_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'model_id'.")

Check warning on line 39 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L38-L39

Added lines #L38 - L39 were not covered by tests

return await self.transport.perform_request(

Check warning on line 41 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L41

Added line #L41 was not covered by tests
"DELETE",
_make_path("_plugins", "_knn", "models", model_id),
params=params,
headers=headers,
)

@query_params()
async def get_model(
self,
model_id: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Used to retrieve information about models present in the cluster.


:arg model_id: The id of the model.
"""
if model_id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'model_id'.")

Check warning on line 62 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L61-L62

Added lines #L61 - L62 were not covered by tests

return await self.transport.perform_request(

Check warning on line 64 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L64

Added line #L64 was not covered by tests
"GET",
_make_path("_plugins", "_knn", "models", model_id),
params=params,
headers=headers,
)

@query_params(
"_source",
"_source_excludes",
"_source_includes",
"allow_no_indices",
"allow_partial_search_results",
"analyze_wildcard",
"analyzer",
"batched_reduce_size",
"ccs_minimize_roundtrips",
"default_operator",
"df",
"docvalue_fields",
"expand_wildcards",
"explain",
"from_",
"ignore_throttled",
"ignore_unavailable",
"lenient",
"max_concurrent_shard_requests",
"pre_filter_shard_size",
"preference",
"q",
"request_cache",
"rest_total_hits_as_int",
"routing",
"scroll",
"search_type",
"seq_no_primary_term",
"size",
"sort",
"stats",
"stored_fields",
"suggest_field",
"suggest_mode",
"suggest_size",
"suggest_text",
"terminate_after",
"timeout",
"track_scores",
"track_total_hits",
"typed_keys",
"version",
)
async def search_models(
self,
body: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Use an OpenSearch query to search for models in the index.


:arg _source: True or false to return the _source field or not,
or a list of fields to return.
:arg _source_excludes: List of fields to exclude from the
returned _source field.
:arg _source_includes: List of fields to extract and return from
the _source field.
:arg allow_no_indices: Whether to ignore if a wildcard indices
expression resolves into no concrete indices. (This includes `_all`
string or when no indices have been specified).
:arg allow_partial_search_results: Indicate if an error should
be returned if there is a partial search failure or timeout. Default is
True.
:arg analyze_wildcard: Specify whether wildcard and prefix
queries should be analyzed. Default is false.
:arg analyzer: The analyzer to use for the query string.
:arg batched_reduce_size: The number of shard results that
should be reduced at once on the coordinating node. This value should be
used as a protection mechanism to reduce the memory overhead per search
request if the potential number of shards in the request can be large.
Default is 512.
:arg ccs_minimize_roundtrips: Indicates whether network round-
trips should be minimized as part of cross-cluster search requests
execution. Default is True.
:arg default_operator: The default operator for query string
query (AND or OR). Valid choices are AND, OR.
:arg df: The field to use as default where no field prefix is
given in the query string.
:arg docvalue_fields: Comma-separated list of fields to return
as the docvalue representation of a field for each hit.
:arg expand_wildcards: Whether to expand wildcard expression to
concrete indices that are open, closed or both. Valid choices are all,
open, closed, hidden, none.
:arg explain: Specify whether to return detailed information
about score computation as part of a hit.
:arg from_: Starting offset. Default is 0.
:arg ignore_throttled: Whether specified concrete, expanded or
aliased indices should be ignored when throttled.
:arg ignore_unavailable: Whether specified concrete indices
should be ignored when unavailable (missing or closed).
:arg lenient: Specify whether format-based query failures (such
as providing text to a numeric field) should be ignored.
:arg max_concurrent_shard_requests: 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 is 5.
:arg pre_filter_shard_size: Threshold that enforces a pre-filter
round-trip to prefilter search shards based on query rewriting if the
number of shards the search request expands to exceeds the threshold.
This filter round-trip can limit the number of shards significantly if
for instance a shard can not match any documents based on its rewrite
method ie. if date filters are mandatory to match but the shard bounds
and the query are disjoint.
:arg preference: Specify the node or shard the operation should
be performed on. Default is random.
:arg q: Query in the Lucene query string syntax.
:arg request_cache: Specify if request cache should be used for
this request or not, defaults to index level setting.
:arg rest_total_hits_as_int: Indicates whether hits.total should
be rendered as an integer or an object in the rest search response.
Default is false.
:arg routing: Comma-separated list of specific routing values.
:arg scroll: Specify how long a consistent view of the index
should be maintained for scrolled search.
:arg search_type: Search operation type. Valid choices are
query_then_fetch, dfs_query_then_fetch.
:arg seq_no_primary_term: Specify whether to return sequence
number and primary term of the last modification of each hit.
:arg size: Number of hits to return. Default is 10.
:arg sort: Comma-separated list of <field>:<direction> pairs.
:arg stats: Specific 'tag' of the request for logging and
statistical purposes.
:arg stored_fields: Comma-separated list of stored fields to
return.
:arg suggest_field: Specify which field to use for suggestions.
:arg suggest_mode: Specify suggest mode. Valid choices are
missing, popular, always.
:arg suggest_size: How many suggestions to return in response.
:arg suggest_text: The source text for which the suggestions
should be returned.
:arg terminate_after: The maximum number of documents to collect
for each shard, upon reaching which the query execution will terminate
early.
:arg timeout: Operation timeout.
:arg track_scores: Whether to calculate and return scores even
if they are not used for sorting.
:arg track_total_hits: Indicate if the number of documents that
match the query should be tracked.
:arg typed_keys: Specify whether aggregation and suggester names
should be prefixed by their respective types in the response.
:arg version: Whether to return document version as part of a
hit.
"""
# from is a reserved word so it cannot be used, use from_ instead
if "from_" in params:
params["from"] = params.pop("from_")

Check warning on line 219 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L218-L219

Added lines #L218 - L219 were not covered by tests

return await self.transport.perform_request(

Check warning on line 221 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L221

Added line #L221 was not covered by tests
"POST",
"/_plugins/_knn/models/_search",
params=params,
headers=headers,
body=body,
)

@query_params("timeout")
async def stats(
self,
node_id: Any = None,
stat: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Provides information about the current status of the k-NN plugin.


:arg node_id: Comma-separated list of node IDs or names to limit
the returned information; use `_local` to return information from the
node you're connecting to, leave empty to get information from all
nodes.
:arg stat: Comma-separated list of stats to retrieve; use `_all`
or empty string to retrieve all stats. Valid choices are
circuit_breaker_triggered, total_load_time, eviction_count, hit_count,
miss_count, graph_memory_usage, graph_memory_usage_percentage,
graph_index_requests, graph_index_errors, graph_query_requests,
graph_query_errors, knn_query_requests, cache_capacity_reached,
load_success_count, load_exception_count, indices_in_cache,
script_compilations, script_compilation_errors, script_query_requests,
script_query_errors, nmslib_initialized, faiss_initialized,
model_index_status, indexing_from_model_degraded, training_requests,
training_errors, training_memory_usage,
training_memory_usage_percentage.
:arg timeout: Operation timeout.
"""
return await self.transport.perform_request(

Check warning on line 259 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L259

Added line #L259 was not covered by tests
"GET",
_make_path("_plugins", "_knn", node_id, "stats", stat),
params=params,
headers=headers,
)

@query_params("preference")
async def train_model(
self,
body: Any,
model_id: Any = None,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Create and train a model that can be used for initializing k-NN native library
indexes during indexing.


:arg model_id: The id of the model.
:arg preference: Preferred node to execute training.
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")

Check warning on line 283 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L282-L283

Added lines #L282 - L283 were not covered by tests

return await self.transport.perform_request(

Check warning on line 285 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L285

Added line #L285 was not covered by tests
"POST",
_make_path("_plugins", "_knn", "models", model_id, "_train"),
params=params,
headers=headers,
body=body,
)

@query_params()
async def warmup(
self,
index: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Preloads native library files into memory, reducing initial search latency for
specified indexes


:arg index: Comma-separated list of indices; use `_all` or empty
string to perform the operation on all indices.
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")

Check warning on line 309 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L308-L309

Added lines #L308 - L309 were not covered by tests

return await self.transport.perform_request(

Check warning on line 311 in opensearchpy/_async/plugins/knn.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/plugins/knn.py#L311

Added line #L311 was not covered by tests
"GET",
_make_path("_plugins", "_knn", "warmup", index),
params=params,
headers=headers,
)
2 changes: 2 additions & 0 deletions opensearchpy/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ..plugins.alerting import AlertingClient
from ..plugins.index_management import IndexManagementClient
from ..plugins.knn import KnnClient
from .client import Client
from .utils import NamespacedClient

Expand All @@ -22,6 +23,7 @@ class PluginsClient(NamespacedClient):

def __init__(self, client: Client) -> None:
super(PluginsClient, self).__init__(client)
self.knn = KnnClient(client)
# self.query_workbench = QueryWorkbenchClient(client)
# self.reporting = ReportingClient(client)
# self.notebooks = NotebooksClient(client)
Expand Down
Loading
Loading