llm/bib: normalize FR rule text at capture, not at every index run #617

Closed
opened 2026-08-13 23:51:22 +00:00 by kert · 1 comment
Owner

Follow-up to #595/#589. The FR full-text endpoint serves HTML-wrapped text (<html><pre>…, inline anchors, entities, stray NULs), and today the cleanup lives at index time: src/llm/source.py strips wrapper/tags/entities and src/llm/chunk.py strips control chars — re-executed for every doc on every (re)index. Cleaner design: normalize once at capture — dev/scripts/fetch_fr_attachments.py writes cleaned plain text to the stored .txt (raw bytes kept alongside as .html), one-time migration cleans the existing data/fr_downloads/*.txt, and the index-time strippers stay as cheap idempotent guards rather than load-bearing transforms. Shared cleaner lives in rex (llm already depends on rex extractors).

Follow-up to #595/#589. The FR full-text endpoint serves HTML-wrapped text (`<html><pre>…`, inline anchors, entities, stray NULs), and today the cleanup lives at index time: [`src/llm/source.py`](https://git.fhirworx.io/homelab/stack/[`src/branch/main/src/llm/source.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/src/branch/main/src/llm/source.py)) strips wrapper/tags/entities and [`src/llm/chunk.py`](https://git.fhirworx.io/homelab/stack/[`src/branch/main/src/llm/chunk.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/src/branch/main/src/llm/chunk.py)) strips control chars — re-executed for every doc on every (re)index. Cleaner design: normalize once at capture — [`dev/scripts/fetch_fr_attachments.py`](https://git.fhirworx.io/homelab/stack/[`src/branch/main/dev/scripts/fetch_fr_attachments.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/src/branch/main/dev/scripts/fetch_fr_attachments.py)) writes cleaned plain text to the stored `.txt` (raw bytes kept alongside as `.html`), one-time migration cleans the existing `data/fr_downloads/*.txt`, and the index-time strippers stay as cheap idempotent guards rather than load-bearing transforms. Shared cleaner lives in `rex` (llm already depends on rex extractors).
kert added the bibllm labels 2026-08-13 23:51:22 +00:00
Author
Owner

Done in d726dca. clean_fr_text in src/rex/frtext.py (wrapper+inline-tag strip, entity unescape, NUL/C0 removal, [[Page N]] preserved, idempotent — 16 TDD tests); dev/scripts/fetch_fr_attachments.py cleans at download (raw kept as .html); migration cleaned the only 2 HTML-wrapped files (2025-13271, 2025-19787 — the older 52 were already plain text); src/llm/source.py now delegates to the shared cleaner as an idempotent guard. Rules collection re-embedded once for the hash bump (5,781 chunks), steady-state indexed=0 skipped=2 confirmed — no recurring re-scrub.

Done in d726dca. `clean_fr_text` in [`src/rex/frtext.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/src/rex/frtext.py) (wrapper+inline-tag strip, entity unescape, NUL/C0 removal, `[[Page N]]` preserved, idempotent — 16 TDD tests); [`dev/scripts/fetch_fr_attachments.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/dev/scripts/fetch_fr_attachments.py) cleans at download (raw kept as `.html`); migration cleaned the only 2 HTML-wrapped files (2025-13271, 2025-19787 — the older 52 were already plain text); [`src/llm/source.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/src/llm/source.py) now delegates to the shared cleaner as an idempotent guard. Rules collection re-embedded once for the hash bump (5,781 chunks), steady-state `indexed=0 skipped=2` confirmed — no recurring re-scrub.
kert closed this issue 2026-08-14 00:09:26 +00:00
Sign in to join this conversation.