Add AI agent decision memory layer with pgvector similarity search
- models/agentdecision.go: AgentDecision GORM model (context/decision as jsonb, reasoning as text) - migrations/migrate.go: AutoMigrate AgentDecision then ALTER TABLE to add vector(1536) column and CREATE ivfflat index via raw SQL - controllers/agentDecisionController.go: CreateAgentDecision, FindSimilarDecisions (cosine distance), UpdateDecisionOutcome - routes/routes.go: three routes under /api/v1/internal (InternalKeyAuth applied at group level) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,7 @@ func Migrate(db *gorm.DB) error {
|
||||
&models.CompetitorBranch{},
|
||||
&models.CarrierPricing{},
|
||||
&models.DoormilePricing{},
|
||||
&models.AgentDecision{},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@@ -48,5 +49,18 @@ func Migrate(db *gorm.DB) error {
|
||||
}
|
||||
|
||||
utils.Info("✅ Database migration completed successfully!")
|
||||
|
||||
if res := db.Exec(`ALTER TABLE agent_decisions ADD COLUMN IF NOT EXISTS context_embedding vector(1536)`); res.Error != nil {
|
||||
utils.Error("❌ Failed to add context_embedding column", "error", res.Error)
|
||||
} else {
|
||||
utils.Info("✅ context_embedding vector column ready")
|
||||
}
|
||||
|
||||
if res := db.Exec(`CREATE INDEX IF NOT EXISTS idx_agent_decisions_embedding ON agent_decisions USING ivfflat (context_embedding vector_cosine_ops) WITH (lists = 100)`); res.Error != nil {
|
||||
utils.Error("❌ Failed to create ivfflat index on context_embedding", "error", res.Error)
|
||||
} else {
|
||||
utils.Info("✅ ivfflat index on context_embedding ready")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user