feat(nevo): backfill leaked preamble + ratio gold-set benchmark (#86) #91

Merged
chaim merged 1 commits from worktree-task86-nevo-backfill-benchmark into main 2026-06-06 19:46:26 +00:00
Owner

מה ולמה

TaskMaster legal-ai #86 — תתי-משימות #2 (backfill) ו-#3 (benchmark), ובדרך נמצא ותוקן באג over-strip ב-#86.1 שכבר מוזג.

extractor.py

  • extract_nevo_ratio() — לוכד את בלוק ה-מיני-רציו של נבו (תקציר ההלכות העריכתי) לפני שהוא נחתך; gold-set מקצועי חינמי (#86.3).
  • הקשחת _DECISION_START (#86.2) — ה-regex שמוזג ב-#86.1 ביצע over-strip:
    • (א) כותרות פסק-דין עטופות markdown (**פסק דין**); ה-anchor הישן דרש שהמילה תהיה התו הראשון בשורה עם מפריד יחיד → פספס את הכותרת ונפל על ציטוט 32K בעומק (עמ"נ 50567-07-21, אובדן 45% מהגוף). עכשיו סובל markdown מוביל + 0-3 מפרידים + צורת נון-סופית (דין ן מול דינו נ).
    • (ב) השופט/הנשיא בודדים תפסו ציטוטים (השופט מ' חשין, פסקה 23). שורת-השופט-הכותב מסתיימת בנקודתיים — עכשיו נדרשת.

ingest.py — לוכד את הרציו לפני החיתוך ושומר ב-nevo_ratio (best-effort, לא-קריטי); גם מחיל strip על מסלול ה-text-upload (היה file-only).

db.py — עמודת case_law.nevo_ratio (אדיטיבי) + התרה ב-update_case_law.

scripts/backfill_nevo_preamble.py (#86.2) — מיגרציית-נתונים dry-run-כברירת-מחדל: מאתר פסקים שהרציו דלף אליהם היסטורית, לוכד רציו→nevo_ratio, משכתב full_text (+content_hash), עושה reindex, ומסמן (לא מוחק) הלכות שהציטוט שלהן בתוך ה-preamble שהוסר. שומר-בטיחות: keep%<--min-keep (60) מוחרג מ---apply כחשד over-strip. --apply כותב backup+manifest ל-data/audit/ תחילה.

scripts/nevo_ratio_benchmark.py (#86.3) — LLM-as-judge מקומי (claude_session, אפס עלות) מודד recall/precision/granularity של הלכותינו מול רציו-נבו.

Invariants — הצהרה

  • נוגע / מקיים: G1 (נרמול-במקור — חיתוך/לכידה ב-ingest, לא בקריאה); כלל-הנדסה §6 (הלכות מזוהמות מסומנות ומדווחות, לא נמחקות בשקט); מיגרציית-נתונים = dry-run-default + backup+manifest + chair-gated (צ'קליסט הפרוטוקול).

אימות

  • pytest tests/test_nevo_preamble.py12 passed (כולל רגרסיות citation/markdown over-strip).
  • backfill dry-run: 19 פסקים דולפים, 27 הלכות מזוהמות, כולם ≥75% keep (ה-over-strip של 32K נעלם). --apply לא הורץ — ממתין לאישורך על ה-manifest.
  • benchmark על בג"ץ 1764/05: recall=0.875, precision=1.0, granularity=1.75x.

🤖 Generated with Claude Code

## מה ולמה TaskMaster `legal-ai` #86 — תתי-משימות #2 (backfill) ו-#3 (benchmark), ובדרך נמצא ותוקן באג over-strip ב-#86.1 שכבר מוזג. **extractor.py** - `extract_nevo_ratio()` — לוכד את בלוק ה-מיני-רציו של נבו (תקציר ההלכות העריכתי) **לפני** שהוא נחתך; gold-set מקצועי חינמי (#86.3). - **הקשחת `_DECISION_START` (#86.2)** — ה-regex שמוזג ב-#86.1 ביצע over-strip: - (א) כותרות `פסק-דין` עטופות markdown (`**פסק דין**`); ה-anchor הישן דרש שהמילה תהיה התו הראשון בשורה עם מפריד יחיד → פספס את הכותרת ונפל על **ציטוט** 32K בעומק (`עמ"נ 50567-07-21`, אובדן 45% מהגוף). עכשיו סובל markdown מוביל + 0-3 מפרידים + צורת נון-סופית (`דין` ן מול `דינו` נ). - (ב) `השופט`/`הנשיא` בודדים תפסו **ציטוטים** (`השופט מ' חשין, פסקה 23`). שורת-השופט-הכותב מסתיימת בנקודתיים — עכשיו נדרשת. **ingest.py** — לוכד את הרציו לפני החיתוך ושומר ב-`nevo_ratio` (best-effort, לא-קריטי); גם מחיל strip על מסלול ה-text-upload (היה file-only). **db.py** — עמודת `case_law.nevo_ratio` (אדיטיבי) + התרה ב-`update_case_law`. **scripts/backfill_nevo_preamble.py (#86.2)** — מיגרציית-נתונים dry-run-כברירת-מחדל: מאתר פסקים שהרציו דלף אליהם היסטורית, לוכד רציו→`nevo_ratio`, משכתב `full_text` (+`content_hash`), עושה reindex, ו**מסמן (לא מוחק)** הלכות שהציטוט שלהן בתוך ה-preamble שהוסר. **שומר-בטיחות:** keep%<`--min-keep` (60) מוחרג מ-`--apply` כחשד over-strip. `--apply` כותב backup+manifest ל-`data/audit/` תחילה. **scripts/nevo_ratio_benchmark.py (#86.3)** — LLM-as-judge מקומי (`claude_session`, אפס עלות) מודד recall/precision/granularity של הלכותינו מול רציו-נבו. ## Invariants — הצהרה - **נוגע / מקיים:** G1 (נרמול-במקור — חיתוך/לכידה ב-ingest, לא בקריאה); כלל-הנדסה §6 (הלכות מזוהמות **מסומנות ומדווחות**, לא נמחקות בשקט); מיגרציית-נתונים = dry-run-default + backup+manifest + chair-gated (צ'קליסט הפרוטוקול). ## אימות - `pytest tests/test_nevo_preamble.py` — **12 passed** (כולל רגרסיות citation/markdown over-strip). - backfill **dry-run**: 19 פסקים דולפים, 27 הלכות מזוהמות, כולם ≥75% keep (ה-over-strip של 32K נעלם). **`--apply` לא הורץ — ממתין לאישורך על ה-manifest.** - benchmark על `בג"ץ 1764/05`: recall=0.875, precision=1.0, granularity=1.75x. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-06-06 19:46:19 +00:00
#86.2 backfill + #86.3 benchmark, plus a #86.1 over-strip fix found en route.

extractor.py
- extract_nevo_ratio(): capture Nevo's מיני-רציו block (editorial holdings
  summary) before it is stripped — a free professional gold-set (#86.3).
- _DECISION_START hardening (#86.2): the merged #86.1 regex over-stripped.
  (a) פסק-דין headers are markdown-wrapped (**פסק  דין**); the old anchor
      required the keyword as the first line char with one separator, so it
      missed the header and matched a citation 32K deep (עמ"נ 50567-07-21,
      losing 45% of the body). Now tolerates leading markdown + 0-3 seps,
      and the final-nun form (דין ן vs דינו נ).
  (b) bare השופט/הנשיא matched CITATIONS ("השופט מ' חשין, פסקה 23"). The
      authoring-judge line ends with a colon; we now require it.

ingest.py
- capture the ratio before stripping and store it on the row (best-effort,
  non-fatal); also strip the text-upload path (was file-only).

db.py
- add case_law.nevo_ratio column (additive); allow it in update_case_law.

scripts/backfill_nevo_preamble.py (#86.2) — dry-run-by-default data migration:
finds historically-leaked rulings, captures ratio→nevo_ratio, rewrites
full_text (+content_hash), reindexes, and FLAGS (never deletes) halachot whose
quote lives in the removed preamble (review_status=pending_review +
nevo_preamble_leak flag). Safety guard: rows with keep%<--min-keep (60) are
excluded from --apply as suspected over-strip. --apply writes backup+manifest
to data/audit/ first. Chair-gated — NOT applied here.

scripts/nevo_ratio_benchmark.py (#86.3) — LLM-as-judge (local claude_session,
zero cost) measures recall/precision/granularity of our halachot vs the Nevo
ratio. Works pre- and post-backfill (reads nevo_ratio, falls back to full_text).

Verified:
- pytest tests/test_nevo_preamble.py — 12 passed (incl. citation/markdown
  over-strip regressions).
- backfill dry-run: 19 leaked rulings, 27 contaminated halachot, all ≥75%
  keep (the 32K over-strip is gone).
- benchmark on בג"ץ 1764/05: recall=0.875 precision=1.0 granularity=1.75x.

Invariants: G1 (normalize at source — strip/capture at ingest, not at read);
no silent swallow (contaminated halachot flagged + reported, not dropped);
data-migration is dry-run-default with backup+manifest, chair-gated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit 366d89e6bb into main 2026-06-06 19:46:26 +00:00
chaim deleted branch worktree-task86-nevo-backfill-benchmark 2026-06-06 19:46:26 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ezer-mishpati/legal-ai#91