fix: keep EmbeddingBasedDocumentSplitter.run_async on the async path - #12358
Open
pcbeingused333 wants to merge 1 commit into
Open
fix: keep EmbeddingBasedDocumentSplitter.run_async on the async path#12358pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
`_split_document_async` embeds the first pass through `_split_text_async`, then hands the result to `_split_large_splits`, which is synchronous: every chunk that came out longer than `max_length` is re-split through `_split_text`, which calls the embedder's blocking `run`. So the recursion runs the embedder's network calls on the event loop, and the deeper the recursion the longer the loop is blocked - `max_length` is exactly the setting that makes the recursion happen. Add `_split_large_splits_async`, mirroring the sync version but awaiting `_split_text_async`, and call it from `_split_document_async`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Someone is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @pcbeingused333, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
HaystackBot
marked this pull request as draft
August 15, 2026 02:37
Author
|
recheck |
Contributor
|
Thanks for signing the CLA, @pcbeingused333! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
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:
EmbeddingBasedDocumentSplitter._split_document_asyncis only async for the first pass:_split_large_splitsre-splits every chunk that came out longer thanmax_lengthby calling_split_text, which calls_calculate_embeddings, which callsself.document_embedder.run(...). So inrun_asyncthe recursion embeds through the blocking path, on the event loop, once per over-long chunk and again at every level of the recursion.This is not an edge case —
max_lengthis the setting whose whole purpose is to trigger that recursion, and the sync path is identical up to that point, so the async version silently behaves like the sync one for the most expensive part of the work.Added
_split_large_splits_async, mirroring the sync version but awaiting_split_text_async, and called it from_split_document_async. The sync path is untouched.How did you test it?
test_recursive_split_of_large_chunks_stays_async: a recording embedder that implements bothrunandrun_async, and a document long enough that the first pass produces a chunk overmax_length. The test asserts the async path is used more than once (so the recursion did happen) and thatrunis never called. Onmainit fails withsync == 1.hatch run test:unit— 6116 passed, 10 skipped.hatch run test:typesandhatch run fmtclean.Notes for the reviewer
The two
_split_large_splitsmethods are near-duplicates, which I kept deliberately: the alternative is to thread an "am I async" flag through the recursion, and the sync/async pairs elsewhere in this file (_split_document,_split_text,_calculate_embeddings) are written the same way.I used an AI assistant while writing this change. I have reviewed it, reproduced the behaviour, and run the tests.
Checklist