Skip to content

fix(google_genai): use dataclass replace to avoid modifying input documents#2762

Merged
davidsbatista merged 2 commits into
deepset-ai:mainfrom
GunaPalanivel:fix/google-genai-document-embedder-immutability-2174
Jan 19, 2026
Merged

fix(google_genai): use dataclass replace to avoid modifying input documents#2762
davidsbatista merged 2 commits into
deepset-ai:mainfrom
GunaPalanivel:fix/google-genai-document-embedder-immutability-2174

Conversation

@GunaPalanivel
Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes

This PR fixes the Google GenAI Document Embedder to not modify input Documents in place when setting embeddings.

Changes Made

GoogleGenAIDocumentEmbedder:

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

Tests Added

  • test_run_does_not_modify_original_documents for document embedder
  • test_run_async_does_not_modify_original_documents for document embedder

How did you test it?

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

Notes for the reviewer

This follows the established pattern from:

…uments

This PR fixes the Google GenAI document embedder to not modify input
Documents in place when setting embeddings.

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

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

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

Related to: deepset-ai#2174
@GunaPalanivel GunaPalanivel requested a review from a team as a code owner January 17, 2026 05:24
@GunaPalanivel GunaPalanivel requested review from davidsbatista and removed request for a team January 17, 2026 05:24
Copy link
Copy Markdown
Contributor

@davidsbatista davidsbatista left a comment

Choose a reason for hiding this comment

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

LGTM! thanks for yet another contribution @GunaPalanivel

@davidsbatista davidsbatista merged commit ed6f209 into deepset-ai:main Jan 19, 2026
10 checks passed
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