-----------张斌2025-06-16 15:00:00--------------

--------------------pgsql创建rag_keyword表语句---------------------------
-- 关键词表（文档关键词+权重）
CREATE TABLE IF NOT EXISTS rag_keyword (
    -- 基础字段（完全对齐项目规范）
    id BIGINT PRIMARY KEY, -- 主键ID（非自增）
    tenant_id BIGINT NOT NULL DEFAULT 0, -- 租户ID int8
    creator VARCHAR(64) NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updater VARCHAR(64) NOT NULL,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    deleted_at timestamp(6),

    -- 业务字段
    dataset_id BIGINT NOT NULL, -- 数据集ID
    document_id BIGINT NOT NULL, -- 文件ID
    word VARCHAR(255) NOT NULL, -- 关键词
    weight SMALLINT NOT NULL DEFAULT 0 -- 权重
    );

-- 索引（按业务高频查询）
CREATE INDEX idx_keyword_tenant_id ON rag_keyword(tenant_id);
CREATE INDEX idx_keyword_dataset_id ON rag_keyword(dataset_id);
CREATE INDEX idx_keyword_document_id ON rag_keyword(document_id);
CREATE INDEX idx_keyword_word ON rag_keyword(word);
CREATE INDEX idx_keyword_deleted_at ON rag_keyword(deleted_at);

-- 表和字段注释
COMMENT ON TABLE rag_keyword IS 'RAG关键词表（文档关键词+权重）';
COMMENT ON COLUMN rag_keyword.id IS '主键ID（非自增）';
COMMENT ON COLUMN rag_keyword.tenant_id IS '租户ID';
COMMENT ON COLUMN rag_keyword.creator IS '创建人';
COMMENT ON COLUMN rag_keyword.created_at IS '创建时间';
COMMENT ON COLUMN rag_keyword.updater IS '更新人';
COMMENT ON COLUMN rag_keyword.updated_at IS '更新时间';
COMMENT ON COLUMN rag_keyword.deleted_at IS '删除时间（软删）';
COMMENT ON COLUMN rag_keyword.dataset_id IS '数据集ID';
COMMENT ON COLUMN rag_keyword.document_id IS '文档ID';
COMMENT ON COLUMN rag_keyword.word IS '关键词';
COMMENT ON COLUMN rag_keyword.weight IS '权重';

--------------------pgsql创建rag_keyword表语句---------------------------