Skip to content

fix: Update AmazonBedrockDocumentEmbedder to not modify Documents in place#2702

Merged
sjrl merged 1 commit into
deepset-ai:mainfrom
GunaPalanivel:fix/bedrock-document-embedder-immutability-2174
Jan 13, 2026
Merged

fix: Update AmazonBedrockDocumentEmbedder to not modify Documents in place#2702
sjrl merged 1 commit into
deepset-ai:mainfrom
GunaPalanivel:fix/bedrock-document-embedder-immutability-2174

Conversation

@GunaPalanivel
Copy link
Copy Markdown
Contributor

@GunaPalanivel GunaPalanivel commented Jan 11, 2026

Description

partially addresses #2174

Updates AmazonBedrockDocumentEmbedder to create new Document instances instead of modifying them in place, following the pattern established in Haystack core (#9693) and recent fixes in FastEmbed (#2678), Optimum (#2675), and Nvidia (#2680) integrations.

Changes

Code Changes

  • Added from dataclasses import replace import
  • Updated _embed_cohere() method to create new document instances using replace(doc, embedding=emb)
  • Updated _embed_titan() method to create new document instances using replace(doc, embedding=emb)

Test Changes

  • Added test_run_cohere_does_not_modify_original_documents() to verify Cohere path creates new instances
  • Added test_run_titan_does_not_modify_original_documents() to verify Titan path creates new instances
  • Both tests confirm original documents remain unchanged and new instances contain embeddings

Documentation

  • Updated CHANGELOG.md with bug fix entry

Testing

All tests pass successfully:

  • ✅ Format check: hatch run fmt-check
  • ✅ Type checking: hatch run test:types
  • ✅ Unit tests: hatch run test:unit (213 passed including 2 new immutability tests)

Notes

  • AmazonBedrockDocumentImageEmbedder already uses the correct pattern (implemented in feat: Add AmazonBedrockDocumentImageEmbedder component #2185)
  • No AmazonBedrockSparseDocumentEmbedder exists in this integration
  • Follows the same immutability pattern as other integrations for consistency across the codebase

Comment thread integrations/amazon_bedrock/CHANGELOG.md Outdated
@sjrl sjrl self-assigned this Jan 12, 2026
@sjrl
Copy link
Copy Markdown
Contributor

sjrl commented Jan 12, 2026

@GunaPalanivel thanks for the changes! Could you also update the code here

sorted_docs = []
for result in results:
idx = result["index"]
score = result["relevanceScore"]
doc = documents[idx]
doc.score = score
sorted_docs.append(doc)
in the AmazonBedrockRanker to use replace as well

@GunaPalanivel GunaPalanivel force-pushed the fix/bedrock-document-embedder-immutability-2174 branch from 1762a72 to d1915ee Compare January 12, 2026 07:48
@GunaPalanivel
Copy link
Copy Markdown
Contributor Author

GunaPalanivel commented Jan 12, 2026

@GunaPalanivel thanks for the changes! Could you also update the code here

sorted_docs = []
for result in results:
idx = result["index"]
score = result["relevanceScore"]
doc = documents[idx]
doc.score = score
sorted_docs.append(doc)

in the AmazonBedrockRanker to use replace as well

Added from dataclasses import replace import
Changed doc.score = score to replace(doc, score=score)
Now creates new document instances instead of modifying in place

Comment thread integrations/amazon_bedrock/CHANGELOG.md
…eepset-ai#2174)

- Add dataclasses.replace import
- Update _embed_cohere to create new document instances
- Update _embed_titan to create new document instances
- Add immutability tests for both Cohere and Titan paths
- Update CHANGELOG.md with bug fix entry

Follows the pattern from FastEmbed, Optimum, and Nvidia integrations.
@GunaPalanivel GunaPalanivel force-pushed the fix/bedrock-document-embedder-immutability-2174 branch from d1915ee to f5bb112 Compare January 12, 2026 07:52
Copy link
Copy Markdown
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sjrl sjrl merged commit 03ef120 into deepset-ai:main Jan 13, 2026
10 checks passed
davidsbatista pushed a commit that referenced this pull request Jan 13, 2026
…2174) (#2702)

- Add dataclasses.replace import
- Update _embed_cohere to create new document instances
- Update _embed_titan to create new document instances
- Add immutability tests for both Cohere and Titan paths
- Update CHANGELOG.md with bug fix entry

Follows the pattern from FastEmbed, Optimum, and Nvidia integrations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants