fix(saas): industry template audit fixes + pgvector optional + relay timeout
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- Fix seed template tools to match actual runtime tool names (file_read/file_write/shell_exec/web_fetch) - Persist system_prompt/temperature/max_tokens via identity system in agentStore.createFromTemplate() - Fire-and-forget assignTemplate() in AgentOnboardingWizard - Fix saas-relay-client unused variable warning - Make pgvector extension optional in knowledge_base migration - Increase StreamBridge timeout from 30s to 90s for thinking models
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
-- Migration: Knowledge Base tables with pgvector support
|
||||
-- Migration: Knowledge Base tables with optional pgvector support
|
||||
-- 5 tables: knowledge_categories, knowledge_items, knowledge_chunks,
|
||||
-- knowledge_versions, knowledge_usage
|
||||
|
||||
-- Enable pgvector extension
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
--
|
||||
-- pgvector is optional: if the extension is not installed, the embedding
|
||||
-- column and HNSW index are skipped. All other tables work normally.
|
||||
|
||||
-- 行业分类树
|
||||
CREATE TABLE IF NOT EXISTS knowledge_categories (
|
||||
@@ -42,12 +42,12 @@ CREATE INDEX IF NOT EXISTS idx_ki_status_updated ON knowledge_items(status, upda
|
||||
CREATE INDEX IF NOT EXISTS idx_ki_keywords ON knowledge_items USING GIN(keywords);
|
||||
|
||||
-- 知识分块(RAG 检索核心)
|
||||
-- 基础表不含 embedding 列;若 pgvector 可用则后续通过 DO 块添加
|
||||
CREATE TABLE IF NOT EXISTS knowledge_chunks (
|
||||
id TEXT PRIMARY KEY,
|
||||
item_id TEXT NOT NULL REFERENCES knowledge_items(id) ON DELETE CASCADE,
|
||||
chunk_index INT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
embedding vector(1536),
|
||||
keywords TEXT[] DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
@@ -55,11 +55,25 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_kchunks_item_idx ON knowledge_chunks(item_
|
||||
CREATE INDEX IF NOT EXISTS idx_kchunks_item ON knowledge_chunks(item_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_kchunks_keywords ON knowledge_chunks USING GIN(keywords);
|
||||
|
||||
-- 向量相似度索引(HNSW,无需预填充数据)
|
||||
-- 仅在有数据后创建此索引可提升性能,这里预创建
|
||||
CREATE INDEX IF NOT EXISTS idx_kchunks_embedding ON knowledge_chunks
|
||||
USING hnsw (embedding vector_cosine_ops)
|
||||
WITH (m = 16, ef_construction = 128);
|
||||
-- 条件添加 embedding 列和 HNSW 索引(仅当 pgvector 可用时)
|
||||
DO $$ BEGIN
|
||||
PERFORM set_config('client_min_messages', 'warning', true);
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'knowledge_chunks' AND column_name = 'embedding'
|
||||
) THEN
|
||||
ALTER TABLE knowledge_chunks ADD COLUMN embedding vector(1536);
|
||||
END IF;
|
||||
IF NOT EXISTS (SELECT 1 FROM pg_indexes WHERE indexname = 'idx_kchunks_embedding') THEN
|
||||
CREATE INDEX idx_kchunks_embedding ON knowledge_chunks
|
||||
USING hnsw (embedding vector_cosine_ops)
|
||||
WITH (m = 16, ef_construction = 128);
|
||||
END IF;
|
||||
RAISE NOTICE 'pgvector enabled for knowledge base';
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
RAISE NOTICE 'pgvector not available, vector features disabled: %', SQLERRM;
|
||||
END $$;
|
||||
|
||||
-- 版本快照
|
||||
CREATE TABLE IF NOT EXISTS knowledge_versions (
|
||||
@@ -89,7 +103,6 @@ CREATE TABLE IF NOT EXISTS knowledge_usage (
|
||||
created_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_ku_item ON knowledge_usage(item_id) WHERE item_id IS NOT NULL;
|
||||
-- BRIN 索引:追加写入的时间序列数据比 B-tree 更高效
|
||||
CREATE INDEX IF NOT EXISTS idx_ku_created_brin ON knowledge_usage USING brin(created_at);
|
||||
|
||||
-- 权限种子数据(使用 jsonb 操作避免 REPLACE 脆弱性)
|
||||
|
||||
Reference in New Issue
Block a user