Summary. In _split_large_section, the paragraph-boundary branch emits the accumulated text without any size enforcement. If the accumulated lines include a single very long line (e.g. a Markdown table cell containing a dumped JSON response — 21,004 chars in our corpus), the whole accumulation is emitted as one chunk. _split_long_text exists but is never applied on this path, so max_chunk_size=1500 is not honored.
Observed. A 23 KB Confluence-exported markdown file produced a 21,061-char chunk (8,518 tokens). Since OnnxEmbedding pads the whole batch (default 32) to the longest sequence (truncation cap 8192), one such chunk inflates an entire batch to batch × 8192 tokens, and attention scales with batch × seq². On an Apple M3 Pro the file stalled for ~88 minutes and the process was then killed by memory pressure. Re-running the same file with --batch-size 2 indexed it in 41 s — which is a workaround, not a fix, since the oversized chunk still gets truncated and embedded as a single degraded vector.
Repro sketch.
from memsearch.chunker import chunk_markdown
text = "# T\n\n| h |\n| :-- |\n| " + ("x" * 21000) + " |\n\nnext paragraph\n"
chunks = chunk_markdown(text, source="t.md", max_chunk_size=1500)
print(max(len(c.content) for c in chunks)) # far beyond 1500
Suggested fix.
- Enforce
max_chunk_size on every emit path in _split_large_section (apply _split_long_text to any oversized emit), and/or
- Sort chunks by token length before batching in the embedding providers so padding waste is bounded by similar-length neighbors.
Related operational context in #613 (we found both while diagnosing a multi-hour indexing loop).
Summary. In
_split_large_section, the paragraph-boundary branch emits the accumulated text without any size enforcement. If the accumulated lines include a single very long line (e.g. a Markdown table cell containing a dumped JSON response — 21,004 chars in our corpus), the whole accumulation is emitted as one chunk._split_long_textexists but is never applied on this path, somax_chunk_size=1500is not honored.Observed. A 23 KB Confluence-exported markdown file produced a 21,061-char chunk (8,518 tokens). Since
OnnxEmbeddingpads the whole batch (default 32) to the longest sequence (truncation cap 8192), one such chunk inflates an entire batch tobatch × 8192tokens, and attention scales withbatch × seq². On an Apple M3 Pro the file stalled for ~88 minutes and the process was then killed by memory pressure. Re-running the same file with--batch-size 2indexed it in 41 s — which is a workaround, not a fix, since the oversized chunk still gets truncated and embedded as a single degraded vector.Repro sketch.
Suggested fix.
max_chunk_sizeon every emit path in_split_large_section(apply_split_long_textto any oversized emit), and/orRelated operational context in #613 (we found both while diagnosing a multi-hour indexing loop).