.Net: fix: count text chunker orphan glue by tokens#14002
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue in TextChunker.ProcessParagraphs where the “orphan paragraph” gluing heuristic could exceed the configured token budget because it used word-count instead of the configured token counter. The change ensures gluing decisions honor the same token-counting strategy used throughout the chunking pipeline, and adds a regression test to prevent reintroduction.
Changes:
- Update orphan-paragraph gluing to use
GetTokenCount(..., tokenCounter)on the combined paragraph rather than adding word counts. - Preserve the existing whitespace normalization behavior for glued paragraphs by continuing to split/join on spaces.
- Add a regression unit test covering a case where word-count-based gluing would exceed the token limit when using a custom token counter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/src/SemanticKernel.Core/Text/TextChunker.cs | Fixes orphan-paragraph gluing to respect the configured token counter when checking max token limits. |
| dotnet/src/SemanticKernel.UnitTests/Text/TextChunkerTests.cs | Adds a regression test ensuring the last paragraph is not glued if it would exceed the requested token limit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d7c77b4 to
37f7f45
Compare
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.
Summary
Fixes #13713.
To verify
dotnet test .\src\SemanticKernel.UnitTests\SemanticKernel.UnitTests.csproj -f net10.0 --filter "FullyQualifiedName~SplitPlainTextParagraphsDoesNotGlueLastParagraphPastTokenLimit"dotnet test .\src\SemanticKernel.UnitTests\SemanticKernel.UnitTests.csproj -f net10.0 --filter "FullyQualifiedName~TextChunkerTests" --no-restoredotnet build .\src\SemanticKernel.Core\SemanticKernel.Core.csproj -f net10.0 --no-restoredotnet format .\src\SemanticKernel.Core\SemanticKernel.Core.csproj --verify-no-changes --no-restoredotnet format .\src\SemanticKernel.UnitTests\SemanticKernel.UnitTests.csproj --verify-no-changes --no-restore