feat(stdlib): add ChunkingStrategy ABC and built-in chunkers#923
Open
planetf1 wants to merge 5 commits intogenerative-computing:mainfrom
Open
feat(stdlib): add ChunkingStrategy ABC and built-in chunkers#923planetf1 wants to merge 5 commits intogenerative-computing:mainfrom
planetf1 wants to merge 5 commits intogenerative-computing:mainfrom
Conversation
Adds mellea/stdlib/chunking.py with ChunkingStrategy ABC and three built-in implementations: SentenceChunker, WordChunker, ParagraphChunker. split(accumulated_text) returns complete chunks, holding back trailing fragments for the next call. Closes generative-computing#899 Part of generative-computing#891 Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Pyright flagged import as unaccessed; no pytest.* calls in the file. Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
…hunkingStrategy - Fix SentenceChunker whitespace leak: lstrip() after match.end() so double-space / tab separators don't bleed into the next chunk as leading whitespace - Add end-of-stream contract to ABC docstring (callers responsible for trailing fragment after stream terminates) - Fix incorrect comment "end-of-string" → "whitespace" - Compile _WHITESPACE / _PARA_BOUNDARY / _PARA_BOUNDARY_END at module level (consistent with _SENTENCE_BOUNDARY; avoids per-call recompile) - Expand SentenceChunker char class to include right curly double/single quotes (U+201D / U+2019) for common LLM output patterns - Document CRLF limitation on ParagraphChunker - Re-export ChunkingStrategy + chunkers from mellea.stdlib.__init__ - Add __all__ to chunking.py - Add tests: closing paren, double-space separator, tab separator, abbreviation edge case (known-bad split), WordChunker leading-whitespace Assisted-by: Claude Code
…acy and curly-quote test - Fix misleading comment on _SENTENCE_BOUNDARY: was "processed by re engine as \u escapes" but the file contained literal Unicode chars. Now uses chr(0x201d) + chr(0x2019) for Python 3.12 compatibility (U+2019 is treated as a string delimiter in single-quoted raw strings on 3.12). - Add test_sentence_chunker_curly_quotes to verify U+201D/U+2019 matching. Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
9 tasks
8 tasks
…mputing#923) - Simplify _SENTENCE_BOUNDARY regex to use \u escapes instead of chr() concatenation (cleaner, same semantics, Python 3.12-safe) - Document that SentenceChunker discards inter-sentence whitespace via lstrip() - Add test_chunking_strategy_is_abstract to document the extension-point contract Assisted-by: Claude Code
jakelorocco
approved these changes
Apr 24, 2026
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.
Adds
mellea/stdlib/chunking.pywith chunking infrastructure for streaming validation.Changes
ChunkingStrategyABC withsplit(accumulated_text: str) -> list[str]SentenceChunker— splits on.,!,?boundariesWordChunker— splits on whitespaceParagraphChunker— splits on\n\ntest/stdlib/test_chunking.py(27 tests, all passing)Test plan
uv run pytest test/stdlib/test_chunking.py -vpasses (27/27)uv run ruff checkcleanuv run mypy mellea/stdlib/chunking.pycleanCloses #899
Part of #891