feat(halacha): application gate + lexical dedup tail + quality harnesses (#81,#82) #92

Merged
chaim merged 1 commits from worktree-task81-82-halacha-engine into main 2026-06-06 19:56:22 +00:00
Owner

מה ולמה

איכות חילוץ-הלכות (#81) ו-dedup-on-insert (#82) — שינויי-מנוע (pure + tested) + כלי מדידה/תפעול.

halacha_quality.py

  • #81.4 application gate: is_fact_dependent() (deixis "מיושם על התיק הזה" בדיוק-גבוה לפי הרובריקה §3/§27) + FLAG_APPLICATION. compute_quality_flags מקבל rule_type ומסמן application או fact-dependent → חוסם auto-approve (המחשה אינה הלכה בת-הכללה).
  • #82.3 lexical tail: jaccard_shingles/normalized_levenshtein/lexical_near_duplicate + FLAG_NEAR_DUPLICATE, לרצועת cosine 0.83–0.93.

halacha_extractor.py — מעביר rule_type לחישוב-הדגלים; ממיר binding שהוא fact-application ל-application (מקביל ל-non_decision→obiter).

db.py (store_halachot_for_chunk) — ה-dedup שולף את השכן הקרוב באותו פסק פעם אחת: cosine ≥ DEDUP → skip (ללא שינוי); cosine ברצועה [BAND, DEDUP) עם חפיפה לקסיקלית גבוהה → FLAG_NEAR_DUPLICATE (לסקירה, לא skip — לא מפילים עיקרון אולי-מובחן ללא סקירה).

config.pyHALACHA_DEDUP_BAND_COSINE (0.83).

Scripts: halacha_goldset.py (#81.7 — export→תיוג→score, בסיס ל-#81.8); halacha_batch_reconcile.py (#82.7 — dedup חוצה-פסקים שמרני, dry-run); calibrate_halacha_dedup.py (#82.1 — כיול ספי-לקסיקל מול gold-set הניקוי).

נדחה (מתועד)

  • #82.4 (merge-provenance) ו-#82.5 (DB ON CONFLICT/UNIQUE על normalized_quote) לא נכללו — ההתנהגות הנוכחית (skip+flag) בטוחה, בעוד UNIQUE על normalized_quote ייכשל על כפילויות קיימות ומיזוג עיוור מסכן אובדן provenance; דורשים מיגרציה chair-reviewed נפרדת.
  • #82.6 (over-merge guard) חסר-משמעות עד שמיזוג נוחת. #81.6 (rhetorical-role classifier מלא) נדחה (section pre-filter + application flag מכסים את המקרה המעשי); #81.8 חסום על gold-set מתויג-אדם (ההארנס סופק כעת).

Invariants — הצהרה

  • נוגע / מקיים: G1 (נרמול-במקור — סימון ב-insert, לא בקריאה); כלל-הנדסה §6 (פריט חשוד מסומן לסקירה, לא נמחק); G2 (אין מסלול מקביל — אותה store_halachot_for_chunk/compute_quality_flags).

אימות

  • pytest tests/test_halacha_quality.py52 passed (14 חדשים).
  • calibrate: (0.55,0.70) → precision 1.0 (אפס false-merge), recall 0.30 — פרופיל נכון לאיתות שחוסם auto-approve.
  • goldset export: CSV של 15 שורות. batch reconcile: 819 הלכות → 5 זוגות מועמדים חוצי-פסקים.

🤖 Generated with Claude Code

## מה ולמה איכות חילוץ-הלכות (#81) ו-dedup-on-insert (#82) — שינויי-מנוע (pure + tested) + כלי מדידה/תפעול. **halacha_quality.py** - **#81.4 application gate:** `is_fact_dependent()` (deixis "מיושם על התיק הזה" בדיוק-גבוה לפי הרובריקה §3/§27) + `FLAG_APPLICATION`. `compute_quality_flags` מקבל `rule_type` ומסמן `application` או fact-dependent → **חוסם auto-approve** (המחשה אינה הלכה בת-הכללה). - **#82.3 lexical tail:** `jaccard_shingles`/`normalized_levenshtein`/`lexical_near_duplicate` + `FLAG_NEAR_DUPLICATE`, לרצועת cosine 0.83–0.93. **halacha_extractor.py** — מעביר `rule_type` לחישוב-הדגלים; ממיר binding שהוא fact-application ל-`application` (מקביל ל-non_decision→obiter). **db.py (`store_halachot_for_chunk`)** — ה-dedup שולף את השכן הקרוב באותו פסק פעם אחת: cosine ≥ DEDUP → skip (ללא שינוי); cosine ברצועה [BAND, DEDUP) עם חפיפה לקסיקלית גבוהה → `FLAG_NEAR_DUPLICATE` (לסקירה, **לא** skip — לא מפילים עיקרון אולי-מובחן ללא סקירה). **config.py** — `HALACHA_DEDUP_BAND_COSINE` (0.83). **Scripts:** `halacha_goldset.py` (#81.7 — export→תיוג→score, בסיס ל-#81.8); `halacha_batch_reconcile.py` (#82.7 — dedup חוצה-פסקים שמרני, dry-run); `calibrate_halacha_dedup.py` (#82.1 — כיול ספי-לקסיקל מול gold-set הניקוי). ## נדחה (מתועד) - **#82.4** (merge-provenance) ו-**#82.5** (DB ON CONFLICT/UNIQUE על normalized_quote) **לא נכללו** — ההתנהגות הנוכחית (skip+flag) בטוחה, בעוד UNIQUE על normalized_quote ייכשל על כפילויות קיימות ומיזוג עיוור מסכן אובדן provenance; דורשים מיגרציה chair-reviewed נפרדת. - **#82.6** (over-merge guard) חסר-משמעות עד שמיזוג נוחת. **#81.6** (rhetorical-role classifier מלא) נדחה (section pre-filter + application flag מכסים את המקרה המעשי); **#81.8** חסום על gold-set מתויג-אדם (ההארנס סופק כעת). ## Invariants — הצהרה - **נוגע / מקיים:** G1 (נרמול-במקור — סימון ב-insert, לא בקריאה); כלל-הנדסה §6 (פריט חשוד מסומן לסקירה, לא נמחק); G2 (אין מסלול מקביל — אותה `store_halachot_for_chunk`/`compute_quality_flags`). ## אימות - `pytest tests/test_halacha_quality.py` — **52 passed** (14 חדשים). - calibrate: (0.55,0.70) → **precision 1.0** (אפס false-merge), recall 0.30 — פרופיל נכון לאיתות שחוסם auto-approve. - goldset export: CSV של 15 שורות. batch reconcile: 819 הלכות → **5 זוגות מועמדים חוצי-פסקים**. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-06-06 19:56:18 +00:00
Halacha-extraction quality (#81) and dedup-on-insert (#82) — engine changes
(pure + tested) plus measurement/ops tooling.

halacha_quality.py
- #81.4 application gate: is_fact_dependent() (high-precision "applied to THIS
  case" deixis per the strict rubric §3/§27) + FLAG_APPLICATION. compute_quality_flags
  now takes rule_type and flags rule_type=='application' OR fact-dependent —
  blocking auto-approve (an illustration is not a generalizable holding).
- #82.3 lexical tail signal: jaccard_shingles / normalized_levenshtein /
  lexical_near_duplicate + FLAG_NEAR_DUPLICATE, for the 0.83–0.93 cosine band.

halacha_extractor.py — pass rule_type to the flag computation; re-type a
binding-labeled fact-application to 'application' (mirrors non_decision→obiter).

db.py (store_halachot_for_chunk) — dedup now fetches the nearest same-precedent
neighbor once: cosine ≥ DEDUP → skip (unchanged); cosine in [BAND, DEDUP) with
high lexical overlap → FLAG_NEAR_DUPLICATE (review, not skip — never drop a
possibly-distinct principle unreviewed).

config.py — HALACHA_DEDUP_BAND_COSINE (0.83).

Scripts:
- scripts/halacha_goldset.py (#81.7) — export stratified sample for human
  tagging; score validators (P/R/F1) against the tags. Backbone for #81.8.
- scripts/halacha_batch_reconcile.py (#82.7) — conservative cross-precedent
  dedup (cosine ≥0.95), dry-run report only.
- scripts/calibrate_halacha_dedup.py (#82.1) — calibrate the lexical thresholds
  against the 2026-06-03 cleanup gold-set.

Deferred (documented): #82.4 merge-provenance and #82.5 DB ON CONFLICT/UNIQUE
on normalized quote are NOT included — the current skip+flag behavior is safe,
whereas a UNIQUE on normalized_quote would fail on existing dups and a blind
merge risks losing provenance; they need their own chair-reviewed migration.
#82.6 over-merge guard is moot until merge lands. #81.6 full rhetorical-role
classifier deferred (section pre-filter + application flag cover the practical
case); #81.8 blocked on the human-tagged gold-set (harness now provided).

Verified:
- pytest tests/test_halacha_quality.py — 52 passed (14 new).
- calibrate: configured (0.55,0.70) → precision 1.0 (zero false-merge), recall
  0.30 — correct profile for an auto-approve-blocking signal.
- goldset export: 15-row sample CSV. batch reconcile: 819 halachot → 5
  cross-precedent candidate pairs.

Invariants: G1 (normalize at source — flag at insert, not at read); §6 (no
silent swallow — suspect items flagged to review, never dropped); G2 (no
parallel path — same store_halachot_for_chunk / compute_quality_flags).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit 32ef259843 into main 2026-06-06 19:56:22 +00:00
chaim deleted branch worktree-task81-82-halacha-engine 2026-06-06 19:56:22 +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#92