Files
AIclinicalresearch/backend/prisma/migrations/manual/ekb_create_indexes_mvp.sql

35 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- ============================================================
-- EKB Schema MVP 索引创建脚本
-- 执行时机prisma db push 之后手动执行
-- 说明MVP 阶段只创建 HNSW 向量索引pg_bigm 索引在 Phase 2 创建
-- ============================================================
-- 1. 确保 pgvector 扩展已启用
CREATE EXTENSION IF NOT EXISTS vector;
-- 2. HNSW 向量索引(语义检索核心)
-- 参数说明m=16 每层最大连接数ef_construction=64 构建时搜索范围
CREATE INDEX IF NOT EXISTS idx_ekb_chunk_embedding
ON "ekb_schema"."ekb_chunk"
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
-- 3. JSONB GIN 索引(可选,提升查询性能)
CREATE INDEX IF NOT EXISTS idx_ekb_doc_metadata_gin
ON "ekb_schema"."ekb_document"
USING gin (metadata jsonb_path_ops);
CREATE INDEX IF NOT EXISTS idx_ekb_doc_structured_gin
ON "ekb_schema"."ekb_document"
USING gin (structured_data jsonb_path_ops);
-- 4. 标签数组索引
CREATE INDEX IF NOT EXISTS idx_ekb_doc_tags_gin
ON "ekb_schema"."ekb_document"
USING gin (tags);