Private
Public Access
1
0

Add AI categorization with Ollama: settings, auto-classify on sync/import, and manual classify from Transactions

Adds local LLM-based transaction categorization using Ollama:
- Settings UI to configure Ollama URL, model, confidence threshold
- Auto-categorization during bank sync and file import
- Manual "Classify Uncategorized" button on Transactions screen that respects active filters
- Payee default category learning loop for classified transactions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-08 18:41:12 -05:00
parent 57d1051213
commit 1c7abb7ffc
18 changed files with 2423 additions and 3 deletions
@@ -0,0 +1,23 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Purrse.Core.Models;
namespace Purrse.Data.Configurations;
public class AiCategorizationSettingsConfiguration : IEntityTypeConfiguration<AiCategorizationSettings>
{
public void Configure(EntityTypeBuilder<AiCategorizationSettings> builder)
{
builder.ToTable("ai_categorization_settings");
builder.HasKey(s => s.Id);
builder.Property(s => s.OllamaUrl).HasMaxLength(500);
builder.Property(s => s.ModelName).HasMaxLength(100);
builder.HasOne(s => s.User)
.WithOne(u => u.AiCategorizationSettings)
.HasForeignKey<AiCategorizationSettings>(s => s.UserId)
.OnDelete(DeleteBehavior.Cascade);
builder.HasIndex(s => s.UserId).IsUnique();
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,53 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Purrse.Data.Migrations
{
/// <inheritdoc />
public partial class AddAiCategorizationSettings : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ai_categorization_settings",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
OllamaUrl = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
ModelName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
ConfidenceThreshold = table.Column<double>(type: "double precision", nullable: false),
TimeoutSeconds = table.Column<int>(type: "integer", nullable: false),
UpdatePayeeDefaults = table.Column<bool>(type: "boolean", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ai_categorization_settings", x => x.Id);
table.ForeignKey(
name: "FK_ai_categorization_settings_users_UserId",
column: x => x.UserId,
principalTable: "users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ai_categorization_settings_UserId",
table: "ai_categorization_settings",
column: "UserId",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ai_categorization_settings");
}
}
}
@@ -85,6 +85,48 @@ namespace Purrse.Data.Migrations
b.ToTable("accounts", (string)null);
});
modelBuilder.Entity("Purrse.Core.Models.AiCategorizationSettings", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<double>("ConfidenceThreshold")
.HasColumnType("double precision");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("ModelName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<string>("OllamaUrl")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("character varying(500)");
b.Property<int>("TimeoutSeconds")
.HasColumnType("integer");
b.Property<bool>("UpdatePayeeDefaults")
.HasColumnType("boolean");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId")
.IsUnique();
b.ToTable("ai_categorization_settings", (string)null);
});
modelBuilder.Entity("Purrse.Core.Models.AmortizationEntry", b =>
{
b.Property<Guid>("Id")
@@ -994,6 +1036,17 @@ namespace Purrse.Data.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Purrse.Core.Models.AiCategorizationSettings", b =>
{
b.HasOne("Purrse.Core.Models.User", "User")
.WithOne("AiCategorizationSettings")
.HasForeignKey("Purrse.Core.Models.AiCategorizationSettings", "UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("Purrse.Core.Models.AmortizationEntry", b =>
{
b.HasOne("Purrse.Core.Models.LoanDetail", "LoanDetail")
@@ -1396,6 +1449,8 @@ namespace Purrse.Data.Migrations
{
b.Navigation("Accounts");
b.Navigation("AiCategorizationSettings");
b.Navigation("BankSyncSettings");
b.Navigation("SyncConnections");
+1
View File
@@ -30,6 +30,7 @@ public class PurrseDbContext : DbContext
public DbSet<LinkedAccount> LinkedAccounts => Set<LinkedAccount>();
public DbSet<SyncLog> SyncLogs => Set<SyncLog>();
public DbSet<BankSyncSettings> BankSyncSettings => Set<BankSyncSettings>();
public DbSet<AiCategorizationSettings> AiCategorizationSettings => Set<AiCategorizationSettings>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{