Skip to content

fix: keep EmbeddingBasedDocumentSplitter.run_async on the async path - #12358

Open
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/embedding-splitter-async-recursion
Open

fix: keep EmbeddingBasedDocumentSplitter.run_async on the async path#12358
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/embedding-splitter-async-recursion

Conversation

@pcbeingused333

Copy link
Copy Markdown

Related Issues

  • No issue; found while reading the component.

Proposed Changes:

EmbeddingBasedDocumentSplitter._split_document_async is only async for the first pass:

splits = await self._split_text_async(text=doc.content)
merged_splits = self._merge_small_splits(splits=splits)
final_splits = self._split_large_splits(splits=merged_splits)   # synchronous

_split_large_splits re-splits every chunk that came out longer than max_length by calling _split_text, which calls _calculate_embeddings, which calls self.document_embedder.run(...). So in run_async the 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_length is 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?

  • New unit test test_recursive_split_of_large_chunks_stays_async: a recording embedder that implements both run and run_async, and a document long enough that the first pass produces a chunk over max_length. The test asserts the async path is used more than once (so the recursion did happen) and that run is never called. On main it fails with sync == 1.
  • hatch run test:unit — 6116 passed, 10 skipped.
  • hatch run test:types and hatch run fmt clean.

Notes for the reviewer

The two _split_large_splits methods 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

`_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>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner August 15, 2026 01:22
@pcbeingused333
pcbeingused333 requested review from sjrl and removed request for a team August 15, 2026 01:22
@vercel

vercel Bot commented Aug 15, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Aug 15, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @pcbeingused333, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from sjrl August 15, 2026 02:37
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Aug 15, 2026
@HaystackBot
HaystackBot marked this pull request as draft August 15, 2026 02:37
@pcbeingused333

Copy link
Copy Markdown
Author

recheck

@pcbeingused333
pcbeingused333 marked this pull request as ready for review August 15, 2026 04:12
@HaystackBot
HaystackBot requested a review from sjrl August 15, 2026 04:29
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @pcbeingused333! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Aug 15, 2026
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.

3 participants