* feat(parties): selection-step evaluation against document-anchored truth
Scores which similar keys are the same party without human labels: every
key in the set carries an org number OCR-read from a linked invoice, so two
keys are the same party exactly when the org numbers agree. Rules and the
Bedrock model both land at 0.91 pair precision; the residual false merges
are different legal entities sharing a trade name, which text cannot and
should not separate. Results and caveats in the README.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* chore(parties): make the model selector opt-in in the selection eval
Sending voucher key text to the AI provider now requires --llm; the
default run scores the rules selector only and makes no network call.
Documents that the opt-in path uses the same configured provider the
production categorizer already sends the same text to.
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>
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>
* feat(parties): phase 0 prerequisites, pg_trgm and golden-set draw
Phase 0 of the Kontakter plan: make the counterparty resolver measurable
before building it.
- Migration 20260902120000 enables pg_trgm (trigram blocking of
counterparty keys) and drops the two context-graph tables from
20260706193007 whose feature code was never merged and which prod no
longer has, so fresh replays agree with prod.
- tests/pg/parties-phase0.pg.test.ts pins the extension, a sanity check on
trigram ranking, and the absence of the graph tables.
- scripts/parties/draw-golden-set.sql is the reproducible, read-only draw
of the 200-key labelling sample (three strata, md5-ordered) and the
payee-identity base rate. The drawn rows contain customer voucher text
and are kept in gitignored dev_docs, never in this public repo.
- scripts/parties/README.md records the label vocabulary and the numbers
measured on prod on 2026-09-02.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(archive): drop the two context-graph tables from the archive contract
The migration in this PR removes graph_counterparties and
graph_transaction_counterparties, so the full-archive contract must stop
classifying them: tests/schema/no-phantom-columns.test.ts asserts that
every classified table exists in the migration replay, and the live-DB
twin in tests/pg/full-archive-coverage.pg.test.ts asserts the same against
information_schema.
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>