Structural dedup: shared chunks-IO, splitter & parser helpers (~190 fewer lines)#7
Open
shaunpatterson wants to merge 6 commits into
Open
Conversation
Adds pure-logic and mockable tests across splitters, postprocessing (incl. the *_from_df drivers), metrics (fake embedding model, mocked sentence-transformers, real sklearn), jina_embedder (mocked httpx), pipeline (fake parser), and the split/metrics/mentions directory drivers (fake splitters/models, parquet fixtures). Adds a coverage config scoping the target to the importable library and excluding paper/ (research replication scripts) and parsing.py (thin adapters over heavy optional SDKs: Azure DI / Docling / PyMuPDF). On that scope coverage is 92% (was ~19%); the remaining gap is the spaCy/maverick coref internals in metrics.py, which need real models to exercise. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
split_documents, compute_metrics, postprocessing (*_from_df) and extract_mentions all read/write .parquet via pandas, but pandas>=2.2 does not pull a parquet engine automatically, so these functions (and their tests) fail at runtime without one. Add pyarrow as an explicit dependency. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- regex_splitter() and RecursiveSplitter._split_with_separator() were the same algorithm differing only in error handling; both now delegate to a single _split_keep_separator(... on_error='raise'|'return_text'). - The ~20-line overlap-backtracking block duplicated verbatim in _merge_splits and _merge_small_splits is extracted to _build_overlap(). Behavior-preserving; verified by the splitter test suite (63 tests). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
split_oversized_chunks_from_df and merge_small_chunks_from_df were ~95%
identical (~110 lines each), and split_documents_from_dir carried a third
copy of the records-building + parquet-merge tail.
Extract:
- build_chunk_records(): {doc:{method:[chunks]}} -> per-chunk records
- upsert_parquet(): write with merge-existing-by-method
- _regularize_chunks_from_df(): the load/groupby/regularize/write orchestrator
The two public *_from_df functions become thin wrappers (regularize fn +
record type), and split_documents_from_dir reuses the same two helpers.
Behavior-preserving; verified by the postprocessing + split_documents
test suites (59 tests, incl. replace_all_results and merge-existing paths).
Net ~120 fewer lines.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The identical title end-offset loop was copy-pasted into all four parsers (Azure DI / Excel / Docling / PyMuPDF). Extract a single pure helper and call it from each site (dropping unused local vars). Adds a direct unit test for the helper (parsing.py is otherwise SDK-bound). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
shaunpatterson
force-pushed
the
refactor/structural-dedup
branch
from
July 8, 2026 01:06
2353c6b to
7557715
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.
Behavior-preserving structural refactors from the code-quality review — each verified against the test suite added in #6.
What changed (each its own commit)
Splitters dedup —
regex_splitter()andRecursiveSplitter._split_with_separator()were the same algorithm differing only in error handling; both now delegate to one_split_keep_separator(..., on_error=...). The ~20-line overlap-backtracking block duplicated verbatim in_merge_splits/_merge_small_splitsis extracted to_build_overlap().Shared chunks-parquet IO —
split_oversized_chunks_from_dfandmerge_small_chunks_from_dfwere ~95% identical (~110 lines each), andsplit_documents_from_dircarried a third copy of the records + parquet-merge tail. Extracted:build_chunk_records()—{doc: {method: [chunks]}}→ per-chunk recordsupsert_parquet()— write with merge-existing-by-method_regularize_chunks_from_df()— the load/groupby/regularize/write orchestratorThe two public
*_from_dffunctions are now thin wrappers;split_documents_from_dirreuses the same two helpers.Parser title-end dedup — the identical title end-offset loop copy-pasted into all four parsers (Azure DI / Excel / Docling / PyMuPDF) is now one pure
_assign_title_end_offsets()helper, with a direct unit test.Net effect
src/diff: +236 / −423 (~190 net lines deleted), no behavior change.Verification
Full suite: 214 passed, 1 skipped, 91% coverage on the scoped target (unchanged by the refactor). The driver tests exercise the
replace_all_resultsand merge-existing-by-method paths through the new shared helpers.Deliberately not included
The greedy table-row-splitter appears in three parser methods (
AzureDIParser._table_to_markdown,ExcelParser._split_by_rows,DoclingParser._split_table_markdown) but with genuinely different shapes (DataFrame rebuild vs markdown lines vs captions), and those live in SDK-bound classes that can't be executed/tested here. Unifying them has no safety net, so it's left out.🤖 Generated with Claude Code