amazon-bedrock-haystack 6.0.0__tar.gz → 6.1.0__tar.gz
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.
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/CHANGELOG.md +7 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/PKG-INFO +1 -1
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/embedders/amazon_bedrock/document_embedder.py +7 -4
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/rankers/amazon_bedrock/ranker.py +2 -2
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_document_embedder.py +68 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/.gitignore +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/LICENSE.txt +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/README.md +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/bedrock_ranker_example.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/chatgenerator_example.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/embedders_generator_with_rag_example.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/s3_downloader_example.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/pydoc/config_docusaurus.yml +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/pyproject.toml +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/amazon_bedrock/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/amazon_bedrock/errors.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/amazon_bedrock/utils.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/py.typed +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/s3/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/s3/errors.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/common/s3/utils.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/downloaders/py.typed +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/downloaders/s3/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/downloaders/s3/s3_downloader.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/embedders/amazon_bedrock/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/embedders/amazon_bedrock/document_image_embedder.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/embedders/amazon_bedrock/text_embedder.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/amazon_bedrock/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/amazon_bedrock/adapters.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/amazon_bedrock/chat/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/amazon_bedrock/chat/utils.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/amazon_bedrock/generator.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/rankers/amazon_bedrock/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/src/haystack_integrations/components/rankers/py.typed +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/__init__.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/conftest.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_chat_generator.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_chat_generator_utils.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_document_image_embedder.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_files/apple.jpg +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_files/haystack-logo.png +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_files/sample_pdf_1.pdf +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_generator.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_ranker.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_s3_downloader.py +0 -0
- {amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_text_embedder.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: amazon-bedrock-haystack
|
|
3
|
-
Version: 6.
|
|
3
|
+
Version: 6.1.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
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
from dataclasses import replace
|
|
2
3
|
from typing import Any
|
|
3
4
|
|
|
4
5
|
from botocore.config import Config
|
|
@@ -186,10 +187,11 @@ class AmazonBedrockDocumentEmbedder:
|
|
|
186
187
|
)
|
|
187
188
|
all_embeddings.extend(embeddings_list)
|
|
188
189
|
|
|
190
|
+
new_documents = []
|
|
189
191
|
for doc, emb in zip(documents, all_embeddings, strict=True):
|
|
190
|
-
doc
|
|
192
|
+
new_documents.append(replace(doc, embedding=emb))
|
|
191
193
|
|
|
192
|
-
return
|
|
194
|
+
return new_documents
|
|
193
195
|
|
|
194
196
|
def _embed_titan(self, documents: list[Document]) -> list[Document]:
|
|
195
197
|
"""
|
|
@@ -214,10 +216,11 @@ class AmazonBedrockDocumentEmbedder:
|
|
|
214
216
|
embedding = response_body["embedding"]
|
|
215
217
|
all_embeddings.append(embedding)
|
|
216
218
|
|
|
219
|
+
new_documents = []
|
|
217
220
|
for doc, emb in zip(documents, all_embeddings, strict=True):
|
|
218
|
-
doc
|
|
221
|
+
new_documents.append(replace(doc, embedding=emb))
|
|
219
222
|
|
|
220
|
-
return
|
|
223
|
+
return new_documents
|
|
221
224
|
|
|
222
225
|
@component.output_types(documents=list[Document])
|
|
223
226
|
def run(self, documents: list[Document]) -> dict[str, list[Document]]:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from dataclasses import replace
|
|
1
2
|
from typing import Any
|
|
2
3
|
|
|
3
4
|
from botocore.exceptions import ClientError
|
|
@@ -251,8 +252,7 @@ class AmazonBedrockRanker:
|
|
|
251
252
|
idx = result["index"]
|
|
252
253
|
score = result["relevanceScore"]
|
|
253
254
|
doc = documents[idx]
|
|
254
|
-
doc
|
|
255
|
-
sorted_docs.append(doc)
|
|
255
|
+
sorted_docs.append(replace(doc, score=score))
|
|
256
256
|
|
|
257
257
|
return {"documents": sorted_docs}
|
|
258
258
|
except ClientError as client_error:
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_document_embedder.py
RENAMED
|
@@ -257,6 +257,74 @@ class TestAmazonBedrockDocumentEmbedder:
|
|
|
257
257
|
assert doc.content == docs[i].content
|
|
258
258
|
assert doc.embedding == [0.1, 0.2, 0.3]
|
|
259
259
|
|
|
260
|
+
def test_run_cohere_does_not_modify_original_documents(self, mock_boto3_session):
|
|
261
|
+
embedder = AmazonBedrockDocumentEmbedder(model="cohere.embed-english-v3")
|
|
262
|
+
|
|
263
|
+
original_docs = [
|
|
264
|
+
Document(content="test 1", id="doc1"),
|
|
265
|
+
Document(content="test 2", id="doc2"),
|
|
266
|
+
]
|
|
267
|
+
|
|
268
|
+
# Store original IDs to verify they're the same objects
|
|
269
|
+
original_doc_ids = [id(doc) for doc in original_docs]
|
|
270
|
+
original_embeddings = [doc.embedding for doc in original_docs]
|
|
271
|
+
|
|
272
|
+
with patch.object(embedder, "_client") as mock_client:
|
|
273
|
+
mock_client.invoke_model.return_value = {
|
|
274
|
+
"body": io.StringIO('{"embeddings": [[0.1, 0.2], [0.3, 0.4]]}'),
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
result = embedder.run(documents=original_docs)
|
|
278
|
+
|
|
279
|
+
# Verify originals are unchanged
|
|
280
|
+
assert all(doc.embedding is None for doc in original_docs)
|
|
281
|
+
assert original_embeddings == [None, None]
|
|
282
|
+
|
|
283
|
+
# Verify returned documents are NEW instances
|
|
284
|
+
returned_doc_ids = [id(doc) for doc in result["documents"]]
|
|
285
|
+
assert original_doc_ids != returned_doc_ids
|
|
286
|
+
|
|
287
|
+
# Verify returned documents have embeddings
|
|
288
|
+
assert result["documents"][0].embedding == [0.1, 0.2]
|
|
289
|
+
assert result["documents"][1].embedding == [0.3, 0.4]
|
|
290
|
+
assert result["documents"][0].content == "test 1"
|
|
291
|
+
assert result["documents"][1].content == "test 2"
|
|
292
|
+
|
|
293
|
+
def test_run_titan_does_not_modify_original_documents(self, mock_boto3_session):
|
|
294
|
+
embedder = AmazonBedrockDocumentEmbedder(model="amazon.titan-embed-text-v1")
|
|
295
|
+
|
|
296
|
+
original_docs = [
|
|
297
|
+
Document(content="test 1", id="doc1"),
|
|
298
|
+
Document(content="test 2", id="doc2"),
|
|
299
|
+
]
|
|
300
|
+
|
|
301
|
+
# Store original IDs to verify they're the same objects
|
|
302
|
+
original_doc_ids = [id(doc) for doc in original_docs]
|
|
303
|
+
original_embeddings = [doc.embedding for doc in original_docs]
|
|
304
|
+
|
|
305
|
+
with patch.object(embedder, "_client") as mock_client:
|
|
306
|
+
# Titan returns one embedding at a time
|
|
307
|
+
mock_client.invoke_model.side_effect = [
|
|
308
|
+
{"body": io.StringIO('{"embedding": [0.1, 0.2]}')},
|
|
309
|
+
{"body": io.StringIO('{"embedding": [0.3, 0.4]}')},
|
|
310
|
+
]
|
|
311
|
+
|
|
312
|
+
result = embedder.run(documents=original_docs)
|
|
313
|
+
|
|
314
|
+
# Verify originals are unchanged
|
|
315
|
+
assert all(doc.embedding is None for doc in original_docs)
|
|
316
|
+
assert original_embeddings == [None, None]
|
|
317
|
+
|
|
318
|
+
# Verify returned documents are NEW instances
|
|
319
|
+
returned_doc_ids = [id(doc) for doc in result["documents"]]
|
|
320
|
+
assert original_doc_ids != returned_doc_ids
|
|
321
|
+
|
|
322
|
+
# Verify returned documents have embeddings
|
|
323
|
+
assert result["documents"][0].embedding == [0.1, 0.2]
|
|
324
|
+
assert result["documents"][1].embedding == [0.3, 0.4]
|
|
325
|
+
assert result["documents"][0].content == "test 1"
|
|
326
|
+
assert result["documents"][1].content == "test 2"
|
|
327
|
+
|
|
260
328
|
@pytest.mark.integration
|
|
261
329
|
@pytest.mark.skipif(
|
|
262
330
|
not os.getenv("AWS_ACCESS_KEY_ID")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/bedrock_ranker_example.py
RENAMED
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/chatgenerator_example.py
RENAMED
|
File without changes
|
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/examples/s3_downloader_example.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_chat_generator.py
RENAMED
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_chat_generator_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_files/haystack-logo.png
RENAMED
|
File without changes
|
{amazon_bedrock_haystack-6.0.0 → amazon_bedrock_haystack-6.1.0}/tests/test_files/sample_pdf_1.pdf
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|