fix(corpus): re-link orphan citations when a cited ruling is uploaded (G1) #309

Merged
chaim merged 1 commits from worktree-citation-relink into main 2026-06-20 11:47:17 +00:00
Owner

מה

precedent_internal_citations פותר cited_case_law_id רק בזמן-חילוץ. כשהחלטה מצטטת פסיקה שעדיין לא בקורפוס — הקצה נשמר עם NULL. הפסיקה מועלית לרוב ימים אחר-כך, אך הקצה היתום לא נפתר-מחדש לעולם → גרף-הציטוטים מתחת-סופר את הקישוריות (אותו דפוס ערך-נגזר-מיושן כמו searchable).

מחמיר: פסיקה חיצונית נשמרת בלי תחילית-ערכאה (3213/97) בעוד הציטוט נושא אותה (ע"א 3213/97) — ולכן חלק גדול מה"חסרים" היה בעצם קיים-אך-לא-מקושר.

שינוי

  • פונקציה חדשה citation_extractor.relink_orphan_citations(case_law_id=None) — פותרת-מחדש קצוות-יתומים דרך הפותר הקנוני _resolve_case_law_id (אפס לוגיקת-התאמה מקבילה, G2); ממוקדת-שורה או סריקה-מלאה כש-None. idempotent.
  • ingest_document קורא לה בכל העלאה (non-fatal) → הגרף מרפא את עצמו.

נתונים קיימים (backfill חד-פעמי מול ה-DB החי)

חוברו 128 קצוות → ייחודיים-בקורפוס 67→178, נותרים-חסרים ייחודיים 262→143. כלומר "בשימוש וטרם הועלה" האמיתי ≈ 143 (לא 262 שהגרף-המיושן רמז).

Invariants

G1 (פתרון-מחדש של הקישור-הנגזר בכתיבה) · G2 (פותר יחיד)

🤖 Generated with Claude Code

## מה `precedent_internal_citations` פותר `cited_case_law_id` **רק בזמן-חילוץ**. כשהחלטה מצטטת פסיקה שעדיין לא בקורפוס — הקצה נשמר עם `NULL`. הפסיקה מועלית לרוב ימים אחר-כך, אך הקצה היתום **לא נפתר-מחדש לעולם** → גרף-הציטוטים מתחת-סופר את הקישוריות (אותו דפוס ערך-נגזר-מיושן כמו `searchable`). מחמיר: פסיקה חיצונית נשמרת **בלי תחילית-ערכאה** (`3213/97`) בעוד הציטוט נושא אותה (`ע"א 3213/97`) — ולכן חלק גדול מה"חסרים" היה בעצם **קיים-אך-לא-מקושר**. ## שינוי - פונקציה חדשה `citation_extractor.relink_orphan_citations(case_law_id=None)` — פותרת-מחדש קצוות-יתומים דרך הפותר הקנוני `_resolve_case_law_id` (אפס לוגיקת-התאמה מקבילה, G2); ממוקדת-שורה או סריקה-מלאה כש-None. idempotent. - `ingest_document` קורא לה בכל העלאה (non-fatal) → הגרף מרפא את עצמו. ## נתונים קיימים (backfill חד-פעמי מול ה-DB החי) חוברו **128 קצוות** → ייחודיים-בקורפוס 67→**178**, נותרים-חסרים ייחודיים 262→**143**. כלומר "בשימוש וטרם הועלה" האמיתי ≈ **143** (לא 262 שהגרף-המיושן רמז). ## Invariants G1 (פתרון-מחדש של הקישור-הנגזר בכתיבה) · G2 (פותר יחיד) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-06-20 11:47:11 +00:00
fix(corpus): re-link orphan citations when a cited ruling is uploaded (G1)
All checks were successful
G12 Leak-Guard / leak-guard (pull_request) Successful in 3s
Lint — undefined names / undefined-names (pull_request) Successful in 10s
f7bf437f67
precedent_internal_citations resolves cited_case_law_id only at extraction
time. When a decision cites a ruling that isn't in the corpus yet, the edge is
stored with cited_case_law_id=NULL. The ruling is often uploaded days later —
but the orphan edge was never re-resolved, so the citation graph permanently
under-counted real connectivity (same stale-derived-value pattern as the
searchable flag). Worse, external rulings store case_number WITHOUT the court
prefix ("3213/97") while citations carry it ("ע\"א 3213/97"), so a large share
of "missing" citations were actually present-but-unlinked.

Fix:
- new citation_extractor.relink_orphan_citations(case_law_id=None): re-resolves
  orphan edges via the canonical _resolve_case_law_id (no parallel matching, G2);
  scoped to one row, or full sweep when None. Idempotent.
- ingest_document calls it on every upload (non-fatal) so the graph self-heals.

Existing backlog already re-linked via a one-off sweep against the live DB:
linked 128 edges → in-corpus distinct rulings 67→178, unlinked distinct
262→143. So real "cited but not uploaded" ≈ 143, not the 262 the stale graph
implied.

Invariants: G1 (re-resolve the derived link at the write) · G2 (single resolver).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit 086913ce8d into main 2026-06-20 11:47:17 +00:00
chaim deleted branch worktree-citation-relink 2026-06-20 11:47:18 +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#309