create_tables.sql
11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
-- Fresh database schema for the wiki and independent RAG systems.
-- This project is new, so the schema is intentionally expressed as create-only DDL.
CREATE DATABASE IF NOT EXISTS `wiki_db` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `wiki_db`;
CREATE TABLE IF NOT EXISTS `wiki_files` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`name` VARCHAR(255) NOT NULL COMMENT 'Original file name',
`format` VARCHAR(50) NOT NULL COMMENT 'File extension or format',
`size` BIGINT NOT NULL COMMENT 'File size in bytes',
`word_count` INT NOT NULL DEFAULT 0 COMMENT 'Parsed word or character count',
`status` VARCHAR(50) NOT NULL DEFAULT 'Pending' COMMENT 'Pending/Uploading/Ingesting/Indexed/Failed',
`input_tokens` INT NOT NULL DEFAULT 0 COMMENT 'Input LLM tokens consumed by ingestion',
`output_tokens` INT NOT NULL DEFAULT 0 COMMENT 'Output LLM tokens consumed by ingestion',
`total_tokens` INT NOT NULL DEFAULT 0 COMMENT 'Total LLM tokens consumed by ingestion',
`ingest_duration` DECIMAL(10, 2) NOT NULL DEFAULT 0.00 COMMENT 'Ingestion duration in seconds',
`ingest_time` DATETIME DEFAULT NULL COMMENT 'Last successful ingestion time',
`error_message` TEXT DEFAULT NULL COMMENT 'Last ingestion error',
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated time',
INDEX `idx_wiki_files_name` (`name`),
INDEX `idx_wiki_files_status` (`status`),
INDEX `idx_wiki_files_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Wiki uploaded files';
CREATE TABLE IF NOT EXISTS `wiki_file_pages` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`file_id` VARCHAR(36) NOT NULL COMMENT 'Related wiki file UUID',
`page_path` VARCHAR(512) NOT NULL COMMENT 'Generated wiki page path',
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
UNIQUE KEY `uq_wiki_file_pages_file_path` (`file_id`, `page_path`),
INDEX `idx_wiki_file_pages_file` (`file_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Wiki generated page links';
CREATE TABLE IF NOT EXISTS `wiki_operation_logs` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`file_id` VARCHAR(36) DEFAULT NULL COMMENT 'Related wiki file UUID',
`file_name` VARCHAR(255) DEFAULT NULL COMMENT 'Denormalized file name',
`operation` VARCHAR(50) NOT NULL COMMENT 'Operation type',
`details` TEXT DEFAULT NULL COMMENT 'Operation details as JSON text',
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
INDEX `idx_wiki_operation_logs_file_created` (`file_id`, `created_at`),
INDEX `idx_wiki_operation_logs_operation_created` (`operation`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Wiki operation logs';
CREATE TABLE IF NOT EXISTS `wiki_query_logs` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`session_id` VARCHAR(100) DEFAULT NULL COMMENT 'Conversation session ID',
`query_text` LONGTEXT NOT NULL COMMENT 'User query',
`history` LONGTEXT DEFAULT NULL COMMENT 'Conversation history JSON',
`answer_text` LONGTEXT DEFAULT NULL COMMENT 'Generated answer',
`model_name` VARCHAR(50) DEFAULT NULL COMMENT 'Model name',
`total_tokens` INT NOT NULL DEFAULT 0 COMMENT 'Token usage',
`duration_ms` INT NOT NULL DEFAULT 0 COMMENT 'Duration in milliseconds',
`status` VARCHAR(50) NOT NULL DEFAULT 'Success' COMMENT 'Success/Error/Timeout/EmptyAnswer',
`error_message` LONGTEXT DEFAULT NULL COMMENT 'Error message',
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
INDEX `idx_wiki_query_logs_session_created` (`session_id`, `created_at`),
INDEX `idx_wiki_query_logs_status_created` (`status`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Wiki query logs';
CREATE TABLE IF NOT EXISTS `rag_documents` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`name` VARCHAR(255) NOT NULL COMMENT 'Source file name',
`file_type` VARCHAR(50) NOT NULL COMMENT 'Source file type',
`size` BIGINT NOT NULL DEFAULT 0 COMMENT 'File size in bytes',
`word_count` INT NOT NULL DEFAULT 0 COMMENT 'Parsed word or character count',
`status` VARCHAR(50) NOT NULL DEFAULT 'Pending' COMMENT 'Uploading/Pending/Indexing/Indexed/Failed/Disabled/Deleted',
`source_path` VARCHAR(1024) NOT NULL COMMENT 'Local source path',
`content_hash` VARCHAR(128) NULL COMMENT 'Source content hash',
`metadata_json` LONGTEXT NULL COMMENT 'Document metadata JSON',
`parser_version` VARCHAR(50) NULL COMMENT 'Parser version',
`chunker_version` VARCHAR(50) NULL COMMENT 'Chunker version',
`block_count` INT NOT NULL DEFAULT 0 COMMENT 'Parsed block count',
`chunk_count` INT NOT NULL DEFAULT 0 COMMENT 'Total chunk count',
`parent_chunk_count` INT NOT NULL DEFAULT 0 COMMENT 'Parent chunk count',
`child_chunk_count` INT NOT NULL DEFAULT 0 COMMENT 'Child chunk count',
`index_duration_ms` INT NOT NULL DEFAULT 0 COMMENT 'Last index duration in milliseconds',
`vlm_page_count` INT NOT NULL DEFAULT 0 COMMENT 'VLM parsed page count',
`vlm_total_tokens` INT NOT NULL DEFAULT 0 COMMENT 'VLM token usage',
`vlm_duration_ms` INT NOT NULL DEFAULT 0 COMMENT 'VLM duration in milliseconds',
`error_code` VARCHAR(100) NULL COMMENT 'Structured error code',
`error_detail_json` LONGTEXT NULL COMMENT 'Structured error detail JSON',
`error_message` LONGTEXT NULL COMMENT 'Error message',
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
`updated_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated time',
`index_started_at` DATETIME NULL COMMENT 'Last index start time',
`indexed_at` DATETIME NULL COMMENT 'Last successful index time',
INDEX `idx_rag_documents_status` (`status`),
INDEX `idx_rag_documents_hash` (`content_hash`),
INDEX `idx_rag_documents_name_status` (`name`, `status`),
INDEX `idx_rag_documents_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='RAG source documents';
CREATE TABLE IF NOT EXISTS `rag_chunks` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`chunk_id` VARCHAR(64) NOT NULL COMMENT 'Business chunk ID used by vector payloads',
`document_id` VARCHAR(36) NOT NULL COMMENT 'Related RAG document UUID',
`parent_chunk_id` VARCHAR(64) NULL COMMENT 'Parent business chunk ID',
`chunk_level` VARCHAR(20) NOT NULL COMMENT 'parent/child',
`chunk_index` INT NOT NULL DEFAULT 0 COMMENT 'Chunk order in document',
`content` LONGTEXT NOT NULL COMMENT 'Chunk content',
`content_hash` VARCHAR(128) NOT NULL COMMENT 'Chunk content hash',
`token_estimate` INT NOT NULL DEFAULT 0 COMMENT 'Estimated token count',
`title_path` VARCHAR(1024) NULL COMMENT 'Title path',
`source_name` VARCHAR(255) NOT NULL COMMENT 'Source name',
`page_start` INT NULL COMMENT 'Start page',
`page_end` INT NULL COMMENT 'End page',
`row_start` INT NULL COMMENT 'Start row',
`row_end` INT NULL COMMENT 'End row',
`prev_chunk_id` VARCHAR(64) NULL COMMENT 'Previous sibling business chunk ID',
`next_chunk_id` VARCHAR(64) NULL COMMENT 'Next sibling business chunk ID',
`status` VARCHAR(50) NOT NULL DEFAULT 'active' COMMENT 'active/deleted/disabled',
`brand_series` VARCHAR(100) NULL COMMENT 'Brand or series label',
`business_category` VARCHAR(100) NULL COMMENT 'Business category label',
`content_kind` VARCHAR(50) NULL COMMENT 'text/table/image/etc',
`section_title` VARCHAR(255) NULL COMMENT 'Section title',
`parse_status` VARCHAR(50) NULL COMMENT 'Parse status or quality marker',
`qdrant_point_id` VARCHAR(64) NULL COMMENT 'Qdrant point UUID',
`metadata_json` LONGTEXT NULL COMMENT 'Extended chunk metadata JSON',
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
UNIQUE KEY `uq_rag_chunks_chunk_id` (`chunk_id`),
INDEX `idx_rag_chunks_document_level_status` (`document_id`, `chunk_level`, `status`),
INDEX `idx_rag_chunks_document_level_index` (`document_id`, `chunk_level`, `chunk_index`),
INDEX `idx_rag_chunks_parent` (`parent_chunk_id`),
INDEX `idx_rag_chunks_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='RAG chunks';
CREATE TABLE IF NOT EXISTS `rag_index_runs` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`document_id` VARCHAR(36) NOT NULL COMMENT 'Related RAG document UUID',
`status` VARCHAR(50) NOT NULL COMMENT 'Run status',
`parser_version` VARCHAR(50) NULL COMMENT 'Parser version',
`chunker_version` VARCHAR(50) NULL COMMENT 'Chunker version',
`block_count` INT NOT NULL DEFAULT 0 COMMENT 'Parsed block count',
`parent_chunk_count` INT NOT NULL DEFAULT 0 COMMENT 'Parent chunk count',
`child_chunk_count` INT NOT NULL DEFAULT 0 COMMENT 'Child chunk count',
`vector_count` INT NOT NULL DEFAULT 0 COMMENT 'Vector count',
`duration_ms` INT NOT NULL DEFAULT 0 COMMENT 'Duration in milliseconds',
`vlm_page_count` INT NOT NULL DEFAULT 0 COMMENT 'VLM parsed page count',
`vlm_total_tokens` INT NOT NULL DEFAULT 0 COMMENT 'VLM token usage',
`error_code` VARCHAR(100) NULL COMMENT 'Structured error code',
`error_detail_json` LONGTEXT NULL COMMENT 'Structured error detail JSON',
`error_message` LONGTEXT NULL COMMENT 'Error message',
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
INDEX `idx_rag_index_runs_document_created` (`document_id`, `created_at`),
INDEX `idx_rag_index_runs_status_created` (`status`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='RAG index run logs';
CREATE TABLE IF NOT EXISTS `rag_query_logs` (
`id` VARCHAR(36) NOT NULL PRIMARY KEY COMMENT 'UUID primary key',
`session_id` VARCHAR(100) NULL COMMENT 'Conversation session ID',
`query_text` LONGTEXT NOT NULL COMMENT 'Original user query',
`rewritten_query` LONGTEXT NULL COMMENT 'Rewritten query',
`intent_result_json` LONGTEXT NULL COMMENT 'Intent result JSON',
`retrieval_plan_json` LONGTEXT NULL COMMENT 'Retrieval plan JSON',
`query_plan_json` LONGTEXT NULL COMMENT 'Query plan JSON',
`filters_json` LONGTEXT NULL COMMENT 'Applied filters JSON',
`ranked_json` LONGTEXT NULL COMMENT 'Ranked candidates JSON',
`sources_json` LONGTEXT NULL COMMENT 'Answer sources JSON',
`adopted_chunk_ids_json` LONGTEXT NULL COMMENT 'Adopted chunk IDs JSON',
`citation_map_json` LONGTEXT NULL COMMENT 'Citation map JSON',
`answer_text` LONGTEXT NULL COMMENT 'Final answer',
`model_name` VARCHAR(100) NULL COMMENT 'Model name',
`total_tokens` INT NOT NULL DEFAULT 0 COMMENT 'Token usage',
`duration_ms` INT NOT NULL DEFAULT 0 COMMENT 'Duration in milliseconds',
`status` VARCHAR(50) NOT NULL DEFAULT 'Success' COMMENT 'Success/Error',
`error_message` LONGTEXT NULL COMMENT 'Error message',
`created_at` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Created time',
INDEX `idx_rag_query_logs_session_status_created` (`session_id`, `status`, `created_at`),
INDEX `idx_rag_query_logs_status_created` (`status`, `created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='RAG query logs';