Conversation
…ownChunker MarkdownChunker deducts the inherited heading prefix from the chunk_size it hands to the recursive fallback chunker, but passed the caller's chunk_overlap unchanged. A valid external configuration such as chunk_size=256, chunk_overlap=100 turned into overlap >= chunk_size for a section under a long heading (body budget 64) and the fallback raised "chunk_overlap must be less than chunk_size", failing the upload at the chunking stage. Scale the overlap proportionally to the reduced budget and keep it strictly below the effective chunk size. Fixes AstrBotDevs#9998
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_markdown_chunker.py" line_range="17" />
<code_context>
+ chunks = await chunker.chunk(LONG_HEADING_DOC)
+
+ assert chunks
+ assert "".join(chunks).count("B") >= 600
+ # The overlap now scales with the reduced budget instead of exceeding it.
+ assert all("B" * 65 not in chunk for chunk in chunks)
</code_context>
<issue_to_address>
**issue (testing):** The body-preservation assertions only check the total number of repeated `B` characters across all chunks. Because chunk overlap duplicates characters, the assertions still pass when a portion of the body is lost, so the regression tests can silently pass while chunking drops content.
**Triggers:** When the fallback chunker omits a body segment but produces enough overlapping duplicate `B` characters to keep the aggregate count at least 600.
**Suggested fix:** Use a body containing unique markers or assert exact coverage of the expected body sequence rather than counting repeated characters across overlapping chunks.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/test_markdown_chunker.py:17
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.
Motivation / 动机
Fixes #9998.
MarkdownChunker._sections_to_chunksdeducts the inherited heading prefix from thechunk_sizeit hands to the recursive fallback chunker (effective_chunk_size = max(chunk_size // 4, chunk_size - prefix_len)), but passed the caller'schunk_overlapthrough unchanged. A valid external configuration such aschunk_size=256, chunk_overlap=100therefore becameoverlap=100 >= effective_chunk_size=64for a section under a long heading, andRecursiveCharacterChunkerraisedchunk_overlap must be less than chunk_size, failing a Markdown upload at the chunking stage. The same document chunks fine withinclude_heading_context=False.Modifications / 改动点
MarkdownChunker._scale_overlap(chunk_overlap, chunk_size, effective_chunk_size): when the body budget was reduced, the overlap is scaled proportionally (100/256→25/64) and always kept strictly below the effective chunk size; when the budget is not reduced the overlap is untouched._sections_to_chunkspasses the scaled overlap to the fallback chunker.tests/test_markdown_chunker.py: the reproducer from the issue (200-char parent heading,## Child, 600 chars of body,chunk_size=256, chunk_overlap=100) now chunks without error and keeps all body text, also when the sizes are passed aschunk()overrides;include_heading_context=Falseis unchanged; parametrized cases for_scale_overlap. The reproducer tests fail onmasterand pass with the fix.Verification / 验证
Checklist / 检查清单
Summary by Sourcery
Keep Markdown chunk overlap valid when inherited heading context reduces the available body budget.
Bug Fixes:
Tests: