Skip to content

feat(chunking): measure wrapped-dose-unit prevalence in the live corpus - #382

Merged
BigSimmo merged 2 commits into
mainfrom
claude/dose-prevalence-measure
Jul 8, 2026
Merged

feat(chunking): measure wrapped-dose-unit prevalence in the live corpus#382
BigSimmo merged 2 commits into
mainfrom
claude/dose-prevalence-measure

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

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.text retains the raw extracted page text — the worker writes cleanString(page.text) (null-byte strip only); removePageNoise runs later inside buildChunks. 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

  • Export countWrappedDoseUnitLines from src/lib/chunking.ts, sharing a new isWrappedDoseUnitContinuation predicate with the fix's rejoinWrappedDoseUnits so measurement and behaviour can't drift.
  • scripts/measure-wrapped-dose-prevalence.ts (npm run measure:wrapped-dose-units): paginates document_pages, counts wrapped units, joins documents for the worst offenders. Read-only (SELECT only). Flags: --limit N, --top N, --json.
  • Unit test in tests/chunking.test.ts covering the counter (mirrors the rejoin cases).

Live result (full corpus)

pages scanned: 27416
pages affected: 7 (0.03%)
documents affected: 6
wrapped units total: 7

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.ts 32/32 pass; typecheck and prettier --check clean.
  • Script executed against the live Clinical KB Database (read-only); output above.

🤖 Generated with Claude Code

BigSimmoand others added 2 commits July 8, 2026 14:59
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>
@supabase

supabaseBot commented Jul 8, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@BigSimmo
BigSimmo marked this pull request as ready for review July 8, 2026 07:06
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@BigSimmo
BigSimmo merged commit 4567003 into mainJul 8, 2026
5 checks passed
@BigSimmo
BigSimmo deleted the claude/dose-prevalence-measure branch July 8, 2026 07:14
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@BigSimmo