Skip to content

ai-search 数据库文档 ​

本节提供了用于存储聊天历史记录的 PostgreSQL 数据库表的设计,包括表结构、字段说明及关系定义。

表设计 ​

表结构 ​

max_search_chat_session 表 ​

存储所有的聊天记录的基本信息。

sql
drop table if exists max_search_chat_session;
CREATE TABLE max_search_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
);

max_search_chat_message 表 ​

存储每个聊天中的消息内容及相关信息。

sql
drop table if exists max_search_chat_message;
CREATE TABLE max_search_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 https://www.tio-boot.com/zh/33*文件存储/01.html

ref ​

https://idoubi.cc/posts/ai-search-engine/

MIT Licensed