nex_docus/backend/scripts/migrate_document_vector_add...

20 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 迁移脚本:为 document_vector 表增加分块chunk支持
-- 背景RAG 由「整篇文档单向量」升级为「按分块向量化」,
-- 一个文件可对应多条 chunk 记录。
--
-- 用法(已有数据库升级):
-- mysql -u <user> -p <db_name> < migrate_document_vector_add_chunks.sql
--
-- 注意:升级后建议对所有项目执行一次「全量重建」向量化,
-- 以将旧的整篇文档向量替换为分块向量(旧记录 chunk_index 默认为 0
ALTER TABLE `document_vector`
ADD COLUMN `chunk_index` INT NOT NULL DEFAULT 0
COMMENT '分块序号0起同一文件可有多个分块' AFTER `file_path`,
ADD COLUMN `chunk_text` TEXT DEFAULT NULL
COMMENT '分块首段文本,作为点击引用时的定位锚点' AFTER `chunk_index`;
-- 新增按 (project_id, file_path, chunk_index) 的复合索引,加速按分块查询/删除
ALTER TABLE `document_vector`
ADD INDEX `idx_project_file_chunk` (`project_id`, `file_path`, `chunk_index`);