调整rag_snippet表字段格式

This commit is contained in:
zhaoawd
2025-12-09 00:36:02 +08:00
parent 3218e51bad
commit 248492d68e
3 changed files with 20 additions and 3 deletions

View File

@ -435,6 +435,8 @@ def merge_snippet_records_from_db(
for alias_id, alias_info in alias_map.items(): for alias_id, alias_info in alias_map.items():
if alias_id in seen_ids: if alias_id in seen_ids:
continue continue
if alias_action_id is None and snippet_action_id is None:
continue
merged.append( merged.append(
{ {
"id": alias_id, "id": alias_id,
@ -520,11 +522,14 @@ def _prepare_rag_payloads(
else: else:
updated_at = updated_at_raw if isinstance(updated_at_raw, datetime) else now updated_at = updated_at_raw if isinstance(updated_at_raw, datetime) else now
created_at = updated_at
row = { row = {
"rag_item_id": rag_item_id, "rag_item_id": rag_item_id,
"workspace_id": workspace_id, "workspace_id": workspace_id,
"table_id": table_id, "table_id": table_id,
"version_ts": version_ts, "version_ts": version_ts,
"created_at": created_at,
"action_result_id": action_result_id, "action_result_id": action_result_id,
"snippet_id": snippet_id, "snippet_id": snippet_id,
"rag_text": rag_text, "rag_text": rag_text,
@ -557,6 +562,7 @@ def _upsert_rag_snippet_rows(engine: Engine, rows: Sequence[Dict[str, Any]]) ->
workspace_id, workspace_id,
table_id, table_id,
version_ts, version_ts,
created_at,
action_result_id, action_result_id,
snippet_id, snippet_id,
rag_text, rag_text,
@ -567,6 +573,7 @@ def _upsert_rag_snippet_rows(engine: Engine, rows: Sequence[Dict[str, Any]]) ->
:workspace_id, :workspace_id,
:table_id, :table_id,
:version_ts, :version_ts,
:created_at,
:action_result_id, :action_result_id,
:snippet_id, :snippet_id,
:rag_text, :rag_text,

View File

@ -7,9 +7,18 @@ CREATE TABLE `rag_snippet` (
`snippet_id` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '原始 snippet id', `snippet_id` varchar(255) COLLATE utf8mb4_bin NOT NULL COMMENT '原始 snippet id',
`rag_text` text COLLATE utf8mb4_bin NOT NULL COMMENT '用于向量化的拼接文本', `rag_text` text COLLATE utf8mb4_bin NOT NULL COMMENT '用于向量化的拼接文本',
`merged_json` json NOT NULL COMMENT '合并后的 snippet 对象', `merged_json` json NOT NULL COMMENT '合并后的 snippet 对象',
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '写入时间,用于分区',
PRIMARY KEY (`rag_item_id`), `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`rag_item_id`,`created_at`),
KEY `idx_action_result` (`action_result_id`), KEY `idx_action_result` (`action_result_id`),
KEY `idx_workspace` (`workspace_id`), KEY `idx_workspace` (`workspace_id`),
KEY `idx_table_version` (`table_id`,`version_ts`) KEY `idx_table_version` (`table_id`,`version_ts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='RAG snippet 索引缓存'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE COLUMNS (`created_at`) (
PARTITION p202401 VALUES LESS THAN ('2024-02-01'),
PARTITION p202402 VALUES LESS THAN ('2024-03-01'),
PARTITION p202403 VALUES LESS THAN ('2024-04-01'),
PARTITION p202404 VALUES LESS THAN ('2024-05-01'),
PARTITION p202405 VALUES LESS THAN ('2024-06-01'),
PARTITION p_future VALUES LESS THAN (MAXVALUE)
) COMMENT='RAG snippet 索引缓存';

View File

@ -38,6 +38,7 @@ def _setup_sqlite_engine():
workspace_id INTEGER, workspace_id INTEGER,
table_id INTEGER, table_id INTEGER,
version_ts INTEGER, version_ts INTEGER,
created_at TEXT,
snippet_id TEXT, snippet_id TEXT,
rag_text TEXT, rag_text TEXT,
merged_json TEXT, merged_json TEXT,