amazon-bedrock-haystack 5.3.1__py3-none-any.whl → 6.0.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-bedrock-haystack
3
- Version: 5.3.1
3
+ Version: 6.0.0
4
4
  Summary: An integration of AWS S3 and Bedrock as a Downloader and Generator components.
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/amazon_bedrock#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -11,17 +11,16 @@ License-File: LICENSE.txt
11
11
  Classifier: Development Status :: 4 - Beta
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.9
15
14
  Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
20
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
21
- Requires-Python: >=3.9
20
+ Requires-Python: >=3.10
22
21
  Requires-Dist: aioboto3>=14.0.0
23
22
  Requires-Dist: boto3>=1.28.57
24
- Requires-Dist: haystack-ai>=2.19.0
23
+ Requires-Dist: haystack-ai>=2.22.0
25
24
  Description-Content-Type: text/markdown
26
25
 
27
26
  # amazon-bedrock-haystack
@@ -1,29 +1,29 @@
1
1
  haystack_integrations/common/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  haystack_integrations/common/amazon_bedrock/__init__.py,sha256=6GZ8Y3Lw0rLOsOAqi6Tu5mZC977UzQvgDxKpOWr8IQw,110
3
3
  haystack_integrations/common/amazon_bedrock/errors.py,sha256=47w_rg3JTGJ5QfsUELrjYBeuLajxUmQ7-zOFvdz4mT8,856
4
- haystack_integrations/common/amazon_bedrock/utils.py,sha256=UIJVl1e_hlP9mQr_YvVTFklbc_kqOgI7DnSxcAuSLx0,2846
4
+ haystack_integrations/common/amazon_bedrock/utils.py,sha256=X_aIqQEPp0GVStmKRZEq4yi2oFAB0NEs0YVcaBxuyjQ,2808
5
5
  haystack_integrations/common/s3/__init__.py,sha256=6GZ8Y3Lw0rLOsOAqi6Tu5mZC977UzQvgDxKpOWr8IQw,110
6
6
  haystack_integrations/common/s3/errors.py,sha256=BrTDLdhQvAuQutyg35cFyP5h8PNkDEieLwehi58UqAU,452
7
- haystack_integrations/common/s3/utils.py,sha256=OJupFj54aQmg6S8VuVq6Lc2qpFZyyJajRVIpwe3_6iA,4744
7
+ haystack_integrations/common/s3/utils.py,sha256=lrPTc4r0l9Bm6dACxCDgvcbDPPtuxjU6nzTDFw4g2Fs,4707
8
8
  haystack_integrations/components/downloaders/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  haystack_integrations/components/downloaders/s3/__init__.py,sha256=2BOd3_N0kGqRJGH-ENrTJqOqzqHryRYaSuNqpLYKMFo,179
10
- haystack_integrations/components/downloaders/s3/s3_downloader.py,sha256=jj9VMQ5QciTZvJ8Qki_zha0tcK0-APm2rMhMPObtr1M,12625
10
+ haystack_integrations/components/downloaders/s3/s3_downloader.py,sha256=xRvQMXEUi7ysOTX3ylC3qw9t0GU2JzGGt7DQEu5Eu8s,12475
11
11
  haystack_integrations/components/embedders/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  haystack_integrations/components/embedders/amazon_bedrock/__init__.py,sha256=7GlhHJ4jFHCxq5QN5losGuGtrGNjvEx2dSQvEYD2yG0,408
13
- haystack_integrations/components/embedders/amazon_bedrock/document_embedder.py,sha256=EKLiKzN0al7OLvfIAnXXNgUTI4TbSc-qCkfjjDJeCd4,13216
14
- haystack_integrations/components/embedders/amazon_bedrock/document_image_embedder.py,sha256=qKsWRGkubFMHDeqTbPgA5qvEag_CDNTnc5kEmDbc6IQ,16202
15
- haystack_integrations/components/embedders/amazon_bedrock/text_embedder.py,sha256=rYmU39q_-9uKANBebcQsPtGE0EjrAkOQSFHL3e6WYag,9349
13
+ haystack_integrations/components/embedders/amazon_bedrock/document_embedder.py,sha256=nbgbHIjy-medDvKCOBvTpbPCBtWbHV8RQQKT3bsQ_po,13205
14
+ haystack_integrations/components/embedders/amazon_bedrock/document_image_embedder.py,sha256=qBUo4P2Ccw6ltRXHdrB1HuUo8-9GQLDcuO7VDfBORlQ,16175
15
+ haystack_integrations/components/embedders/amazon_bedrock/text_embedder.py,sha256=RE4rdnUZOm0PL_uf2HTLmsstA2hdMB0Rpz9Ga3VWlF4,9315
16
16
  haystack_integrations/components/generators/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  haystack_integrations/components/generators/amazon_bedrock/__init__.py,sha256=lv4NouIVm78YavUssWQrHHP_81u-7j21qW8v1kZMJPQ,284
18
- haystack_integrations/components/generators/amazon_bedrock/adapters.py,sha256=SDCi_EA-1OUmTKrnbcql9oQQuLnoAGzF_XwrKnQ1_jk,19628
19
- haystack_integrations/components/generators/amazon_bedrock/generator.py,sha256=1vuA0x6k8UOvPjeKjYvcYORpsTFXs1rKMUXlima51IY,14725
18
+ haystack_integrations/components/generators/amazon_bedrock/adapters.py,sha256=4-gIWfw70hGaXMNS30UbJFNFCWK2KG6RMnT_4z5RHxc,19625
19
+ haystack_integrations/components/generators/amazon_bedrock/generator.py,sha256=S4uuM4Mi6Z0CSveKTtVySXp12K3tZrhbyRWu19YwVME,14679
20
20
  haystack_integrations/components/generators/amazon_bedrock/chat/__init__.py,sha256=6GZ8Y3Lw0rLOsOAqi6Tu5mZC977UzQvgDxKpOWr8IQw,110
21
- haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py,sha256=batM98HDpUyZEwG-pGYhgTQ6Z9uoGE2TUb3EaZjmox4,26227
22
- haystack_integrations/components/generators/amazon_bedrock/chat/utils.py,sha256=sWgh-58YeDIatDFNLX2YG1KPJghsyXK5p5uVM4pe8U4,27236
21
+ haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py,sha256=KJqeKFzM1thG2GSVm51pY5aX6gctmtnJvF_kwOH8gqQ,26143
22
+ haystack_integrations/components/generators/amazon_bedrock/chat/utils.py,sha256=juOaTi8DuXr-i68zzjCnYoc5eNxO1DxcTI9fcNfg4rE,27214
23
23
  haystack_integrations/components/rankers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  haystack_integrations/components/rankers/amazon_bedrock/__init__.py,sha256=mJQKShAP5AfZvfKQisSh7kfKu6RIXzsYdk4eqMtcaEk,75
25
- haystack_integrations/components/rankers/amazon_bedrock/ranker.py,sha256=oFNTF2BnKNA1VERiF42ttTFDzxOiaBIA1H5ozLNFFFU,11800
26
- amazon_bedrock_haystack-5.3.1.dist-info/METADATA,sha256=-icmdgZ9-poMEUHeBb470jU0VnpZwAzlHOcaUS57bLA,2228
27
- amazon_bedrock_haystack-5.3.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
28
- amazon_bedrock_haystack-5.3.1.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
29
- amazon_bedrock_haystack-5.3.1.dist-info/RECORD,,
25
+ haystack_integrations/components/rankers/amazon_bedrock/ranker.py,sha256=DuNV-2nxI4D2Mw7Nxq_z-u88_PMAjmQGJGBg1WzfvlQ,11749
26
+ amazon_bedrock_haystack-6.0.0.dist-info/METADATA,sha256=08syh5v_gPM1V9lbXZC0pup1RnX4K9WGxL_qLzBptdY,2179
27
+ amazon_bedrock_haystack-6.0.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
28
+ amazon_bedrock_haystack-6.0.0.dist-info/licenses/LICENSE.txt,sha256=B05uMshqTA74s-0ltyHKI6yoPfJ3zYgQbvcXfDVGFf8,10280
29
+ amazon_bedrock_haystack-6.0.0.dist-info/RECORD,,
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
- from typing import Any, Optional, Union
5
+ from typing import Any
6
6
 
7
7
  import aioboto3
8
8
  import boto3
@@ -20,14 +20,14 @@ AWS_CONFIGURATION_KEYS = [
20
20
 
21
21
 
22
22
  def get_aws_session(
23
- aws_access_key_id: Optional[str] = None,
24
- aws_secret_access_key: Optional[str] = None,
25
- aws_session_token: Optional[str] = None,
26
- aws_region_name: Optional[str] = None,
27
- aws_profile_name: Optional[str] = None,
23
+ aws_access_key_id: str | None = None,
24
+ aws_secret_access_key: str | None = None,
25
+ aws_session_token: str | None = None,
26
+ aws_region_name: str | None = None,
27
+ aws_profile_name: str | None = None,
28
28
  async_mode: bool = False,
29
29
  **kwargs: Any,
30
- ) -> Union[boto3.Session, aioboto3.Session]:
30
+ ) -> boto3.Session | aioboto3.Session:
31
31
  """
32
32
  Creates an AWS Session with the given parameters.
33
33
  Checks if the provided AWS credentials are valid and can be used to connect to AWS.
@@ -6,7 +6,6 @@ import os
6
6
  from dataclasses import dataclass
7
7
  from http import HTTPStatus
8
8
  from pathlib import Path
9
- from typing import Optional
10
9
 
11
10
  from boto3.session import Session
12
11
  from botocore.config import Config
@@ -23,9 +22,9 @@ class S3Storage:
23
22
  self,
24
23
  s3_bucket: str,
25
24
  session: Session,
26
- s3_prefix: Optional[str] = None,
27
- endpoint_url: Optional[str] = None,
28
- config: Optional[Config] = None,
25
+ s3_prefix: str | None = None,
26
+ endpoint_url: str | None = None,
27
+ config: Config | None = None,
29
28
  ) -> None:
30
29
  """
31
30
  Initializes the S3Storage object with the provided parameters.
@@ -3,9 +3,10 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  import os
6
+ from collections.abc import Callable
6
7
  from concurrent.futures import ThreadPoolExecutor
7
8
  from pathlib import Path
8
- from typing import Any, Callable, Optional
9
+ from typing import Any
9
10
 
10
11
  from botocore.config import Config
11
12
  from haystack import component, default_from_dict, default_to_dict, logging
@@ -29,20 +30,20 @@ class S3Downloader:
29
30
  def __init__(
30
31
  self,
31
32
  *,
32
- aws_access_key_id: Optional[Secret] = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
33
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
33
+ aws_access_key_id: Secret | None = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
34
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
34
35
  "AWS_SECRET_ACCESS_KEY", strict=False
35
36
  ),
36
- aws_session_token: Optional[Secret] = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
37
- aws_region_name: Optional[Secret] = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
38
- aws_profile_name: Optional[Secret] = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
39
- boto3_config: Optional[dict[str, Any]] = None,
40
- file_root_path: Optional[str] = None,
41
- file_extensions: Optional[list[str]] = None,
37
+ aws_session_token: Secret | None = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
38
+ aws_region_name: Secret | None = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
39
+ aws_profile_name: Secret | None = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
40
+ boto3_config: dict[str, Any] | None = None,
41
+ file_root_path: str | None = None,
42
+ file_extensions: list[str] | None = None,
42
43
  file_name_meta_key: str = "file_name",
43
44
  max_workers: int = 32,
44
45
  max_cache_size: int = 100,
45
- s3_key_generation_function: Optional[Callable[[Document], str]] = None,
46
+ s3_key_generation_function: Callable[[Document], str] | None = None,
46
47
  ) -> None:
47
48
  """
48
49
  Initializes the `S3Downloader` with the provided parameters.
@@ -104,9 +105,9 @@ class S3Downloader:
104
105
  self.file_name_meta_key = file_name_meta_key
105
106
  self.s3_key_generation_function = s3_key_generation_function
106
107
 
107
- self._storage: Optional[S3Storage] = None
108
+ self._storage: S3Storage | None = None
108
109
 
109
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
110
+ def resolve_secret(secret: Secret | None) -> str | None:
110
111
  return secret.resolve_value() if secret else None
111
112
 
112
113
  self._session = get_aws_session(
@@ -142,8 +143,7 @@ class S3Downloader:
142
143
  """
143
144
 
144
145
  if self._storage is None:
145
- msg = f"The component {self.__class__.__name__} was not warmed up. Call 'warm_up()' before calling run()."
146
- raise RuntimeError(msg)
146
+ self.warm_up()
147
147
 
148
148
  filtered_documents = self._filter_documents_by_extensions(documents) if self.file_extensions else documents
149
149
 
@@ -170,7 +170,7 @@ class S3Downloader:
170
170
  if Path(doc.meta.get(self.file_name_meta_key, "")).suffix.lower() in self.file_extensions
171
171
  ]
172
172
 
173
- def _download_file(self, document: Document) -> Optional[Document]:
173
+ def _download_file(self, document: Document) -> Document | None:
174
174
  """
175
175
  Download a single file from AWS S3 Bucket to local filesystem.
176
176
 
@@ -1,5 +1,5 @@
1
1
  import json
2
- from typing import Any, Optional
2
+ from typing import Any
3
3
 
4
4
  from botocore.config import Config
5
5
  from botocore.exceptions import ClientError
@@ -50,18 +50,18 @@ class AmazonBedrockDocumentEmbedder:
50
50
  def __init__(
51
51
  self,
52
52
  model: str,
53
- aws_access_key_id: Optional[Secret] = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
54
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
53
+ aws_access_key_id: Secret | None = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
54
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
55
55
  "AWS_SECRET_ACCESS_KEY", strict=False
56
56
  ),
57
- aws_session_token: Optional[Secret] = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
58
- aws_region_name: Optional[Secret] = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
59
- aws_profile_name: Optional[Secret] = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
57
+ aws_session_token: Secret | None = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
58
+ aws_region_name: Secret | None = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
59
+ aws_profile_name: Secret | None = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
60
60
  batch_size: int = 32,
61
61
  progress_bar: bool = True,
62
- meta_fields_to_embed: Optional[list[str]] = None,
62
+ meta_fields_to_embed: list[str] | None = None,
63
63
  embedding_separator: str = "\n",
64
- boto3_config: Optional[dict[str, Any]] = None,
64
+ boto3_config: dict[str, Any] | None = None,
65
65
  **kwargs: Any,
66
66
  ) -> None:
67
67
  """
@@ -115,7 +115,7 @@ class AmazonBedrockDocumentEmbedder:
115
115
  self.boto3_config = boto3_config
116
116
  self.kwargs = kwargs
117
117
 
118
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
118
+ def resolve_secret(secret: Secret | None) -> str | None:
119
119
  return secret.resolve_value() if secret else None
120
120
 
121
121
  try:
@@ -186,7 +186,7 @@ class AmazonBedrockDocumentEmbedder:
186
186
  )
187
187
  all_embeddings.extend(embeddings_list)
188
188
 
189
- for doc, emb in zip(documents, all_embeddings):
189
+ for doc, emb in zip(documents, all_embeddings, strict=True):
190
190
  doc.embedding = emb
191
191
 
192
192
  return documents
@@ -214,7 +214,7 @@ class AmazonBedrockDocumentEmbedder:
214
214
  embedding = response_body["embedding"]
215
215
  all_embeddings.append(embedding)
216
216
 
217
- for doc, emb in zip(documents, all_embeddings):
217
+ for doc, emb in zip(documents, all_embeddings, strict=True):
218
218
  doc.embedding = emb
219
219
 
220
220
  return documents
@@ -4,7 +4,7 @@
4
4
 
5
5
  import json
6
6
  from dataclasses import replace
7
- from typing import Any, Optional
7
+ from typing import Any
8
8
 
9
9
  from botocore.config import Config
10
10
  from botocore.exceptions import ClientError
@@ -68,18 +68,18 @@ class AmazonBedrockDocumentImageEmbedder:
68
68
  self,
69
69
  *,
70
70
  model: str,
71
- aws_access_key_id: Optional[Secret] = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
72
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
71
+ aws_access_key_id: Secret | None = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
72
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
73
73
  "AWS_SECRET_ACCESS_KEY", strict=False
74
74
  ),
75
- aws_session_token: Optional[Secret] = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
76
- aws_region_name: Optional[Secret] = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
77
- aws_profile_name: Optional[Secret] = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
75
+ aws_session_token: Secret | None = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
76
+ aws_region_name: Secret | None = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
77
+ aws_profile_name: Secret | None = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
78
78
  file_path_meta_field: str = "file_path",
79
- root_path: Optional[str] = None,
80
- image_size: Optional[tuple[int, int]] = None,
79
+ root_path: str | None = None,
80
+ image_size: tuple[int, int] | None = None,
81
81
  progress_bar: bool = True,
82
- boto3_config: Optional[dict[str, Any]] = None,
82
+ boto3_config: dict[str, Any] | None = None,
83
83
  **kwargs: Any,
84
84
  ) -> None:
85
85
  """
@@ -144,7 +144,7 @@ class AmazonBedrockDocumentImageEmbedder:
144
144
  raise ValueError(msg)
145
145
  self.embedding_types = embedding_types
146
146
 
147
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
147
+ def resolve_secret(secret: Secret | None) -> str | None:
148
148
  return secret.resolve_value() if secret else None
149
149
 
150
150
  try:
@@ -288,7 +288,7 @@ class AmazonBedrockDocumentImageEmbedder:
288
288
 
289
289
  docs_with_embeddings = []
290
290
 
291
- for doc, emb in zip(documents, embeddings):
291
+ for doc, emb in zip(documents, embeddings, strict=True):
292
292
  # we store this information for later inspection
293
293
  new_meta = {
294
294
  **doc.meta,
@@ -1,5 +1,5 @@
1
1
  import json
2
- from typing import Any, Optional
2
+ from typing import Any
3
3
 
4
4
  from botocore.config import Config
5
5
  from botocore.exceptions import ClientError
@@ -43,14 +43,14 @@ class AmazonBedrockTextEmbedder:
43
43
  def __init__(
44
44
  self,
45
45
  model: str,
46
- aws_access_key_id: Optional[Secret] = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
47
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
46
+ aws_access_key_id: Secret | None = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
47
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
48
48
  "AWS_SECRET_ACCESS_KEY", strict=False
49
49
  ),
50
- aws_session_token: Optional[Secret] = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
51
- aws_region_name: Optional[Secret] = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
52
- aws_profile_name: Optional[Secret] = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
53
- boto3_config: Optional[dict[str, Any]] = None,
50
+ aws_session_token: Secret | None = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
51
+ aws_region_name: Secret | None = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
52
+ aws_profile_name: Secret | None = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
53
+ boto3_config: dict[str, Any] | None = None,
54
54
  **kwargs: Any,
55
55
  ) -> None:
56
56
  """
@@ -94,7 +94,7 @@ class AmazonBedrockTextEmbedder:
94
94
  self.boto3_config = boto3_config
95
95
  self.kwargs = kwargs
96
96
 
97
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
97
+ def resolve_secret(secret: Secret | None) -> str | None:
98
98
  return secret.resolve_value() if secret else None
99
99
 
100
100
  try:
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  from abc import ABC, abstractmethod
3
- from typing import Any, Optional
3
+ from typing import Any
4
4
 
5
5
  from botocore.eventstream import EventStream
6
6
  from haystack.dataclasses import StreamingChunk, SyncStreamingCallbackT
@@ -19,7 +19,7 @@ class BedrockModelAdapter(ABC):
19
19
  It will be overridden by the corresponding parameter in the `model_kwargs` if it is present.
20
20
  """
21
21
 
22
- def __init__(self, model_kwargs: dict[str, Any], max_length: Optional[int]) -> None:
22
+ def __init__(self, model_kwargs: dict[str, Any], max_length: int | None) -> None:
23
23
  self.model_kwargs = model_kwargs
24
24
  self.max_length = max_length
25
25
 
@@ -115,7 +115,7 @@ class AnthropicClaudeAdapter(BedrockModelAdapter):
115
115
  :param max_length: Maximum length of generated text
116
116
  """
117
117
 
118
- def __init__(self, model_kwargs: dict[str, Any], max_length: Optional[int]) -> None:
118
+ def __init__(self, model_kwargs: dict[str, Any], max_length: int | None) -> None:
119
119
  self.use_messages_api = model_kwargs.get("use_messages_api", True)
120
120
  self.include_thinking = model_kwargs.get("include_thinking", True)
121
121
  self.thinking_tag = model_kwargs.get("thinking_tag", "thinking")
@@ -175,7 +175,7 @@ class AnthropicClaudeAdapter(BedrockModelAdapter):
175
175
  if self.include_thinking and len(thinking) == len(texts):
176
176
  texts = [
177
177
  f"{self.thinking_tag_start}{thinking}{self.thinking_tag_end}{text}"
178
- for text, thinking in zip(texts, thinking)
178
+ for text, thinking in zip(texts, thinking, strict=True)
179
179
  ]
180
180
  return texts
181
181
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Optional
1
+ from typing import Any
2
2
 
3
3
  import aioboto3
4
4
  from botocore.config import Config
@@ -140,26 +140,26 @@ class AmazonBedrockChatGenerator:
140
140
  automatically from the environment or the AWS configuration file.
141
141
  If the AWS environment is not configured, set `aws_access_key_id`, `aws_secret_access_key`,
142
142
  and `aws_region_name` as environment variables or pass them as
143
- [Secret](https://docs.haystack.deepset.ai/v2.0/docs/secret-management) arguments. Make sure the region you set
143
+ [Secret](https://docs.haystack.deepset.ai/docs/secret-management) arguments. Make sure the region you set
144
144
  supports Amazon Bedrock.
145
145
  """
146
146
 
147
147
  def __init__(
148
148
  self,
149
149
  model: str,
150
- aws_access_key_id: Optional[Secret] = Secret.from_env_var(["AWS_ACCESS_KEY_ID"], strict=False), # noqa: B008
151
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
150
+ aws_access_key_id: Secret | None = Secret.from_env_var(["AWS_ACCESS_KEY_ID"], strict=False), # noqa: B008
151
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
152
152
  ["AWS_SECRET_ACCESS_KEY"], strict=False
153
153
  ),
154
- aws_session_token: Optional[Secret] = Secret.from_env_var(["AWS_SESSION_TOKEN"], strict=False), # noqa: B008
155
- aws_region_name: Optional[Secret] = Secret.from_env_var(["AWS_DEFAULT_REGION"], strict=False), # noqa: B008
156
- aws_profile_name: Optional[Secret] = Secret.from_env_var(["AWS_PROFILE"], strict=False), # noqa: B008
157
- generation_kwargs: Optional[dict[str, Any]] = None,
158
- streaming_callback: Optional[StreamingCallbackT] = None,
159
- boto3_config: Optional[dict[str, Any]] = None,
160
- tools: Optional[ToolsType] = None,
154
+ aws_session_token: Secret | None = Secret.from_env_var(["AWS_SESSION_TOKEN"], strict=False), # noqa: B008
155
+ aws_region_name: Secret | None = Secret.from_env_var(["AWS_DEFAULT_REGION"], strict=False), # noqa: B008
156
+ aws_profile_name: Secret | None = Secret.from_env_var(["AWS_PROFILE"], strict=False), # noqa: B008
157
+ generation_kwargs: dict[str, Any] | None = None,
158
+ streaming_callback: StreamingCallbackT | None = None,
159
+ boto3_config: dict[str, Any] | None = None,
160
+ tools: ToolsType | None = None,
161
161
  *,
162
- guardrail_config: Optional[dict[str, str]] = None,
162
+ guardrail_config: dict[str, str] | None = None,
163
163
  ) -> None:
164
164
  """
165
165
  Initializes the `AmazonBedrockChatGenerator` with the provided parameters. The parameters are passed to the
@@ -225,7 +225,7 @@ class AmazonBedrockChatGenerator:
225
225
  _validate_guardrail_config(guardrail_config=guardrail_config, streaming=streaming_callback is not None)
226
226
  self.guardrail_config = guardrail_config
227
227
 
228
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
228
+ def resolve_secret(secret: Secret | None) -> str | None:
229
229
  return secret.resolve_value() if secret else None
230
230
 
231
231
  config = Config(
@@ -252,7 +252,7 @@ class AmazonBedrockChatGenerator:
252
252
  raise AmazonBedrockConfigurationError(msg) from exception
253
253
 
254
254
  self.generation_kwargs = generation_kwargs or {}
255
- self.async_session: Optional[aioboto3.Session] = None
255
+ self.async_session: aioboto3.Session | None = None
256
256
 
257
257
  def _get_async_session(self) -> aioboto3.Session:
258
258
  """
@@ -341,11 +341,11 @@ class AmazonBedrockChatGenerator:
341
341
  def _prepare_request_params(
342
342
  self,
343
343
  messages: list[ChatMessage],
344
- streaming_callback: Optional[StreamingCallbackT] = None,
345
- generation_kwargs: Optional[dict[str, Any]] = None,
346
- tools: Optional[ToolsType] = None,
344
+ streaming_callback: StreamingCallbackT | None = None,
345
+ generation_kwargs: dict[str, Any] | None = None,
346
+ tools: ToolsType | None = None,
347
347
  requires_async: bool = False,
348
- ) -> tuple[dict[str, Any], Optional[StreamingCallbackT]]:
348
+ ) -> tuple[dict[str, Any], StreamingCallbackT | None]:
349
349
  """
350
350
  Prepares and formats parameters required to call the Amazon Bedrock Converse API.
351
351
 
@@ -423,9 +423,9 @@ class AmazonBedrockChatGenerator:
423
423
  def run(
424
424
  self,
425
425
  messages: list[ChatMessage],
426
- streaming_callback: Optional[StreamingCallbackT] = None,
427
- generation_kwargs: Optional[dict[str, Any]] = None,
428
- tools: Optional[ToolsType] = None,
426
+ streaming_callback: StreamingCallbackT | None = None,
427
+ generation_kwargs: dict[str, Any] | None = None,
428
+ tools: ToolsType | None = None,
429
429
  ) -> dict[str, list[ChatMessage]]:
430
430
  """
431
431
  Executes a synchronous inference call to the Amazon Bedrock model using the Converse API.
@@ -484,9 +484,9 @@ class AmazonBedrockChatGenerator:
484
484
  async def run_async(
485
485
  self,
486
486
  messages: list[ChatMessage],
487
- streaming_callback: Optional[StreamingCallbackT] = None,
488
- generation_kwargs: Optional[dict[str, Any]] = None,
489
- tools: Optional[ToolsType] = None,
487
+ streaming_callback: StreamingCallbackT | None = None,
488
+ generation_kwargs: dict[str, Any] | None = None,
489
+ tools: ToolsType | None = None,
490
490
  ) -> dict[str, list[ChatMessage]]:
491
491
  """
492
492
  Executes an asynchronous inference call to the Amazon Bedrock model using the Converse API.
@@ -1,7 +1,7 @@
1
1
  import base64
2
2
  import json
3
3
  from datetime import datetime, timezone
4
- from typing import Any, Optional
4
+ from typing import Any
5
5
 
6
6
  from botocore.eventstream import EventStream
7
7
  from haystack import logging
@@ -40,7 +40,7 @@ FINISH_REASON_MAPPING: dict[str, FinishReason] = {
40
40
 
41
41
 
42
42
  # Haystack to Bedrock util methods
43
- def _format_tools(tools: Optional[list[Tool]] = None) -> Optional[dict[str, Any]]:
43
+ def _format_tools(tools: list[Tool] | None = None) -> dict[str, Any] | None:
44
44
  """
45
45
  Format Haystack Tool(s) to Amazon Bedrock toolConfig format.
46
46
 
@@ -454,7 +454,7 @@ def _convert_event_to_streaming_chunk(
454
454
  return streaming_chunk
455
455
 
456
456
 
457
- def _process_reasoning_contents(chunks: list[StreamingChunk]) -> Optional[ReasoningContent]:
457
+ def _process_reasoning_contents(chunks: list[StreamingChunk]) -> ReasoningContent | None:
458
458
  """
459
459
  Process reasoning contents from a list of StreamingChunk objects into the Bedrock expected format.
460
460
 
@@ -613,7 +613,7 @@ async def _parse_streaming_response_async(
613
613
  return [reply]
614
614
 
615
615
 
616
- def _validate_guardrail_config(guardrail_config: Optional[dict[str, str]] = None, streaming: bool = False) -> None:
616
+ def _validate_guardrail_config(guardrail_config: dict[str, str] | None = None, streaming: bool = False) -> None:
617
617
  """
618
618
  Validate the guardrail configuration.
619
619
 
@@ -1,7 +1,8 @@
1
1
  import json
2
2
  import re
3
3
  import warnings
4
- from typing import Any, Callable, ClassVar, Literal, Optional, Union, get_args
4
+ from collections.abc import Callable
5
+ from typing import Any, ClassVar, Literal, get_args
5
6
 
6
7
  from botocore.config import Config
7
8
  from botocore.exceptions import ClientError
@@ -58,7 +59,7 @@ class AmazonBedrockGenerator:
58
59
  automatically from the environment or the AWS configuration file.
59
60
  If the AWS environment is not configured, set `aws_access_key_id`, `aws_secret_access_key`,
60
61
  `aws_session_token`, and `aws_region_name` as environment variables or pass them as
61
- [Secret](https://docs.haystack.deepset.ai/v2.0/docs/secret-management) arguments. Make sure the region you set
62
+ [Secret](https://docs.haystack.deepset.ai/docs/secret-management) arguments. Make sure the region you set
62
63
  supports Amazon Bedrock.
63
64
  """
64
65
 
@@ -95,18 +96,18 @@ class AmazonBedrockGenerator:
95
96
  def __init__(
96
97
  self,
97
98
  model: str,
98
- aws_access_key_id: Optional[Secret] = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
99
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
99
+ aws_access_key_id: Secret | None = Secret.from_env_var("AWS_ACCESS_KEY_ID", strict=False), # noqa: B008
100
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
100
101
  "AWS_SECRET_ACCESS_KEY", strict=False
101
102
  ),
102
- aws_session_token: Optional[Secret] = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
103
- aws_region_name: Optional[Secret] = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
104
- aws_profile_name: Optional[Secret] = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
105
- max_length: Optional[int] = None,
106
- truncate: Optional[bool] = None,
107
- streaming_callback: Optional[Callable[[StreamingChunk], None]] = None,
108
- boto3_config: Optional[dict[str, Any]] = None,
109
- model_family: Optional[MODEL_FAMILIES] = None,
103
+ aws_session_token: Secret | None = Secret.from_env_var("AWS_SESSION_TOKEN", strict=False), # noqa: B008
104
+ aws_region_name: Secret | None = Secret.from_env_var("AWS_DEFAULT_REGION", strict=False), # noqa: B008
105
+ aws_profile_name: Secret | None = Secret.from_env_var("AWS_PROFILE", strict=False), # noqa: B008
106
+ max_length: int | None = None,
107
+ truncate: bool | None = None,
108
+ streaming_callback: Callable[[StreamingChunk], None] | None = None,
109
+ boto3_config: dict[str, Any] | None = None,
110
+ model_family: MODEL_FAMILIES | None = None,
110
111
  **kwargs: Any,
111
112
  ) -> None:
112
113
  """
@@ -156,7 +157,7 @@ class AmazonBedrockGenerator:
156
157
  self.kwargs = kwargs
157
158
  self.model_family = model_family
158
159
 
159
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
160
+ def resolve_secret(secret: Secret | None) -> str | None:
160
161
  return secret.resolve_value() if secret else None
161
162
 
162
163
  try:
@@ -187,9 +188,9 @@ class AmazonBedrockGenerator:
187
188
  def run(
188
189
  self,
189
190
  prompt: str,
190
- streaming_callback: Optional[Callable[[StreamingChunk], None]] = None,
191
- generation_kwargs: Optional[dict[str, Any]] = None,
192
- ) -> dict[str, Union[list[str], dict[str, Any]]]:
191
+ streaming_callback: Callable[[StreamingChunk], None] | None = None,
192
+ generation_kwargs: dict[str, Any] | None = None,
193
+ ) -> dict[str, list[str] | dict[str, Any]]:
193
194
  """
194
195
  Generates a list of string response to the given prompt.
195
196
 
@@ -240,7 +241,7 @@ class AmazonBedrockGenerator:
240
241
  return {"replies": replies, "meta": metadata}
241
242
 
242
243
  @classmethod
243
- def get_model_adapter(cls, model: str, model_family: Optional[str] = None) -> type[BedrockModelAdapter]:
244
+ def get_model_adapter(cls, model: str, model_family: str | None = None) -> type[BedrockModelAdapter]:
244
245
  """
245
246
  Gets the model adapter for the given model.
246
247
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Optional
1
+ from typing import Any
2
2
 
3
3
  from botocore.exceptions import ClientError
4
4
  from haystack import Document, component, default_from_dict, default_to_dict, logging
@@ -52,7 +52,7 @@ class AmazonBedrockRanker:
52
52
  automatically from the environment or the AWS configuration file.
53
53
  If the AWS environment is not configured, set `aws_access_key_id`, `aws_secret_access_key`,
54
54
  and `aws_region_name` as environment variables or pass them as
55
- [Secret](https://docs.haystack.deepset.ai/v2.0/docs/secret-management) arguments. Make sure the region you set
55
+ [Secret](https://docs.haystack.deepset.ai/docs/secret-management) arguments. Make sure the region you set
56
56
  supports Amazon Bedrock.
57
57
  """
58
58
 
@@ -60,15 +60,15 @@ class AmazonBedrockRanker:
60
60
  self,
61
61
  model: str = "cohere.rerank-v3-5:0",
62
62
  top_k: int = 10,
63
- aws_access_key_id: Optional[Secret] = Secret.from_env_var(["AWS_ACCESS_KEY_ID"], strict=False), # noqa: B008
64
- aws_secret_access_key: Optional[Secret] = Secret.from_env_var( # noqa: B008
63
+ aws_access_key_id: Secret | None = Secret.from_env_var(["AWS_ACCESS_KEY_ID"], strict=False), # noqa: B008
64
+ aws_secret_access_key: Secret | None = Secret.from_env_var( # noqa: B008
65
65
  ["AWS_SECRET_ACCESS_KEY"], strict=False
66
66
  ),
67
- aws_session_token: Optional[Secret] = Secret.from_env_var(["AWS_SESSION_TOKEN"], strict=False), # noqa: B008
68
- aws_region_name: Optional[Secret] = Secret.from_env_var(["AWS_DEFAULT_REGION"], strict=False), # noqa: B008
69
- aws_profile_name: Optional[Secret] = Secret.from_env_var(["AWS_PROFILE"], strict=False), # noqa: B008
70
- max_chunks_per_doc: Optional[int] = None,
71
- meta_fields_to_embed: Optional[list[str]] = None,
67
+ aws_session_token: Secret | None = Secret.from_env_var(["AWS_SESSION_TOKEN"], strict=False), # noqa: B008
68
+ aws_region_name: Secret | None = Secret.from_env_var(["AWS_DEFAULT_REGION"], strict=False), # noqa: B008
69
+ aws_profile_name: Secret | None = Secret.from_env_var(["AWS_PROFILE"], strict=False), # noqa: B008
70
+ max_chunks_per_doc: int | None = None,
71
+ meta_fields_to_embed: list[str] | None = None,
72
72
  meta_data_separator: str = "\n",
73
73
  ) -> None:
74
74
  if not model:
@@ -103,7 +103,7 @@ class AmazonBedrockRanker:
103
103
  self.meta_fields_to_embed = meta_fields_to_embed or []
104
104
  self.meta_data_separator = meta_data_separator
105
105
 
106
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
106
+ def resolve_secret(secret: Secret | None) -> str | None:
107
107
  return secret.resolve_value() if secret else None
108
108
 
109
109
  try:
@@ -177,7 +177,7 @@ class AmazonBedrockRanker:
177
177
  return concatenated_input_list
178
178
 
179
179
  @component.output_types(documents=list[Document])
180
- def run(self, query: str, documents: list[Document], top_k: Optional[int] = None) -> dict[str, list[Document]]:
180
+ def run(self, query: str, documents: list[Document], top_k: int | None = None) -> dict[str, list[Document]]:
181
181
  """
182
182
  Use the Amazon Bedrock Reranker to re-rank the list of documents based on the query.
183
183
 
@@ -201,7 +201,7 @@ class AmazonBedrockRanker:
201
201
  if not documents:
202
202
  return {"documents": []}
203
203
 
204
- def resolve_secret(secret: Optional[Secret]) -> Optional[str]:
204
+ def resolve_secret(secret: Secret | None) -> str | None:
205
205
  return secret.resolve_value() if secret else None
206
206
 
207
207
  region = resolve_secret(self.aws_region_name)