CREATE TABLE `rag_snippet` (
  `rag_item_id` bigint NOT NULL COMMENT 'RAG item id (stable hash of table/version/snippet_id)',
  `workspace_id` bigint NOT NULL COMMENT 'RAG workspace scope',
  `table_id` bigint NOT NULL COMMENT '来源表ID',
  `version_ts` bigint NOT NULL COMMENT '表版本号',
  `action_result_id` bigint NOT NULL COMMENT '来源 action_results 主键ID（snippet_alias 或 snippet 行）',
  `snippet_id` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '原始 snippet id',
  `rag_text` text COLLATE utf8mb4_bin NOT NULL COMMENT '用于向量化的拼接文本',
  `merged_json` json NOT NULL COMMENT '合并后的 snippet 对象',
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`rag_item_id`),
  KEY `idx_action_result` (`action_result_id`),
  KEY `idx_workspace` (`workspace_id`),
  KEY `idx_table_version` (`table_id`,`version_ts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='RAG snippet 索引缓存';
