feat(ai-runtime): complete ai runtime policy refactor (ADR-035)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
-- Rollback: ลบตาราง ai_execution_profiles
|
||||
-- Date: 2026-06-11
|
||||
-- Related Delta: 2026-06-11-create-ai-execution-profiles.sql
|
||||
-- ------------------------------------------------------------
|
||||
|
||||
DROP TABLE IF EXISTS ai_execution_profiles;
|
||||
@@ -0,0 +1,38 @@
|
||||
-- Delta: สร้างตาราง ai_execution_profiles สำหรับ AI Runtime Policy Refactor
|
||||
-- Date: 2026-06-11
|
||||
-- Related ADR: ADR-029, Feature-235
|
||||
-- Source of defaults: docs/ai-profiles.md
|
||||
-- Applied in: v1.9.x (AI Runtime Policy Refactor cutover)
|
||||
-- ------------------------------------------------------------
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ai_execution_profiles (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ID ภายใน (ไม่ expose ใน API)',
|
||||
profile_name VARCHAR(50) NOT NULL COMMENT 'ชื่อ profile: interactive, standard, quality, deep-analysis',
|
||||
temperature DECIMAL(4,3) NOT NULL COMMENT 'LLM temperature parameter',
|
||||
top_p DECIMAL(4,3) NOT NULL COMMENT 'LLM top_p parameter',
|
||||
max_tokens INT NOT NULL COMMENT 'Maximum tokens to generate',
|
||||
num_ctx INT NOT NULL COMMENT 'Context window size (tokens)',
|
||||
repeat_penalty DECIMAL(5,3) NOT NULL COMMENT 'Repeat penalty parameter',
|
||||
keep_alive_seconds INT NOT NULL COMMENT 'Model keep_alive in seconds (0 = unload immediately)',
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1 = profile นี้ใช้งานได้; 0 = disabled',
|
||||
updated_by INT NULL COMMENT 'user_id ที่แก้ไขล่าสุด (NULL = seed default)',
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_profile_name (profile_name),
|
||||
INDEX idx_profile_active (profile_name, is_active),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(user_id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
|
||||
COMMENT = 'ตาราง execution profile parameters สำหรับ np-dms-ai (ADR-029, Feature-235); ค่า default จาก docs/ai-profiles.md';
|
||||
|
||||
-- ------------------------------------------------------------
|
||||
-- Seed: default profiles จาก docs/ai-profiles.md
|
||||
-- ------------------------------------------------------------
|
||||
INSERT INTO ai_execution_profiles (
|
||||
profile_name, temperature, top_p, max_tokens, num_ctx, repeat_penalty, keep_alive_seconds
|
||||
) VALUES
|
||||
('interactive', 0.700, 0.900, 2048, 4096, 1.150, 300), -- keep_alive: "5m"
|
||||
('standard', 0.500, 0.800, 4096, 8192, 1.150, 600), -- keep_alive: "10m"
|
||||
('quality', 0.100, 0.950, 8192, 8192, 1.150, 600), -- keep_alive: "10m"
|
||||
('deep-analysis', 0.300, 0.850, 8192, 32768, 1.150, 0) -- keep_alive: "0" (admin sandbox only)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
profile_name = profile_name; -- no-op: ไม่ overwrite ค่าที่ admin calibrate ไว้แล้ว
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
-- Rollback: ลบ fields ที่เพิ่มสำหรับ AI Runtime Policy Refactor
|
||||
-- Date: 2026-06-11
|
||||
-- Related Delta: 2026-06-11-extend-ai-audit-logs-runtime-policy.sql
|
||||
-- ------------------------------------------------------------
|
||||
|
||||
ALTER TABLE ai_audit_logs
|
||||
DROP INDEX IF EXISTS idx_ai_audit_canonical_model;
|
||||
|
||||
ALTER TABLE ai_audit_logs
|
||||
DROP INDEX IF EXISTS idx_ai_audit_effective_profile;
|
||||
|
||||
ALTER TABLE ai_audit_logs
|
||||
DROP COLUMN IF EXISTS snapshot_params_json;
|
||||
|
||||
ALTER TABLE ai_audit_logs
|
||||
DROP COLUMN IF EXISTS canonical_model;
|
||||
|
||||
ALTER TABLE ai_audit_logs
|
||||
DROP COLUMN IF EXISTS effective_profile;
|
||||
@@ -0,0 +1,37 @@
|
||||
-- Delta: เพิ่ม fields สำหรับ AI Runtime Policy Refactor ใน ai_audit_logs
|
||||
-- Date: 2026-06-11
|
||||
-- Related ADR: ADR-023, ADR-029, Feature-235
|
||||
-- Applied in: AI Runtime Policy Refactor cutover (big bang)
|
||||
-- ------------------------------------------------------------
|
||||
-- เพิ่ม 3 columns:
|
||||
-- effective_profile — profile name ที่ backend กำหนด (interactive/standard/quality/deep-analysis)
|
||||
-- canonical_model — canonical model identity (np-dms-ai / np-dms-ocr)
|
||||
-- snapshot_params_json — parameters snapshot ณ เวลา dispatch (FR-A09)
|
||||
-- ------------------------------------------------------------
|
||||
|
||||
-- effective_profile: ชื่อ ExecutionProfile ที่ backend กำหนดจาก job.type
|
||||
ALTER TABLE ai_audit_logs
|
||||
ADD COLUMN IF NOT EXISTS effective_profile VARCHAR(50) NULL
|
||||
COMMENT 'ExecutionProfile ที่ backend กำหนด: interactive|standard|quality|deep-analysis (Feature-235)'
|
||||
AFTER model_name;
|
||||
|
||||
-- canonical_model: ชื่อ canonical identity — ไม่ใช่ runtime tag
|
||||
ALTER TABLE ai_audit_logs
|
||||
ADD COLUMN IF NOT EXISTS canonical_model VARCHAR(50) NULL
|
||||
COMMENT 'Canonical model identity: np-dms-ai หรือ np-dms-ocr (Feature-235, ADR-023)'
|
||||
AFTER effective_profile;
|
||||
|
||||
-- snapshot_params_json: parameters ที่ถูก snapshot ตอน dispatch โดย AiPolicyService (FR-A09)
|
||||
-- { temperature, topP, maxTokens, numCtx, repeatPenalty, keepAliveSeconds }
|
||||
ALTER TABLE ai_audit_logs
|
||||
ADD COLUMN IF NOT EXISTS snapshot_params_json JSON NULL
|
||||
COMMENT 'Runtime parameters snapshot ณ เวลา dispatch — ใช้จริงใน Ollama call (FR-A09, Feature-235)'
|
||||
AFTER canonical_model;
|
||||
|
||||
-- index สำหรับ analytics queries ตาม profile
|
||||
ALTER TABLE ai_audit_logs
|
||||
ADD INDEX IF NOT EXISTS idx_ai_audit_effective_profile (effective_profile);
|
||||
|
||||
-- index สำหรับ canonical_model
|
||||
ALTER TABLE ai_audit_logs
|
||||
ADD INDEX IF NOT EXISTS idx_ai_audit_canonical_model (canonical_model);
|
||||
Reference in New Issue
Block a user