Skip to content

fix(watsonx): use dataclass replace to avoid modifying input documents#2766

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

fix(watsonx): use dataclass replace to avoid modifying input documents#2766
sjrl merged 1 commit into
deepset-ai:mainfrom
GunaPalanivel:fix/watsonx-document-embedder-immutability-2174

Conversation

@GunaPalanivel
Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes

This PR fixes the Watson X Document Embedder to avoid mutating input Documents when setting embeddings.

Changes Made

WatsonxDocumentEmbedder:

  • run() method: Use replace(doc, embedding=emb) instead of doc.embedding = emb

Tests Added

  • test_run_does_not_modify_original_documents for document embedder

How did you test it?

cd integrations/watsonx
hatch run test:unit  # All 58 tests pass
hatch run fmt-check  # All checks pass

Notes for the reviewer

This follows the established pattern from:

This PR fixes the Watson X Document Embedder to avoid mutating input
Documents when setting embeddings.

Instead of mutating the original documents:
  doc.embedding = emb

We now create new document instances using dataclass replace:
  replace(doc, embedding=emb)

This follows the established pattern from haystack-ai/haystack#9693 and
aligns with other integrations (FastEmbed, Optimum, Nvidia, Bedrock, Cohere,
Google GenAI, Jina).

Related to: deepset-ai#2174
@GunaPalanivel GunaPalanivel requested a review from a team as a code owner January 20, 2026 13:18
@GunaPalanivel GunaPalanivel requested review from sjrl and removed request for a team January 20, 2026 13:18
@github-actions github-actions Bot added integration:watsonx type:documentation Improvements or additions to documentation labels Jan 20, 2026
@sjrl sjrl self-assigned this Jan 20, 2026
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 8195716 into deepset-ai:main Jan 21, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:watsonx type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adjust Document Embedders in core integrations to not modify Documents in place

2 participants