fix(chunking): don't repeat a very large split element in every chunk

Merged
KH
1mo ago
+158-5

Fixes #3872.

Each chunk split from one element gets the whole element in metadata.orig_elements and serializes its own copy. The spreadsheet in the issue becomes one Table with 9.6 MB of text_as_html, chunk_by_title cuts it into 12,555 chunks, and the JSON ends up around 54 GB.

This adds SPLIT_ORIG_ELEMENTS_MAX_CHARS = 1,000,000 (text + HTML + image data). If a single element over that limit really gets split into more than one chunk, those chunks skip orig_elements and a warning is logged. Everything else works as before, including large elements that fit in one chunk and pre-chunks with several elements.

With default by_title options the issue's file now gives 24 MB of JSON in 0.5 s.

Keeping orig_elements on the first chunk only would also work, if you prefer that.