Repository navigation
feat: make the tiktoken encoding configurable in RecursiveDocumentSpl… - #12974
Merged
sjrl merged 3 commits intoOct 15, 2026
Merged
Conversation
…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
requested review from
julian-risch
and removed request for
a team
September 26, 2026 15:19
Contributor
|
@shivsin25 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
# Conflicts: # haystack/components/preprocessors/recursive_splitter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Proposed Changes:
tokenizer_encodingparameter (default"o200k_base", the encoding used until now), with the same name, default and docstring as inDocumentSplitter.warm_up()loads that encoding instead of the hardcodedo200k_base.tokenizer_encodingis serialized. Pipelines saved before this change still load with the default.split_unitdocstring, the docs page and added a release note.How did you test it?
warm_up()callstiktoken.get_encodingwith the configured encoding, and a pipeline round trip keeps it. Loading a pipeline dict withouttokenizer_encodingfalls back to the default.o200k_baseandcl100k_base: the splitter uses the requested encoding, and every chunk stays withinsplit_lengthtokens in that encoding.mainand pass with this change.hatch run test:unit test/components/preprocessorsandhatch run test:integration test/components/preprocessors: all pass.hatch run test:unit: 6550 passed. One unrelated failure on my Windows machine:test_byte_stream.pyexpectstext/csv, but Windows maps.csvto Excel's MIME type.hatch run test:typesandhatch run fmt-checkare 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+FFFDreplacement characters. It happens onmainwith the default encoding too, for example with emoji or rare CJK characters and a smallsplit_length.DocumentSplitteravoids 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
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.