elasticsearch 8.13.0__py3-none-any.whl → 8.13.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. elasticsearch/_async/client/__init__.py +21 -0
  2. elasticsearch/_async/client/ml.py +61 -0
  3. elasticsearch/_async/client/security.py +7 -2
  4. elasticsearch/_sync/client/__init__.py +21 -0
  5. elasticsearch/_sync/client/ml.py +61 -0
  6. elasticsearch/_sync/client/security.py +7 -2
  7. elasticsearch/_version.py +1 -1
  8. elasticsearch/helpers/vectorstore/__init__.py +62 -0
  9. elasticsearch/helpers/vectorstore/_async/__init__.py +16 -0
  10. elasticsearch/helpers/vectorstore/_async/_utils.py +39 -0
  11. elasticsearch/helpers/vectorstore/_async/embedding_service.py +89 -0
  12. elasticsearch/helpers/vectorstore/_async/strategies.py +466 -0
  13. elasticsearch/helpers/vectorstore/_async/vectorstore.py +391 -0
  14. elasticsearch/helpers/vectorstore/_sync/__init__.py +16 -0
  15. elasticsearch/helpers/vectorstore/_sync/_utils.py +39 -0
  16. elasticsearch/helpers/vectorstore/_sync/embedding_service.py +89 -0
  17. elasticsearch/helpers/vectorstore/_sync/strategies.py +466 -0
  18. elasticsearch/helpers/vectorstore/_sync/vectorstore.py +388 -0
  19. elasticsearch/helpers/vectorstore/_utils.py +116 -0
  20. {elasticsearch-8.13.0.dist-info → elasticsearch-8.13.2.dist-info}/METADATA +5 -2
  21. {elasticsearch-8.13.0.dist-info → elasticsearch-8.13.2.dist-info}/RECORD +25 -13
  22. {elasticsearch-8.13.0.dist-info → elasticsearch-8.13.2.dist-info}/LICENSE +0 -0
  23. {elasticsearch-8.13.0.dist-info → elasticsearch-8.13.2.dist-info}/NOTICE +0 -0
  24. {elasticsearch-8.13.0.dist-info → elasticsearch-8.13.2.dist-info}/WHEEL +0 -0
  25. {elasticsearch-8.13.0.dist-info → elasticsearch-8.13.2.dist-info}/top_level.txt +0 -0
@@ -1936,6 +1936,7 @@ class AsyncElasticsearch(BaseClient):
1936
1936
  id: str,
1937
1937
  error_trace: t.Optional[bool] = None,
1938
1938
  filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
1939
+ force_synthetic_source: t.Optional[bool] = None,
1939
1940
  human: t.Optional[bool] = None,
1940
1941
  preference: t.Optional[str] = None,
1941
1942
  pretty: t.Optional[bool] = None,
@@ -1958,6 +1959,10 @@ class AsyncElasticsearch(BaseClient):
1958
1959
 
1959
1960
  :param index: Name of the index that contains the document.
1960
1961
  :param id: Unique identifier of the document.
1962
+ :param force_synthetic_source: Should this request force synthetic _source? Use
1963
+ this to test if the mapping supports synthetic _source and to get a sense
1964
+ of the worst case performance. Fetches with this enabled will be slower the
1965
+ enabling synthetic source natively in the index.
1961
1966
  :param preference: Specifies the node or shard the operation should be performed
1962
1967
  on. Random by default.
1963
1968
  :param realtime: If `true`, the request is real-time as opposed to near-real-time.
@@ -1989,6 +1994,8 @@ class AsyncElasticsearch(BaseClient):
1989
1994
  __query["error_trace"] = error_trace
1990
1995
  if filter_path is not None:
1991
1996
  __query["filter_path"] = filter_path
1997
+ if force_synthetic_source is not None:
1998
+ __query["force_synthetic_source"] = force_synthetic_source
1992
1999
  if human is not None:
1993
2000
  __query["human"] = human
1994
2001
  if preference is not None:
@@ -2578,6 +2585,7 @@ class AsyncElasticsearch(BaseClient):
2578
2585
  docs: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
2579
2586
  error_trace: t.Optional[bool] = None,
2580
2587
  filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
2588
+ force_synthetic_source: t.Optional[bool] = None,
2581
2589
  human: t.Optional[bool] = None,
2582
2590
  ids: t.Optional[t.Union[str, t.Sequence[str]]] = None,
2583
2591
  preference: t.Optional[str] = None,
@@ -2600,6 +2608,10 @@ class AsyncElasticsearch(BaseClient):
2600
2608
  or when a document in the `docs` array does not specify an index.
2601
2609
  :param docs: The documents you want to retrieve. Required if no index is specified
2602
2610
  in the request URI.
2611
+ :param force_synthetic_source: Should this request force synthetic _source? Use
2612
+ this to test if the mapping supports synthetic _source and to get a sense
2613
+ of the worst case performance. Fetches with this enabled will be slower the
2614
+ enabling synthetic source natively in the index.
2603
2615
  :param ids: The IDs of the documents you want to retrieve. Allowed when the index
2604
2616
  is specified in the request URI.
2605
2617
  :param preference: Specifies the node or shard the operation should be performed
@@ -2634,6 +2646,8 @@ class AsyncElasticsearch(BaseClient):
2634
2646
  __query["error_trace"] = error_trace
2635
2647
  if filter_path is not None:
2636
2648
  __query["filter_path"] = filter_path
2649
+ if force_synthetic_source is not None:
2650
+ __query["force_synthetic_source"] = force_synthetic_source
2637
2651
  if human is not None:
2638
2652
  __query["human"] = human
2639
2653
  if preference is not None:
@@ -3677,6 +3691,7 @@ class AsyncElasticsearch(BaseClient):
3677
3691
  ext: t.Optional[t.Mapping[str, t.Any]] = None,
3678
3692
  fields: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
3679
3693
  filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
3694
+ force_synthetic_source: t.Optional[bool] = None,
3680
3695
  from_: t.Optional[int] = None,
3681
3696
  highlight: t.Optional[t.Mapping[str, t.Any]] = None,
3682
3697
  human: t.Optional[bool] = None,
@@ -3793,6 +3808,10 @@ class AsyncElasticsearch(BaseClient):
3793
3808
  :param fields: Array of wildcard (`*`) patterns. The request returns values for
3794
3809
  field names matching these patterns in the `hits.fields` property of the
3795
3810
  response.
3811
+ :param force_synthetic_source: Should this request force synthetic _source? Use
3812
+ this to test if the mapping supports synthetic _source and to get a sense
3813
+ of the worst case performance. Fetches with this enabled will be slower the
3814
+ enabling synthetic source natively in the index.
3796
3815
  :param from_: Starting document offset. Needs to be non-negative. By default,
3797
3816
  you cannot page through more than 10,000 hits using the `from` and `size`
3798
3817
  parameters. To page through more hits, use the `search_after` parameter.
@@ -3972,6 +3991,8 @@ class AsyncElasticsearch(BaseClient):
3972
3991
  __query["expand_wildcards"] = expand_wildcards
3973
3992
  if filter_path is not None:
3974
3993
  __query["filter_path"] = filter_path
3994
+ if force_synthetic_source is not None:
3995
+ __query["force_synthetic_source"] = force_synthetic_source
3975
3996
  if human is not None:
3976
3997
  __query["human"] = human
3977
3998
  if ignore_throttled is not None:
@@ -3653,6 +3653,7 @@ class MlClient(NamespacedClient):
3653
3653
  prefix_strings: t.Optional[t.Mapping[str, t.Any]] = None,
3654
3654
  pretty: t.Optional[bool] = None,
3655
3655
  tags: t.Optional[t.Sequence[str]] = None,
3656
+ wait_for_completion: t.Optional[bool] = None,
3656
3657
  body: t.Optional[t.Dict[str, t.Any]] = None,
3657
3658
  ) -> ObjectApiResponse[t.Any]:
3658
3659
  """
@@ -3690,6 +3691,8 @@ class MlClient(NamespacedClient):
3690
3691
  this field unset.
3691
3692
  :param prefix_strings: Optional prefix strings applied at inference
3692
3693
  :param tags: An array of tags to organize the model.
3694
+ :param wait_for_completion: Whether to wait for all child operations (e.g. model
3695
+ download) to complete.
3693
3696
  """
3694
3697
  if model_id in SKIP_IN_PATH:
3695
3698
  raise ValueError("Empty value passed for parameter 'model_id'")
@@ -3707,6 +3710,8 @@ class MlClient(NamespacedClient):
3707
3710
  __query["human"] = human
3708
3711
  if pretty is not None:
3709
3712
  __query["pretty"] = pretty
3713
+ if wait_for_completion is not None:
3714
+ __query["wait_for_completion"] = wait_for_completion
3710
3715
  if not __body:
3711
3716
  if compressed_definition is not None:
3712
3717
  __body["compressed_definition"] = compressed_definition
@@ -5038,6 +5043,62 @@ class MlClient(NamespacedClient):
5038
5043
  path_parts=__path_parts,
5039
5044
  )
5040
5045
 
5046
+ @_rewrite_parameters(
5047
+ body_fields=("number_of_allocations",),
5048
+ )
5049
+ async def update_trained_model_deployment(
5050
+ self,
5051
+ *,
5052
+ model_id: str,
5053
+ error_trace: t.Optional[bool] = None,
5054
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
5055
+ human: t.Optional[bool] = None,
5056
+ number_of_allocations: t.Optional[int] = None,
5057
+ pretty: t.Optional[bool] = None,
5058
+ body: t.Optional[t.Dict[str, t.Any]] = None,
5059
+ ) -> ObjectApiResponse[t.Any]:
5060
+ """
5061
+ Updates certain properties of trained model deployment.
5062
+
5063
+ `<https://www.elastic.co/guide/en/elasticsearch/reference/8.13/update-trained-model-deployment.html>`_
5064
+
5065
+ :param model_id: The unique identifier of the trained model. Currently, only
5066
+ PyTorch models are supported.
5067
+ :param number_of_allocations: The number of model allocations on each node where
5068
+ the model is deployed. All allocations on a node share the same copy of the
5069
+ model in memory but use a separate set of threads to evaluate the model.
5070
+ Increasing this value generally increases the throughput. If this setting
5071
+ is greater than the number of hardware threads it will automatically be changed
5072
+ to a value less than the number of hardware threads.
5073
+ """
5074
+ if model_id in SKIP_IN_PATH:
5075
+ raise ValueError("Empty value passed for parameter 'model_id'")
5076
+ __path_parts: t.Dict[str, str] = {"model_id": _quote(model_id)}
5077
+ __path = f'/_ml/trained_models/{__path_parts["model_id"]}/deployment/_update'
5078
+ __query: t.Dict[str, t.Any] = {}
5079
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
5080
+ if error_trace is not None:
5081
+ __query["error_trace"] = error_trace
5082
+ if filter_path is not None:
5083
+ __query["filter_path"] = filter_path
5084
+ if human is not None:
5085
+ __query["human"] = human
5086
+ if pretty is not None:
5087
+ __query["pretty"] = pretty
5088
+ if not __body:
5089
+ if number_of_allocations is not None:
5090
+ __body["number_of_allocations"] = number_of_allocations
5091
+ __headers = {"accept": "application/json", "content-type": "application/json"}
5092
+ return await self.perform_request( # type: ignore[return-value]
5093
+ "POST",
5094
+ __path,
5095
+ params=__query,
5096
+ headers=__headers,
5097
+ body=__body,
5098
+ endpoint_id="ml.update_trained_model_deployment",
5099
+ path_parts=__path_parts,
5100
+ )
5101
+
5041
5102
  @_rewrite_parameters()
5042
5103
  async def upgrade_job_snapshot(
5043
5104
  self,
@@ -1756,7 +1756,7 @@ class SecurityClient(NamespacedClient):
1756
1756
  cluster: t.Optional[
1757
1757
  t.Sequence[
1758
1758
  t.Union[
1759
- "t.Literal['all', 'cancel_task', 'create_snapshot', 'grant_api_key', 'manage', 'manage_api_key', 'manage_ccr', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client']",
1759
+ "t.Literal['all', 'cancel_task', 'create_snapshot', 'cross_cluster_replication', 'cross_cluster_search', 'delegate_pki', 'grant_api_key', 'manage', 'manage_api_key', 'manage_autoscaling', 'manage_behavioral_analytics', 'manage_ccr', 'manage_data_frame_transforms', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_search_application', 'manage_search_query_rules', 'manage_search_synonyms', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_data_frame_transforms', 'monitor_enrich', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'none', 'post_behavioral_analytics_event', 'read_ccr', 'read_connector_secrets', 'read_fleet_secrets', 'read_ilm', 'read_pipeline', 'read_security', 'read_slm', 'transport_client', 'write_connector_secrets', 'write_fleet_secrets']",
1760
1760
  str,
1761
1761
  ]
1762
1762
  ]
@@ -2079,7 +2079,7 @@ class SecurityClient(NamespacedClient):
2079
2079
  cluster: t.Optional[
2080
2080
  t.Sequence[
2081
2081
  t.Union[
2082
- "t.Literal['all', 'cancel_task', 'create_snapshot', 'grant_api_key', 'manage', 'manage_api_key', 'manage_ccr', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client']",
2082
+ "t.Literal['all', 'cancel_task', 'create_snapshot', 'cross_cluster_replication', 'cross_cluster_search', 'delegate_pki', 'grant_api_key', 'manage', 'manage_api_key', 'manage_autoscaling', 'manage_behavioral_analytics', 'manage_ccr', 'manage_data_frame_transforms', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_search_application', 'manage_search_query_rules', 'manage_search_synonyms', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_data_frame_transforms', 'monitor_enrich', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'none', 'post_behavioral_analytics_event', 'read_ccr', 'read_connector_secrets', 'read_fleet_secrets', 'read_ilm', 'read_pipeline', 'read_security', 'read_slm', 'transport_client', 'write_connector_secrets', 'write_fleet_secrets']",
2083
2083
  str,
2084
2084
  ]
2085
2085
  ]
@@ -2375,6 +2375,7 @@ class SecurityClient(NamespacedClient):
2375
2375
  t.Union[str, t.Mapping[str, t.Any]],
2376
2376
  ]
2377
2377
  ] = None,
2378
+ typed_keys: t.Optional[bool] = None,
2378
2379
  with_limited_by: t.Optional[bool] = None,
2379
2380
  body: t.Optional[t.Dict[str, t.Any]] = None,
2380
2381
  ) -> ObjectApiResponse[t.Any]:
@@ -2412,6 +2413,8 @@ class SecurityClient(NamespacedClient):
2412
2413
  :param sort: Other than `id`, all public fields of an API key are eligible for
2413
2414
  sorting. In addition, sort can also be applied to the `_doc` field to sort
2414
2415
  by index order.
2416
+ :param typed_keys: Determines whether aggregation names are prefixed by their
2417
+ respective types in the response.
2415
2418
  :param with_limited_by: Return the snapshot of the owner user's role descriptors
2416
2419
  associated with the API key. An API key's actual permission is the intersection
2417
2420
  of its assigned role descriptors and the owner user's role descriptors.
@@ -2439,6 +2442,8 @@ class SecurityClient(NamespacedClient):
2439
2442
  __query["human"] = human
2440
2443
  if pretty is not None:
2441
2444
  __query["pretty"] = pretty
2445
+ if typed_keys is not None:
2446
+ __query["typed_keys"] = typed_keys
2442
2447
  if with_limited_by is not None:
2443
2448
  __query["with_limited_by"] = with_limited_by
2444
2449
  if not __body:
@@ -1934,6 +1934,7 @@ class Elasticsearch(BaseClient):
1934
1934
  id: str,
1935
1935
  error_trace: t.Optional[bool] = None,
1936
1936
  filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
1937
+ force_synthetic_source: t.Optional[bool] = None,
1937
1938
  human: t.Optional[bool] = None,
1938
1939
  preference: t.Optional[str] = None,
1939
1940
  pretty: t.Optional[bool] = None,
@@ -1956,6 +1957,10 @@ class Elasticsearch(BaseClient):
1956
1957
 
1957
1958
  :param index: Name of the index that contains the document.
1958
1959
  :param id: Unique identifier of the document.
1960
+ :param force_synthetic_source: Should this request force synthetic _source? Use
1961
+ this to test if the mapping supports synthetic _source and to get a sense
1962
+ of the worst case performance. Fetches with this enabled will be slower the
1963
+ enabling synthetic source natively in the index.
1959
1964
  :param preference: Specifies the node or shard the operation should be performed
1960
1965
  on. Random by default.
1961
1966
  :param realtime: If `true`, the request is real-time as opposed to near-real-time.
@@ -1987,6 +1992,8 @@ class Elasticsearch(BaseClient):
1987
1992
  __query["error_trace"] = error_trace
1988
1993
  if filter_path is not None:
1989
1994
  __query["filter_path"] = filter_path
1995
+ if force_synthetic_source is not None:
1996
+ __query["force_synthetic_source"] = force_synthetic_source
1990
1997
  if human is not None:
1991
1998
  __query["human"] = human
1992
1999
  if preference is not None:
@@ -2576,6 +2583,7 @@ class Elasticsearch(BaseClient):
2576
2583
  docs: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
2577
2584
  error_trace: t.Optional[bool] = None,
2578
2585
  filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
2586
+ force_synthetic_source: t.Optional[bool] = None,
2579
2587
  human: t.Optional[bool] = None,
2580
2588
  ids: t.Optional[t.Union[str, t.Sequence[str]]] = None,
2581
2589
  preference: t.Optional[str] = None,
@@ -2598,6 +2606,10 @@ class Elasticsearch(BaseClient):
2598
2606
  or when a document in the `docs` array does not specify an index.
2599
2607
  :param docs: The documents you want to retrieve. Required if no index is specified
2600
2608
  in the request URI.
2609
+ :param force_synthetic_source: Should this request force synthetic _source? Use
2610
+ this to test if the mapping supports synthetic _source and to get a sense
2611
+ of the worst case performance. Fetches with this enabled will be slower the
2612
+ enabling synthetic source natively in the index.
2601
2613
  :param ids: The IDs of the documents you want to retrieve. Allowed when the index
2602
2614
  is specified in the request URI.
2603
2615
  :param preference: Specifies the node or shard the operation should be performed
@@ -2632,6 +2644,8 @@ class Elasticsearch(BaseClient):
2632
2644
  __query["error_trace"] = error_trace
2633
2645
  if filter_path is not None:
2634
2646
  __query["filter_path"] = filter_path
2647
+ if force_synthetic_source is not None:
2648
+ __query["force_synthetic_source"] = force_synthetic_source
2635
2649
  if human is not None:
2636
2650
  __query["human"] = human
2637
2651
  if preference is not None:
@@ -3675,6 +3689,7 @@ class Elasticsearch(BaseClient):
3675
3689
  ext: t.Optional[t.Mapping[str, t.Any]] = None,
3676
3690
  fields: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
3677
3691
  filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
3692
+ force_synthetic_source: t.Optional[bool] = None,
3678
3693
  from_: t.Optional[int] = None,
3679
3694
  highlight: t.Optional[t.Mapping[str, t.Any]] = None,
3680
3695
  human: t.Optional[bool] = None,
@@ -3791,6 +3806,10 @@ class Elasticsearch(BaseClient):
3791
3806
  :param fields: Array of wildcard (`*`) patterns. The request returns values for
3792
3807
  field names matching these patterns in the `hits.fields` property of the
3793
3808
  response.
3809
+ :param force_synthetic_source: Should this request force synthetic _source? Use
3810
+ this to test if the mapping supports synthetic _source and to get a sense
3811
+ of the worst case performance. Fetches with this enabled will be slower the
3812
+ enabling synthetic source natively in the index.
3794
3813
  :param from_: Starting document offset. Needs to be non-negative. By default,
3795
3814
  you cannot page through more than 10,000 hits using the `from` and `size`
3796
3815
  parameters. To page through more hits, use the `search_after` parameter.
@@ -3970,6 +3989,8 @@ class Elasticsearch(BaseClient):
3970
3989
  __query["expand_wildcards"] = expand_wildcards
3971
3990
  if filter_path is not None:
3972
3991
  __query["filter_path"] = filter_path
3992
+ if force_synthetic_source is not None:
3993
+ __query["force_synthetic_source"] = force_synthetic_source
3973
3994
  if human is not None:
3974
3995
  __query["human"] = human
3975
3996
  if ignore_throttled is not None:
@@ -3653,6 +3653,7 @@ class MlClient(NamespacedClient):
3653
3653
  prefix_strings: t.Optional[t.Mapping[str, t.Any]] = None,
3654
3654
  pretty: t.Optional[bool] = None,
3655
3655
  tags: t.Optional[t.Sequence[str]] = None,
3656
+ wait_for_completion: t.Optional[bool] = None,
3656
3657
  body: t.Optional[t.Dict[str, t.Any]] = None,
3657
3658
  ) -> ObjectApiResponse[t.Any]:
3658
3659
  """
@@ -3690,6 +3691,8 @@ class MlClient(NamespacedClient):
3690
3691
  this field unset.
3691
3692
  :param prefix_strings: Optional prefix strings applied at inference
3692
3693
  :param tags: An array of tags to organize the model.
3694
+ :param wait_for_completion: Whether to wait for all child operations (e.g. model
3695
+ download) to complete.
3693
3696
  """
3694
3697
  if model_id in SKIP_IN_PATH:
3695
3698
  raise ValueError("Empty value passed for parameter 'model_id'")
@@ -3707,6 +3710,8 @@ class MlClient(NamespacedClient):
3707
3710
  __query["human"] = human
3708
3711
  if pretty is not None:
3709
3712
  __query["pretty"] = pretty
3713
+ if wait_for_completion is not None:
3714
+ __query["wait_for_completion"] = wait_for_completion
3710
3715
  if not __body:
3711
3716
  if compressed_definition is not None:
3712
3717
  __body["compressed_definition"] = compressed_definition
@@ -5038,6 +5043,62 @@ class MlClient(NamespacedClient):
5038
5043
  path_parts=__path_parts,
5039
5044
  )
5040
5045
 
5046
+ @_rewrite_parameters(
5047
+ body_fields=("number_of_allocations",),
5048
+ )
5049
+ def update_trained_model_deployment(
5050
+ self,
5051
+ *,
5052
+ model_id: str,
5053
+ error_trace: t.Optional[bool] = None,
5054
+ filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
5055
+ human: t.Optional[bool] = None,
5056
+ number_of_allocations: t.Optional[int] = None,
5057
+ pretty: t.Optional[bool] = None,
5058
+ body: t.Optional[t.Dict[str, t.Any]] = None,
5059
+ ) -> ObjectApiResponse[t.Any]:
5060
+ """
5061
+ Updates certain properties of trained model deployment.
5062
+
5063
+ `<https://www.elastic.co/guide/en/elasticsearch/reference/8.13/update-trained-model-deployment.html>`_
5064
+
5065
+ :param model_id: The unique identifier of the trained model. Currently, only
5066
+ PyTorch models are supported.
5067
+ :param number_of_allocations: The number of model allocations on each node where
5068
+ the model is deployed. All allocations on a node share the same copy of the
5069
+ model in memory but use a separate set of threads to evaluate the model.
5070
+ Increasing this value generally increases the throughput. If this setting
5071
+ is greater than the number of hardware threads it will automatically be changed
5072
+ to a value less than the number of hardware threads.
5073
+ """
5074
+ if model_id in SKIP_IN_PATH:
5075
+ raise ValueError("Empty value passed for parameter 'model_id'")
5076
+ __path_parts: t.Dict[str, str] = {"model_id": _quote(model_id)}
5077
+ __path = f'/_ml/trained_models/{__path_parts["model_id"]}/deployment/_update'
5078
+ __query: t.Dict[str, t.Any] = {}
5079
+ __body: t.Dict[str, t.Any] = body if body is not None else {}
5080
+ if error_trace is not None:
5081
+ __query["error_trace"] = error_trace
5082
+ if filter_path is not None:
5083
+ __query["filter_path"] = filter_path
5084
+ if human is not None:
5085
+ __query["human"] = human
5086
+ if pretty is not None:
5087
+ __query["pretty"] = pretty
5088
+ if not __body:
5089
+ if number_of_allocations is not None:
5090
+ __body["number_of_allocations"] = number_of_allocations
5091
+ __headers = {"accept": "application/json", "content-type": "application/json"}
5092
+ return self.perform_request( # type: ignore[return-value]
5093
+ "POST",
5094
+ __path,
5095
+ params=__query,
5096
+ headers=__headers,
5097
+ body=__body,
5098
+ endpoint_id="ml.update_trained_model_deployment",
5099
+ path_parts=__path_parts,
5100
+ )
5101
+
5041
5102
  @_rewrite_parameters()
5042
5103
  def upgrade_job_snapshot(
5043
5104
  self,
@@ -1756,7 +1756,7 @@ class SecurityClient(NamespacedClient):
1756
1756
  cluster: t.Optional[
1757
1757
  t.Sequence[
1758
1758
  t.Union[
1759
- "t.Literal['all', 'cancel_task', 'create_snapshot', 'grant_api_key', 'manage', 'manage_api_key', 'manage_ccr', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client']",
1759
+ "t.Literal['all', 'cancel_task', 'create_snapshot', 'cross_cluster_replication', 'cross_cluster_search', 'delegate_pki', 'grant_api_key', 'manage', 'manage_api_key', 'manage_autoscaling', 'manage_behavioral_analytics', 'manage_ccr', 'manage_data_frame_transforms', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_search_application', 'manage_search_query_rules', 'manage_search_synonyms', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_data_frame_transforms', 'monitor_enrich', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'none', 'post_behavioral_analytics_event', 'read_ccr', 'read_connector_secrets', 'read_fleet_secrets', 'read_ilm', 'read_pipeline', 'read_security', 'read_slm', 'transport_client', 'write_connector_secrets', 'write_fleet_secrets']",
1760
1760
  str,
1761
1761
  ]
1762
1762
  ]
@@ -2079,7 +2079,7 @@ class SecurityClient(NamespacedClient):
2079
2079
  cluster: t.Optional[
2080
2080
  t.Sequence[
2081
2081
  t.Union[
2082
- "t.Literal['all', 'cancel_task', 'create_snapshot', 'grant_api_key', 'manage', 'manage_api_key', 'manage_ccr', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'read_ccr', 'read_ilm', 'read_pipeline', 'read_slm', 'transport_client']",
2082
+ "t.Literal['all', 'cancel_task', 'create_snapshot', 'cross_cluster_replication', 'cross_cluster_search', 'delegate_pki', 'grant_api_key', 'manage', 'manage_api_key', 'manage_autoscaling', 'manage_behavioral_analytics', 'manage_ccr', 'manage_data_frame_transforms', 'manage_enrich', 'manage_ilm', 'manage_index_templates', 'manage_ingest_pipelines', 'manage_logstash_pipelines', 'manage_ml', 'manage_oidc', 'manage_own_api_key', 'manage_pipeline', 'manage_rollup', 'manage_saml', 'manage_search_application', 'manage_search_query_rules', 'manage_search_synonyms', 'manage_security', 'manage_service_account', 'manage_slm', 'manage_token', 'manage_transform', 'manage_user_profile', 'manage_watcher', 'monitor', 'monitor_data_frame_transforms', 'monitor_enrich', 'monitor_ml', 'monitor_rollup', 'monitor_snapshot', 'monitor_text_structure', 'monitor_transform', 'monitor_watcher', 'none', 'post_behavioral_analytics_event', 'read_ccr', 'read_connector_secrets', 'read_fleet_secrets', 'read_ilm', 'read_pipeline', 'read_security', 'read_slm', 'transport_client', 'write_connector_secrets', 'write_fleet_secrets']",
2083
2083
  str,
2084
2084
  ]
2085
2085
  ]
@@ -2375,6 +2375,7 @@ class SecurityClient(NamespacedClient):
2375
2375
  t.Union[str, t.Mapping[str, t.Any]],
2376
2376
  ]
2377
2377
  ] = None,
2378
+ typed_keys: t.Optional[bool] = None,
2378
2379
  with_limited_by: t.Optional[bool] = None,
2379
2380
  body: t.Optional[t.Dict[str, t.Any]] = None,
2380
2381
  ) -> ObjectApiResponse[t.Any]:
@@ -2412,6 +2413,8 @@ class SecurityClient(NamespacedClient):
2412
2413
  :param sort: Other than `id`, all public fields of an API key are eligible for
2413
2414
  sorting. In addition, sort can also be applied to the `_doc` field to sort
2414
2415
  by index order.
2416
+ :param typed_keys: Determines whether aggregation names are prefixed by their
2417
+ respective types in the response.
2415
2418
  :param with_limited_by: Return the snapshot of the owner user's role descriptors
2416
2419
  associated with the API key. An API key's actual permission is the intersection
2417
2420
  of its assigned role descriptors and the owner user's role descriptors.
@@ -2439,6 +2442,8 @@ class SecurityClient(NamespacedClient):
2439
2442
  __query["human"] = human
2440
2443
  if pretty is not None:
2441
2444
  __query["pretty"] = pretty
2445
+ if typed_keys is not None:
2446
+ __query["typed_keys"] = typed_keys
2442
2447
  if with_limited_by is not None:
2443
2448
  __query["with_limited_by"] = with_limited_by
2444
2449
  if not __body:
elasticsearch/_version.py CHANGED
@@ -15,4 +15,4 @@
15
15
  # specific language governing permissions and limitations
16
16
  # under the License.
17
17
 
18
- __versionstr__ = "8.13.0"
18
+ __versionstr__ = "8.13.2"
@@ -0,0 +1,62 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from elasticsearch.helpers.vectorstore._async.embedding_service import (
19
+ AsyncElasticsearchEmbeddings,
20
+ AsyncEmbeddingService,
21
+ )
22
+ from elasticsearch.helpers.vectorstore._async.strategies import (
23
+ AsyncBM25Strategy,
24
+ AsyncDenseVectorScriptScoreStrategy,
25
+ AsyncDenseVectorStrategy,
26
+ AsyncRetrievalStrategy,
27
+ AsyncSparseVectorStrategy,
28
+ )
29
+ from elasticsearch.helpers.vectorstore._async.vectorstore import AsyncVectorStore
30
+ from elasticsearch.helpers.vectorstore._sync.embedding_service import (
31
+ ElasticsearchEmbeddings,
32
+ EmbeddingService,
33
+ )
34
+ from elasticsearch.helpers.vectorstore._sync.strategies import (
35
+ BM25Strategy,
36
+ DenseVectorScriptScoreStrategy,
37
+ DenseVectorStrategy,
38
+ RetrievalStrategy,
39
+ SparseVectorStrategy,
40
+ )
41
+ from elasticsearch.helpers.vectorstore._sync.vectorstore import VectorStore
42
+ from elasticsearch.helpers.vectorstore._utils import DistanceMetric
43
+
44
+ __all__ = [
45
+ "AsyncBM25Strategy",
46
+ "AsyncDenseVectorScriptScoreStrategy",
47
+ "AsyncDenseVectorStrategy",
48
+ "AsyncElasticsearchEmbeddings",
49
+ "AsyncEmbeddingService",
50
+ "AsyncRetrievalStrategy",
51
+ "AsyncSparseVectorStrategy",
52
+ "AsyncVectorStore",
53
+ "BM25Strategy",
54
+ "DenseVectorScriptScoreStrategy",
55
+ "DenseVectorStrategy",
56
+ "DistanceMetric",
57
+ "ElasticsearchEmbeddings",
58
+ "EmbeddingService",
59
+ "RetrievalStrategy",
60
+ "SparseVectorStrategy",
61
+ "VectorStore",
62
+ ]
@@ -0,0 +1,16 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
@@ -0,0 +1,39 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from elasticsearch import AsyncElasticsearch, BadRequestError, NotFoundError
19
+
20
+
21
+ async def model_must_be_deployed(client: AsyncElasticsearch, model_id: str) -> None:
22
+ """
23
+ :raises [NotFoundError]: if the model is neither downloaded nor deployed.
24
+ :raises [ConflictError]: if the model is downloaded but not yet deployed.
25
+ """
26
+ doc = {"text_field": f"test if the model '{model_id}' is deployed"}
27
+ try:
28
+ await client.ml.infer_trained_model(model_id=model_id, docs=[doc])
29
+ except BadRequestError:
30
+ # The model is deployed but expects a different input field name.
31
+ pass
32
+
33
+
34
+ async def model_is_deployed(client: AsyncElasticsearch, model_id: str) -> bool:
35
+ try:
36
+ await model_must_be_deployed(client, model_id)
37
+ return True
38
+ except NotFoundError:
39
+ return False
@@ -0,0 +1,89 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from abc import ABC, abstractmethod
19
+ from typing import List
20
+
21
+ from elasticsearch import AsyncElasticsearch
22
+ from elasticsearch._version import __versionstr__ as lib_version
23
+
24
+
25
+ class AsyncEmbeddingService(ABC):
26
+ @abstractmethod
27
+ async def embed_documents(self, texts: List[str]) -> List[List[float]]:
28
+ """Generate embeddings for a list of documents.
29
+
30
+ :param texts: A list of document strings to generate embeddings for.
31
+
32
+ :return: A list of embeddings, one for each document in the input.
33
+ """
34
+
35
+ @abstractmethod
36
+ async def embed_query(self, query: str) -> List[float]:
37
+ """Generate an embedding for a single query text.
38
+
39
+ :param text: The query text to generate an embedding for.
40
+
41
+ :return: The embedding for the input query text.
42
+ """
43
+
44
+
45
+ class AsyncElasticsearchEmbeddings(AsyncEmbeddingService):
46
+ """Elasticsearch as a service for embedding model inference.
47
+
48
+ You need to have an embedding model downloaded and deployed in Elasticsearch:
49
+ - https://www.elastic.co/guide/en/elasticsearch/reference/current/infer-trained-model.html
50
+ - https://www.elastic.co/guide/en/machine-learning/current/ml-nlp-deploy-models.html
51
+ """ # noqa: E501
52
+
53
+ def __init__(
54
+ self,
55
+ *,
56
+ client: AsyncElasticsearch,
57
+ model_id: str,
58
+ input_field: str = "text_field",
59
+ user_agent: str = f"elasticsearch-py-es/{lib_version}",
60
+ ):
61
+ """
62
+ :param agent_header: user agent header specific to the 3rd party integration.
63
+ Used for usage tracking in Elastic Cloud.
64
+ :param model_id: The model_id of the model deployed in the Elasticsearch cluster.
65
+ :param input_field: The name of the key for the input text field in the
66
+ document. Defaults to 'text_field'.
67
+ :param client: Elasticsearch client connection. Alternatively specify the
68
+ Elasticsearch connection with the other es_* parameters.
69
+ """
70
+ # Add integration-specific usage header for tracking usage in Elastic Cloud.
71
+ # client.options preserves existing (non-user-agent) headers.
72
+ client = client.options(headers={"User-Agent": user_agent})
73
+
74
+ self.client = client
75
+ self.model_id = model_id
76
+ self.input_field = input_field
77
+
78
+ async def embed_documents(self, texts: List[str]) -> List[List[float]]:
79
+ return await self._embedding_func(texts)
80
+
81
+ async def embed_query(self, text: str) -> List[float]:
82
+ result = await self._embedding_func([text])
83
+ return result[0]
84
+
85
+ async def _embedding_func(self, texts: List[str]) -> List[List[float]]:
86
+ response = await self.client.ml.infer_trained_model(
87
+ model_id=self.model_id, docs=[{self.input_field: text} for text in texts]
88
+ )
89
+ return [doc["predicted_value"] for doc in response["inference_results"]]