Skip to content

fix: keep init parameters when serializing RecursiveDocumentSplitter and TextCleaner - #12738

Merged
sjrl merged 2 commits into
deepset-ai:mainfrom
alanhuangyoo:fix/splitter-cleaner-serialization
Sep 14, 2026
Merged

sjrl merged 2 commits into
deepset-ai:mainfrom
alanhuangyoo:fix/splitter-cleaner-serialization

Conversation

@alanhuangyoo

Copy link
Copy Markdown
Contributor

Related Issues

  • No issue. Found while checking which components rely on the default component_to_dict fallback.

Proposed Changes:

RecursiveDocumentSplitter and TextCleaner have no to_dict, so component_to_dict reads an attribute named after each init parameter. When that attribute doesn't exist, it quietly uses the signature default.

  • RecursiveDocumentSplitter stores split_unit as self.split_units, so it always serializes split_unit: word. After Pipeline.dumps() / loads(), a splitter created with split_unit="char" or "token" counts words instead.
  • TextCleaner keeps all four options in underscored attributes, so every option serializes as its default and a reloaded cleaner returns the texts unchanged.
original: split_units='char' chunks=['alpha ', 'beta ', 'gamma ', 'delta ', 'epsilon ', 'zeta eta ', 'theta'] cleaner=['hello world']
reloaded: split_units='word' chunks=['alpha beta gamma delta epsilon zeta eta theta'] cleaner=['Hello, World!']

The existing test_run_serialization_in_pipeline compares two dumps, which are both wrong in the same way, so it passes.

Both classes now get a to_dict that writes the stored values under the init parameter names. Deserialization still goes through default_from_dict, and the attribute names stay as they are.

How did you test it?

  • New tests test_serialization_keeps_split_unit and test_serialization_keeps_init_parameters check the serialized init parameters and that a pipeline loaded from YAML gives the same output as the original. Both fail on main.
  • pytest -m "not integration" test/components/preprocessors test/core/pipeline test/core/test_serialization.py: 834 passed, 22 failed. The failures are the same on main: 21 need the NLTK punkt_tab data, which isn't downloaded here, and test_show_in_notebook needs IPython.
  • ruff check, ruff format --check, and mypy on the four changed Python files pass.

Notes for the reviewer

I checked every @component class in haystack/ without a to_dict for the same mismatch between init parameter and attribute names. Apart from the Repeat sample component in haystack/testing, these two are the only ones.

Checklist

This PR was fully generated with an AI assistant (Claude Code), including the fix, the tests and this description. The checks above are the ones that were actually run.

🤖 Generated with Claude Code

…and TextCleaner

Neither class had to_dict, so serialization fell back to reading
attributes named after the init parameters and used the defaults when
they were missing. RecursiveDocumentSplitter stores split_unit as
split_units and TextCleaner stores its options in underscored
attributes, so a pipeline saved and loaded again got a word splitter
and a cleaner that does nothing.

Co-Authored-By: Claude Opus 5 <[email protected]>
@alanhuangyoo
alanhuangyoo requested a review from a team as a code owner September 13, 2026 22:02
@alanhuangyoo
alanhuangyoo requested review from sjrl and removed request for a team September 13, 2026 22:02
@vercel

vercel Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

@alanhuangyoo is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @alanhuangyoo, thanks for your interest in contributing to Haystack! 🙏

⚠️ You currently have 3 open pull requests in this repository (#12737, #12736 and this one). Our review capacity is limited, so please hold off opening more PRs until we've had a chance to review your first 2 open PRs. This helps us give each contribution the attention it deserves. Thank you!

This is an automated message to help us keep the review queue healthy.

@github-actions github-actions Bot added the type:documentation Improvements on the docs label Sep 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/preprocessors
  recursive_splitter.py
  text_cleaner.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants