perf(citation-verification): cache view + parallelize backend retrieval #369

Merged
chaim merged 1 commits from worktree-citation-verify-perf into main 2026-06-30 17:36:37 +00:00
Owner

למה

טאב "אימות פסיקה" נטען מחדש בכל כניסה, וגם הטעינה הראשונה לקחה 1.5–3 שניות. אבחון מצא שני שורשים בלתי-תלויים.

מה

Frontendweb-ui/src/lib/api/citation-verification.ts

  • staleTime 10ש' → 5 דק' + refetchOnMount: false. Radix Tabs מוריד (unmount) את תוכן-הטאב הלא-פעיל, אז מעבר חזרה אחרי חלון 10ש' גרם build מלא מחדש. מוטציות-האימות עדיין מבצעות invalidateQueries, כך שעריכה מושכת נתון טרי.

Backendmcp-server/src/legal_mcp/services/case_citation_verification.py

  • לולאת ה-per-argument רצה בטור (לכל טיעון: Voyage embed + חיפוש-וקטורי + authority — ~300ms × N). חולצה ל-_fetch() ומפוזרת עם asyncio.gather. הסדר נשמר (gather), מונה n_verified ו-seen-sets לכל-טיעון ללא שינוי. טעינה ראשונה ~פי-5 מהירה יותר בתיקים רב-טיעוניים.

Invariants

  • G2 — אין מסלול-אחזור מקביל חדש; אותו search_library + citation_authority + radar, רק במקביל במקום בטור.
  • §6 (אין בליעה שקטה) — כשלי search/radar עדיין מתועדים כ-warning.
  • INV-DIG1 / INV-AH — ללא שינוי: הצירוף נשאר read-only, לעולם לא מצטט.

בדיקות

  • py_compile · tsc --noEmit (build מלא ב-CI; Turbopack שבור ב-worktree עם symlink).

🤖 Generated with Claude Code

## למה טאב **"אימות פסיקה"** נטען מחדש בכל כניסה, וגם הטעינה הראשונה לקחה 1.5–3 שניות. אבחון מצא שני שורשים בלתי-תלויים. ## מה **Frontend** — [`web-ui/src/lib/api/citation-verification.ts`](web-ui/src/lib/api/citation-verification.ts) - `staleTime` 10ש' → 5 דק' + `refetchOnMount: false`. Radix Tabs מוריד (unmount) את תוכן-הטאב הלא-פעיל, אז מעבר חזרה אחרי חלון 10ש' גרם build מלא מחדש. מוטציות-האימות עדיין מבצעות `invalidateQueries`, כך שעריכה מושכת נתון טרי. **Backend** — [`mcp-server/src/legal_mcp/services/case_citation_verification.py`](mcp-server/src/legal_mcp/services/case_citation_verification.py) - לולאת ה-per-argument רצה **בטור** (לכל טיעון: Voyage embed + חיפוש-וקטורי + authority — ~300ms × N). חולצה ל-`_fetch()` ומפוזרת עם `asyncio.gather`. הסדר נשמר (gather), מונה `n_verified` ו-`seen`-sets לכל-טיעון ללא שינוי. טעינה ראשונה ~פי-5 מהירה יותר בתיקים רב-טיעוניים. ## Invariants - **G2** — אין מסלול-אחזור מקביל חדש; אותו `search_library` + `citation_authority` + radar, רק במקביל במקום בטור. - **§6 (אין בליעה שקטה)** — כשלי search/radar עדיין מתועדים כ-warning. - **INV-DIG1 / INV-AH** — ללא שינוי: הצירוף נשאר read-only, לעולם לא מצטט. ## בדיקות - `py_compile` ✅ · `tsc --noEmit` ✅ (build מלא ב-CI; Turbopack שבור ב-worktree עם symlink). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chaim added 1 commit 2026-06-30 17:36:25 +00:00
perf(citation-verification): cache view + parallelize backend retrieval
All checks were successful
G12 Leak-Guard / leak-guard (pull_request) Successful in 4s
Lint — undefined names / undefined-names (pull_request) Successful in 10s
88ca96bf19
The "אימות פסיקה" tab reloaded its data on every tab revisit and the first
load took 1.5–3s. Two independent causes, two fixes:

Frontend (web-ui/src/lib/api/citation-verification.ts):
- staleTime 10s → 5min and refetchOnMount: false. Radix Tabs unmounts inactive
  TabsContent, so switching back used to trigger a full rebuild once the 10s
  window elapsed. Verify mutations still invalidate the query, so edits pull
  fresh data.

Backend (mcp-server/.../case_citation_verification.py):
- The per-argument loop ran a Voyage embed + vector search + batched authority
  query sequentially (N args × ~300ms waterfall). Extracted to _fetch() and
  fanned out with asyncio.gather — order preserved, n_verified counter and
  per-argument seen-sets unchanged. First load ~5× faster on multi-argument cases.

Pure read/assembly — no new parallel path (G2), no silent error swallowing
(search/radar still log warnings). Invariants: INV-DIG1/INV-AH unaffected
(still read-only, never cites).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chaim merged commit 850ca25239 into main 2026-06-30 17:36:37 +00:00
chaim deleted branch worktree-citation-verify-perf 2026-06-30 17:36:37 +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#369