fix(chunkers): make SimpleTextSplitter fallback URL-safe (#2200) - #2228
fix(chunkers): make SimpleTextSplitter fallback URL-safe (#2200)#2228hijzy wants to merge 3 commits into
Conversation
* fix(chunkers): make SimpleTextSplitter fallback URL-safe (#2115) `SimpleTextSplitter._simple_split_text()` called `self.protect_urls` and `self.restore_urls`, methods defined only on `BaseChunker`. Since `SimpleTextSplitter` does not inherit `BaseChunker`, every call raised `AttributeError: 'SimpleTextSplitter' object has no attribute 'protect_urls'`. The multi-modal file-parsing pipeline swallowed the error and fell back to returning the whole text as a single chunk, producing ~5.8k noisy log rows on ACK where langchain_text_splitters is missing and the fallback branch is actually exercised. Extract the URL protect/restore helpers into a small `URLProtectionMixin` in `chunkers/base.py`; have both `BaseChunker` and `SimpleTextSplitter` inherit it. This preserves BaseChunker's public API (mixin methods are inherited transparently), keeps SimpleTextSplitter's constructor and return type unchanged, and shares a single URL regex between the two paths. Add regression tests in tests/chunkers/test_simple_chunker.py covering short/long input, empty input, no-URL text, and parametrised (chunk_size, overlap) combinations to ensure the fallback never raises again. * refactor(chunkers): expose URL placeholder prefix as class constant Address OCR review on #2116: the placeholder-leak assertion in tests/chunkers/test_simple_chunker.py hardcoded the string `'__URL_'`, which duplicates an implementation detail of `URLProtectionMixin.protect_urls` (formatted as `f'__URL_{len(url_map)}__'`). If the prefix ever changed in `base.py`, the assertion would silently keep passing while no longer catching real placeholder leaks. Expose the prefix as a class-level constant `URLProtectionMixin._URL_PLACEHOLDER_PREFIX = "__URL_"`, use it inside `protect_urls`, and import it in the test so the two paths stay in sync automatically. No behavior change: placeholders keep the same textual form (`__URL_<n>__`), so both the current base chunker and the fallback `SimpleTextSplitter` produce identical output to before. * fix(chunkers): keep URL placeholders atomic at split boundaries --------- Co-authored-by: MemOS AutoDev <autodev@memtensor.local>
🤖 Open Code ReviewTarget: PR #2228 🔍 OpenCodeReview found 4 issue(s) in this PR. 1.
|
✅ Automated Test Results: PASSEDAll tests passed (9/9 executed). memos_python_core/changed-repo-python: 9/9. Duration: 5s [advisory, non-gating] AI-generated tests on branch test/auto-gen-477e71d1dfcfc2e0-20260806193914: 103/104 passed, 1 failed — these do NOT affect the PR verdict; review the branch manually. Branch: |
✅ Automated Test Results: PASSEDAll tests passed (21/21 executed). memos_python_core/changed-repo-python: 21/21. Duration: 5s [advisory, non-gating] AI-generated tests on branch test/auto-gen-64dcd4c62d980dd4-20260806204020: 65/65 passed — these do NOT affect the PR verdict; review the branch manually. Branch: |
Summary
Related issues: #2115, #2200
Compatibility
How Has This Been Tested?
Type of change
Checklist
Reviewer Checklist