Files
Agent-System/deploy/postgres/kb_init.sql
T

35 lines
1.2 KiB
SQL

-- 共享知识库 (Shared Knowledge Base) 初始化脚本
-- pgvector 扩展及基础条目库
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE TABLE IF NOT EXISTS kb_documents (
id BIGSERIAL PRIMARY KEY,
title TEXT NOT NULL,
doc_no TEXT NOT NULL DEFAULT '',
category TEXT NOT NULL DEFAULT '',
content TEXT NOT NULL,
embedding vector(1024),
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_kb_doc_title ON kb_documents USING gin (title gin_trgm_ops);
CREATE INDEX IF NOT EXISTS idx_kb_doc_no ON kb_documents(doc_no);
CREATE INDEX IF NOT EXISTS idx_kb_category ON kb_documents(category);
-- 共享法规/知识切片表
CREATE TABLE IF NOT EXISTS kb_chunks (
id BIGSERIAL PRIMARY KEY,
document_id BIGINT REFERENCES kb_documents(id) ON DELETE CASCADE,
chunk_index INT NOT NULL DEFAULT 0,
chunk_text TEXT NOT NULL,
embedding vector(1024),
tokens_count INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_kb_chunk_doc ON kb_chunks(document_id);