feat(chunking): measure wrapped-dose-unit prevalence in the live corpus - #382
Merged
Conversation
Export countWrappedDoseUnitLines from chunking.ts (sharing the fix's isWrappedDoseUnitContinuation predicate so the two cannot drift) and add scripts/measure-wrapped-dose-prevalence.ts. document_pages.text retains the raw extracted page text (worker writes cleanString(page.text); removePageNoise runs later in buildChunks), so counting wrapped units on that column is an accurate, read-only measure of how many indexed doses lost their unit pre-fix — no PDF re-extraction or re-index required. This quantifies whether a re-index is worth the spend (PR #334 follow-up). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@/lib/env snapshots process.env at module load, so importing chunking statically (before loadEnvConfig) left the admin client with empty Supabase config. Import countWrappedDoseUnitLines dynamically inside main(), matching loadAdminClient. Verified against the live corpus. 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 8, 2026 07:06
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Uh oh!
There was an error while loading. Please reload this page.
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
Follow-up to #334 (the wrapped-dose-unit chunking fix). That PR asked the open question: how many already-indexed doses lost their unit, and is a re-index worth it? This adds the tooling to answer it and reports the live number.
Key realisation:
document_pages.textretains the raw extracted page text — the worker writescleanString(page.text)(null-byte strip only);removePageNoiseruns later insidebuildChunks. So the wrapped"12.5\nmg"shape is still present in that column, and counting it there is an accurate, read-only measure with no PDF re-extraction and no re-index.Changes
countWrappedDoseUnitLinesfromsrc/lib/chunking.ts, sharing a newisWrappedDoseUnitContinuationpredicate with the fix'srejoinWrappedDoseUnitsso measurement and behaviour can't drift.scripts/measure-wrapped-dose-prevalence.ts(npm run measure:wrapped-dose-units): paginatesdocument_pages, counts wrapped units, joinsdocumentsfor the worst offenders. Read-only (SELECT only). Flags:--limit N,--top N,--json.tests/chunking.test.tscovering the counter (mirrors the rejoin cases).Live result (full corpus)
Recommendation: do not re-index for this bug. 7 stripped units corpus-wide is negligible; re-embedding cost dwarfs the benefit. The #334 fix already prevents all future occurrences. If the 6 named documents matter, re-index just those (or fold them into any re-index done for other reasons).
Tests
tests/chunking.test.ts32/32 pass;typecheckandprettier --checkclean.Clinical KB Database(read-only); output above.🤖 Generated with Claude Code