Skip to content

feat: make the tiktoken encoding configurable in RecursiveDocumentSpl… - #12974

Merged
sjrl merged 3 commits into
deepset-ai:mainfrom
shivsin25:feat/recursive-splitter-tokenizer-encoding
Oct 15, 2026
Merged

sjrl merged 3 commits into
deepset-ai:mainfrom
shivsin25:feat/recursive-splitter-tokenizer-encoding

Conversation

@shivsin25

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

  • New keyword-only tokenizer_encoding parameter (default "o200k_base", the encoding used until now), with the same name, default and docstring as in DocumentSplitter. warm_up() loads that encoding instead of the hardcoded o200k_base.
  • tokenizer_encoding is serialized. Pipelines saved before this change still load with the default.
  • Updated the split_unit docstring, the docs page and added a release note.

How did you test it?

  • Unit tests (no network): warm_up() calls tiktoken.get_encoding with the configured encoding, and a pipeline round trip keeps it. Loading a pipeline dict without tokenizer_encoding falls back to the default.
  • Integration test with real tiktoken for o200k_base and cl100k_base: the splitter uses the requested encoding, and every chunk stays within split_length tokens in that encoding.
  • The new tests fail on main and pass with this change.
  • hatch run test:unit test/components/preprocessors and hatch run test:integration test/components/preprocessors: all pass.
  • hatch run test:unit: 6550 passed. One unrelated failure on my Windows machine: test_byte_stream.py expects text/csv, but Windows maps .csv to Excel's MIME type.
  • hatch run test:types and hatch run fmt-check are clean. The pre-commit hooks pass.

Notes for the reviewer

While testing with non-English text I found a separate, existing problem: when a token slice ends in the middle of a multi-byte character, the chunk is decoded with U+FFFD replacement characters. It happens on main with the default encoding too, for example with emoji or rare CJK characters and a small split_length. DocumentSplitter avoids this by decoding with offsets. I kept it out of this PR and will open a separate issue for it.

I used an AI assistant while working on this and reviewed and tested all changes myself.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

…itter

Add a keyword-only tokenizer_encoding parameter, defaulting to the
previously hardcoded "o200k_base", so that token-based chunks can be sized
with the encoding of the model they are meant for. Same name, default and
behavior as in DocumentSplitter.

Closes deepset-ai#12973

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@shivsin25
shivsin25 requested a review from a team as a code owner September 26, 2026 15:19
@shivsin25
shivsin25 requested review from julian-risch and removed request for a team September 26, 2026 15:19
@vercel

vercel Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

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
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!

@sjrl
sjrl merged commit 2c3d20e into deepset-ai:main Oct 15, 2026
23 of 24 checks passed
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.

Make the tiktoken encoding configurable in RecursiveDocumentSplitter

2 participants