690519:1631 224 to 226 AI #01
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
-- Delta 16: Add Intent Classification Tables (ADR-024)
|
||||
-- Feature: 224-intent-classification
|
||||
-- Created: 2026-05-19
|
||||
-- เพิ่มตาราง ai_intent_definitions และ ai_intent_patterns สำหรับ Hybrid Intent Classifier
|
||||
|
||||
-- Intent Definitions Table
|
||||
CREATE TABLE IF NOT EXISTS ai_intent_definitions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
public_id UUID NOT NULL DEFAULT UUID(),
|
||||
intent_code VARCHAR(50) NOT NULL,
|
||||
description_th VARCHAR(255) NOT NULL,
|
||||
description_en VARCHAR(255) NOT NULL,
|
||||
category ENUM('read', 'suggest', 'utility') NOT NULL,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
UNIQUE KEY uk_intent_public_id (public_id),
|
||||
UNIQUE KEY uk_intent_code (intent_code),
|
||||
INDEX idx_intent_active (is_active, category)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Intent Patterns Table
|
||||
CREATE TABLE IF NOT EXISTS ai_intent_patterns (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
public_id UUID NOT NULL DEFAULT UUID(),
|
||||
intent_code VARCHAR(50) NOT NULL,
|
||||
language ENUM('th', 'en', 'any') NOT NULL DEFAULT 'any',
|
||||
pattern_type ENUM('keyword', 'regex') NOT NULL DEFAULT 'keyword',
|
||||
pattern_value VARCHAR(255) NOT NULL,
|
||||
priority INT NOT NULL DEFAULT 100,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
UNIQUE KEY uk_pattern_public_id (public_id),
|
||||
INDEX idx_pattern_intent_code (intent_code),
|
||||
INDEX idx_pattern_active_priority (is_active, priority ASC),
|
||||
CONSTRAINT fk_intent_pattern_definition
|
||||
FOREIGN KEY (intent_code) REFERENCES ai_intent_definitions(intent_code)
|
||||
ON UPDATE CASCADE ON DELETE RESTRICT
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Seed Intent Definitions (v1) — 12 รายการตาม ADR-024
|
||||
INSERT IGNORE INTO ai_intent_definitions (intent_code, description_th, description_en, category) VALUES
|
||||
-- Read Intents
|
||||
('RAG_QUERY', 'ถามคำถามธรรมชาติ ตอบจาก vector + doc context', 'Natural language query from vector DB + document context', 'read'),
|
||||
('GET_RFA', 'ดึง RFA ตาม filter', 'Get RFA by filters', 'read'),
|
||||
('GET_DRAWING', 'ดึง Drawing revision', 'Get Drawing revision', 'read'),
|
||||
('GET_TRANSMITTAL', 'ดึง Transmittal', 'Get Transmittal', 'read'),
|
||||
('GET_CORRESPONDENCE','ดึง Correspondence ทั่วไป', 'Get Correspondence', 'read'),
|
||||
('GET_CIRCULATION', 'ดึง Circulation', 'Get Circulation', 'read'),
|
||||
('GET_RFA_DRAWINGS', 'ดึง Drawings ที่ผูกกับ RFA', 'Get Drawings linked to RFA', 'read'),
|
||||
('SUMMARIZE_DOCUMENT','สรุปเอกสารที่เปิดอยู่', 'Summarize current document', 'read'),
|
||||
('LIST_OVERDUE', 'รายการ cross-entity ที่เกินกำหนด', 'List overdue items across entities', 'read'),
|
||||
-- Suggest Intents
|
||||
('SUGGEST_METADATA', 'แนะนำ metadata สำหรับเอกสารที่อัปโหลด', 'Suggest metadata for uploaded document', 'suggest'),
|
||||
('SUGGEST_ACTION', 'แจ้งเตือนว่าควรทำอะไรต่อ', 'Suggest next actions', 'suggest'),
|
||||
-- Utility Intents
|
||||
('FALLBACK', 'ไม่เข้า intent ไหน / ไม่เกี่ยวกับระบบ', 'No matching intent / unrelated to system', 'utility');
|
||||
@@ -0,0 +1,89 @@
|
||||
-- Delta 17: Seed Intent Patterns (v1) for ADR-024 Intent Classification
|
||||
-- Feature: 224-intent-classification
|
||||
-- Created: 2026-05-19
|
||||
-- เพิ่ม patterns เริ่มต้นสำหรับ 12 Intent Definitions (keyword + regex)
|
||||
|
||||
-- RAG_QUERY patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('RAG_QUERY', 'th', 'keyword', 'ค้นหา', 10),
|
||||
('RAG_QUERY', 'th', 'keyword', 'หาข้อมูล', 10),
|
||||
('RAG_QUERY', 'en', 'keyword', 'search', 10),
|
||||
('RAG_QUERY', 'en', 'keyword', 'find', 10),
|
||||
('RAG_QUERY', 'any', 'regex', '(?i)(what|where|who|when|how|why).*\\?', 50);
|
||||
|
||||
-- GET_RFA patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('GET_RFA', 'th', 'keyword', 'rfa', 10),
|
||||
('GET_RFA', 'th', 'keyword', 'อาร์เอฟเอ', 10),
|
||||
('GET_RFA', 'en', 'keyword', 'request for approval', 15),
|
||||
('GET_RFA', 'any', 'regex', '(?i)rfa[- ]?\\d+', 5);
|
||||
|
||||
-- GET_DRAWING patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('GET_DRAWING', 'th', 'keyword', 'แบบ', 20),
|
||||
('GET_DRAWING', 'th', 'keyword', 'drawing', 10),
|
||||
('GET_DRAWING', 'en', 'keyword', 'drawing', 10),
|
||||
('GET_DRAWING', 'en', 'keyword', 'revision', 20),
|
||||
('GET_DRAWING', 'any', 'regex', '(?i)(shop.?draw|dwg|rev\\.?\\s*\\d)', 5);
|
||||
|
||||
-- GET_TRANSMITTAL patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('GET_TRANSMITTAL', 'th', 'keyword', 'transmittal', 10),
|
||||
('GET_TRANSMITTAL', 'th', 'keyword', 'ทรานส์มิตทอล', 10),
|
||||
('GET_TRANSMITTAL', 'en', 'keyword', 'transmittal', 10),
|
||||
('GET_TRANSMITTAL', 'any', 'regex', '(?i)tr[- ]?\\d+', 5);
|
||||
|
||||
-- GET_CORRESPONDENCE patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('GET_CORRESPONDENCE', 'th', 'keyword', 'จดหมาย', 10),
|
||||
('GET_CORRESPONDENCE', 'th', 'keyword', 'หนังสือ', 15),
|
||||
('GET_CORRESPONDENCE', 'en', 'keyword', 'correspondence', 10),
|
||||
('GET_CORRESPONDENCE', 'en', 'keyword', 'letter', 15);
|
||||
|
||||
-- GET_CIRCULATION patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('GET_CIRCULATION', 'th', 'keyword', 'เวียน', 10),
|
||||
('GET_CIRCULATION', 'th', 'keyword', 'circulation', 10),
|
||||
('GET_CIRCULATION', 'en', 'keyword', 'circulation', 10),
|
||||
('GET_CIRCULATION', 'en', 'keyword', 'distribute', 15);
|
||||
|
||||
-- GET_RFA_DRAWINGS patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('GET_RFA_DRAWINGS', 'th', 'keyword', 'แบบใน rfa', 5),
|
||||
('GET_RFA_DRAWINGS', 'en', 'keyword', 'drawings in rfa', 5),
|
||||
('GET_RFA_DRAWINGS', 'any', 'regex', '(?i)(draw|แบบ).*(rfa|อาร์เอฟเอ)', 5);
|
||||
|
||||
-- SUMMARIZE_DOCUMENT patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('SUMMARIZE_DOCUMENT', 'th', 'keyword', 'สรุป', 10),
|
||||
('SUMMARIZE_DOCUMENT', 'th', 'keyword', 'สรุปเอกสาร', 5),
|
||||
('SUMMARIZE_DOCUMENT', 'en', 'keyword', 'summarize', 10),
|
||||
('SUMMARIZE_DOCUMENT', 'en', 'keyword', 'summary', 10),
|
||||
('SUMMARIZE_DOCUMENT', 'any', 'regex', '(?i)(สรุป|summar|tldr|tl;dr)', 5);
|
||||
|
||||
-- LIST_OVERDUE patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('LIST_OVERDUE', 'th', 'keyword', 'เกินกำหนด', 10),
|
||||
('LIST_OVERDUE', 'th', 'keyword', 'ค้าง', 15),
|
||||
('LIST_OVERDUE', 'th', 'keyword', 'overdue', 10),
|
||||
('LIST_OVERDUE', 'en', 'keyword', 'overdue', 10),
|
||||
('LIST_OVERDUE', 'en', 'keyword', 'late', 20),
|
||||
('LIST_OVERDUE', 'any', 'regex', '(?i)(overdue|เกินกำหนด|ล่าช้า)', 5);
|
||||
|
||||
-- SUGGEST_METADATA patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('SUGGEST_METADATA', 'th', 'keyword', 'แนะนำ metadata', 5),
|
||||
('SUGGEST_METADATA', 'th', 'keyword', 'แท็ก', 15),
|
||||
('SUGGEST_METADATA', 'en', 'keyword', 'suggest metadata', 5),
|
||||
('SUGGEST_METADATA', 'en', 'keyword', 'tag', 15),
|
||||
('SUGGEST_METADATA', 'any', 'regex', '(?i)(suggest|แนะนำ).*(tag|meta|ประเภท)', 5);
|
||||
|
||||
-- SUGGEST_ACTION patterns
|
||||
INSERT IGNORE INTO ai_intent_patterns (intent_code, language, pattern_type, pattern_value, priority) VALUES
|
||||
('SUGGEST_ACTION', 'th', 'keyword', 'ทำอะไรต่อ', 10),
|
||||
('SUGGEST_ACTION', 'th', 'keyword', 'แนะนำ', 20),
|
||||
('SUGGEST_ACTION', 'en', 'keyword', 'what should i do', 10),
|
||||
('SUGGEST_ACTION', 'en', 'keyword', 'next step', 10),
|
||||
('SUGGEST_ACTION', 'any', 'regex', '(?i)(next.?step|ทำอะไร|ควรทำ|what.*do)', 10);
|
||||
|
||||
-- FALLBACK: ไม่ต้อง seed pattern — ใช้เป็น default เมื่อไม่ match อะไรเลย
|
||||
Reference in New Issue
Block a user