fix(chunking): keep dose units wrapped onto their own line by PDF extraction - #334
Merged
Conversation
…raction
PyMuPDF get_text(sort=True) splits a dose in a narrow table cell across
lines ('12.5\nmg'); the <=2-char debris rule then deleted the unit line,
indexing a unitless dose. removePageNoise now rejoins a unit-only line
(mg, mcg, mL, IU, %, ...) to a preceding digit-ending line before
filtering. A lone unit with no preceding number is still dropped, and
page footers are never merged into.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>This pull request has been ignored for the connected project Preview Branches by Supabase. |
BigSimmo
marked this pull request as ready for review
July 6, 2026 18:12
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BigSimmo
enabled auto-merge
July 6, 2026 18:12
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Aug 18, 2026
Merged
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 freeto 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
PyMuPDF extraction (
page.get_text("text", sort=True), the exact call inworker/python/extract_pdf_assets.py) splits a dose in a narrow table cell across lines:"12.5\nmg".looksLikeMetadataNoisetreats any line of <= 2 characters as extraction debris, soremovePageNoisesilently deleted the unit line, indexing a unitless dose (12.5) — a clinical-output correctness risk.removePageNoisenow rejoins a unit-only line (mg,mcg,µg,g,kg,mL,L,IU,U,mmol,%) to the preceding line when that line ends in a digit, before the debris filter runs. Conservative by design:mcg,mmol) also get rejoined, so"100\nmcg"indexes as100 mcginstead of two lines.Evidence
get_text("text", sort=True)yields'12.5\nmg'/'600\nmcg'. Real guideline dose tables use exactly this narrow-column layout.Tests
tests/chunking.test.ts(rejoin decimal + integer doses, lone-unit still dropped, footer not merged). 31/31 pass.npm run typecheckandprettier --checkclean.tests/property-chunking.test.ts(branchclaude/audit-sweep-property-tests) updated to note the exception; its generators never emit unit-only lines so the property suite is unaffected.Governance note
Touches ingestion chunking only; behavior change is additive (keeps/rejoins clinical content that was previously deleted). Existing indexed chunks are unaffected until a re-index; new ingestions pick this up immediately.
🤖 Generated with Claude Code