Repository navigation
A split paragraph's first chunk carries its headings once - #1285
Merged
WaylandYang merged 2 commits intoOct 16, 2026
Merged
Conversation
Signed-off-by: dada-yan <[email protected]>
WaylandYang
approved these changes
Oct 16, 2026
WaylandYang
left a comment
Contributor
There was a problem hiding this comment.
Thank you. The diagnosis is exact: the first piece's prefix was recomputed after its headings had left pending, so they were printed twice and could push the chunk over budget. Keeping the earlier prefix for that piece, as table_unit does, fixes it without moving any boundaries. A possible simplification for later: if the prefix is recomputed after each flush() instead of before it, the first flag and the unreachable!() copy of headings can both go. Merging.
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.
When the first block after a heading (a paragraph, or more often a list) is too long for one chunk, its first piece carried the new headings twice, sometimes going over budget.
Problem
Packer::text_unitcomputes the prefix while the new headings are still inpending, which leaves them out, then moves them into the first piece's body. But the loop recomputed it for every piece, so withpendingnow empty the first piece's prefix had them too, though the splitter had left room for one copy.On dev 2293ec9,
chunk_with_budget(text, 40)on# Report,Intro.,## Part Aand a paragraph of 60 short sentences gives the paragraph a 42-token first chunk:Without
Intro., both headings repeat: 45 tokens. At the default budget of 300, with 240 sentences, the two shapes give 303 and 306. Extraction sees those headings twice.Change
table_unitalready does; only continuation pieces recompute it.headingand chunk counts stay the same; only that first chunk's text changes.Verification
the_first_chunk_of_a_split_paragraph_carries_its_headings_oncechunks the example: the paragraph's first chunk must be# Reportplus its source (from## Part A), its second both headings plus its source. With only the test added, dev 2293ec9 fails it:## Part Atwice, 42 tokens against 40. With the change, the four cases above give 38, 38, 299 and 299 tokens.Linux x86_64 container, Rust 1.98.1, PostgreSQL 16 + pgvector 0.8.6, Poppler 25.03, DB required, commit 078b8d5 on dev 2293ec9: fmt and clippy clean;
cargo test --locked --workspace --no-fail-fast1562 passed, 1 failed, 6 ignored; a chat timing test timed out under load, then passed with its binary run alone.Limits