Skip to content

fix(documents): no minimum-size merge across a PDF section boundary - #16

Merged
YBazanPro merged 1 commit into
mainfrom
claude/sweet-kalam-5f70b6
Oct 17, 2026
Merged

YBazanPro merged 1 commit into
mainfrom
claude/sweet-kalam-5f70b6

Conversation

@YBazanPro

Copy link
Copy Markdown
Owner

What changed

Chunker.TryMerge now refuses a minimum-size merge that crosses into a section without a heading line. Only PDF sections have none in practice: plain text is a single section, and Markdown's heading-less section (text before the first heading) is always first.

Why

A passage under MinTokens that cannot merge backward merges into the next sibling section (SameParent). Markdown puts the sibling's heading line (# Two) in front of the merged part, so the boundary stays visible. PdfSourceExtractor.ToDocument gives sections HeadingLine = null, so section Two's text ended up in a passage labelled One, with no boundary marker. It was then embedded under "One" and cited as "One".

Two fixes were considered. The chosen one is to not merge. The rejected alternative was a synthetic heading line (the last path element) for PDF sections: the passage would still carry the wrong SectionPath, and heading text would enter PDF passage text, against spec 010 AC-11.

Trade-off: such a PDF passage can now stay under MinTokens.

Golden diff

Only Golden/pdf-blocks-small.txt changes. All other golden files are byte-identical.

Reviewer notes

  • Test first: ChunkerPageTests.Chunk_smallPassageBeforeASiblingSection_isNotMergedIntoIt failed before the fix (1 passage instead of 2).
  • Docs: spec 010 (chunking intro, AC-17, dated deviation note), spec 007 (merge details) and the SourceSection.HeadingLine doc comment record the exception.
  • Golden regeneration gotcha: RAGASSISTANT_UPDATE_GOLDEN=1 rewrites every golden file with LF. With core.autocrlf=true, the unchanged files then show as modified with no content diff. Restore them with git checkout -- before committing.
  • Verification: dotnet build, dotnet format --verify-no-changes and dotnet test --solution RagAssistant.slnx pass (1177/1177). The branch was rebased onto main after refactor(documents): one extractor per format, Chunker takes a SourceDocument #15 merged; the tree is identical to the tested commit.

🤖 Generated with Claude Code

A small PDF passage merged into the next sibling section, but PDF sections
have no heading line to prefix, so the sibling's text ended up labelled,
embedded and cited under the previous section's path. The Chunker now
refuses a merge across a section without a heading line (PDF only in
practice); such a passage stays under MinTokens instead.

Golden: only pdf-blocks-small.txt changes. Specs 007 and 010 record the
exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YBazanPro
YBazanPro merged commit b3fddd8 into main Oct 17, 2026
1 check passed
@YBazanPro
YBazanPro deleted the claude/sweet-kalam-5f70b6 branch October 17, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant