Migrants arrive with vouchers, not bank transactions, so the bank-keyed
ledger context is empty for them. This adds the description-keyed twin.
- public.ledger_key(text): legibility key on top of the frozen
normalize_counterparty_key mirror: strips AP-register prefixes (levfakt,
leverantörsfaktura från N, levbet, faktura, kvitto, utgift), the supplier
number that follows them, and trailing 1-3 digit runs, never "inköp".
Mirrored by lib/parties/ledger-key.ts; the pair is pinned by a shared
fixture list in the pg test.
- public.get_observed_parties(company, from_date, limit): posted vouchers
grouped by ledger_key(description) with occurrences, variants, expense
and revenue SEK from the lines, first/last seen, median cadence and the
Laplace-smoothed dominant result account. Excludes storno, opening
balance, year-end and VAT settlement, and vouchers that carry a bank
merchant name (those stay with get_ledger_deep_context). SECURITY
INVOKER, so RLS scopes it. Never stored.
- lib/parties/classify.ts: the deterministic pre-classifier moved out of
the evaluation script so product and evaluation share one implementation
(0.965 agreement with the founder labels, party recall 0.99).
- lib/parties/observed.ts: RPC wrapper that classifies each row and
derives a display rhythm from the cadence.
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* feat(parties): shadow evaluation of the key pre-classifier
Scores a deterministic rule router and the Bedrock model router (zero-shot
and with twenty founder examples) against the founder-labelled golden set,
on the same held-out rows, reporting strict agreement plus party TPR/TNR.
Read-only: reads the gitignored JSONL, calls getAiService(), writes a report
next to the input, never opens a database connection.
Results and the definitional disagreements are recorded in the README.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* docs(parties): settle the four edge rules from the first labelling round
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>