Teach local AI from user category corrections

- Add MerchantCorrection model: upsert by merchantName, Category enum
- Check corrections DB first in suggestCategoryForMerchant (source: "learned",
  no confirmation required); falls through to rules then Ollama if no match
- Inject recent corrections as few-shot examples in the Ollama prompt so the
  model improves even for merchants not yet explicitly corrected
- Add POST /categories/correct route to persist corrections
- Detect category override on form save (suggestedCategory !== chosen category)
  and silently fire a correction — no extra UX required
- Fix test isolation: beforeEach re-applies vi.fn() defaults after restoreAllMocks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 17:28:26 -04:00
parent 1015e24e69
commit 3e6231b654
7 changed files with 152 additions and 8 deletions

View File

@@ -42,6 +42,14 @@ model PaySchedule {
createdAt DateTime @default(now())
}
model MerchantCorrection {
id String @id @default(cuid())
merchantName String @unique
category Category
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model MonthlyInsight {
id String @id @default(cuid())
month String @unique