数据库设计
本节提供了用于存储聊天历史记录的 PostgreSQL 数据库表的设计,包括表结构、字段说明及关系定义。
表设计
表结构
perplexica_chat_session 表
存储所有的聊天记录的基本信息。
drop table if exists perplexica_chat_session;
CREATE TABLE perplexica_chat_session (
id bigint PRIMARY KEY, -- 聊天的唯一标识符
user_id bigint,
title varchar NOT NULL, -- 聊天标题
type varchar,
chat_type int,
org varchar,
focus_mode varchar,
files jsonb,
metadata jsonb,
"created_at" "timestamptz" DEFAULT now(),
"remark" VARCHAR(256),
"creator" VARCHAR(64) DEFAULT '',
"create_time" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" VARCHAR(64) DEFAULT '',
"update_time" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted" SMALLINT DEFAULT 0,
"tenant_id" BIGINT NOT NULL DEFAULT 0
);
perplexica_chat_message 表
存储每个聊天中的消息内容及相关信息。
drop table if exists perplexica_chat_message;
CREATE TABLE perplexica_chat_message (
id bigint PRIMARY KEY,
chat_id bigint,
role VARCHAR(20) NOT NULL, -- 消息角色,如 user 或 assistant
content TEXT NOT NULL, -- 消息内容
rewrited text,
sources jsonb,
metadata JSONB,
"created_at" "timestamptz" DEFAULT now(),
"remark" VARCHAR(256),
"creator" VARCHAR(64) DEFAULT '',
"create_time" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" VARCHAR(64) DEFAULT '',
"update_time" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
"deleted" SMALLINT DEFAULT 0,
"tenant_id" BIGINT NOT NULL DEFAULT 0
);
files 表
复用 tio_boot_admin_uplaod_file
ref
https://idoubi.cc/posts/ai-search-engine/