diff --git a/migrations/282_document_chunks_hier_columns.sql b/migrations/282_document_chunks_hier_columns.sql new file mode 100644 index 0000000..19fa8c8 --- /dev/null +++ b/migrations/282_document_chunks_hier_columns.sql @@ -0,0 +1,14 @@ +-- PR-DocSrv-Hierarchical-Decomposition-1 (c1: schema) +-- 계층 분해 트리 컬럼 (단일 statement = runner single-statement 제약 OK, 다중 ADD COLUMN action). +-- parent_id : 트리 부모. DB FK 미설정(cascade 모호성 + single-statement 회피). 무결성은 builder(G2)+replace(G5) 검증 쿼리로 강제. +-- level : authoritative depth (0=root/doc, 증가). +-- node_type : nullable hint(chapter/section/clause...). retrieval/replace 활성 조건에 절대 미사용. +-- is_leaf : authoritative leaf 마커 (replace predicate 가 이것만 신뢰). +-- in_corpus : 검색 코퍼스 편입 여부. 기본 true → 기존 legacy 행은 검색 유지. 신규 hier 행은 false 로 적재. +-- plan: ~/.claude/plans/hierarchical-decomposition-tiered-nesting-marmot.md +ALTER TABLE document_chunks + ADD COLUMN IF NOT EXISTS parent_id bigint NULL, + ADD COLUMN IF NOT EXISTS level smallint NULL, + ADD COLUMN IF NOT EXISTS node_type text NULL, + ADD COLUMN IF NOT EXISTS is_leaf boolean NOT NULL DEFAULT false, + ADD COLUMN IF NOT EXISTS in_corpus boolean NOT NULL DEFAULT true; diff --git a/migrations/283_corpus_chunks_view.sql b/migrations/283_corpus_chunks_view.sql new file mode 100644 index 0000000..4f5705d --- /dev/null +++ b/migrations/283_corpus_chunks_view.sql @@ -0,0 +1,7 @@ +-- PR-DocSrv-Hierarchical-Decomposition-1 (c1: corpus choke point) +-- 검색 코퍼스 단일 진입점 뷰. 모든 retrieval(vector/keyword/hybrid/RAG/rerank candidate)은 +-- document_chunks 직접 접근 금지, 이 뷰만 본다(c2 rewire). in_corpus=false(비활성 hier leaf 등) 자동 제외. +-- 관리/디버그/문서상세 쿼리는 예외(document_chunks 직접 가능). +-- SELECT *: 현재 컬럼 동결 — 향후 document_chunks 컬럼 추가 시 본 뷰 CREATE OR REPLACE 재생성 필요. +CREATE OR REPLACE VIEW corpus_chunks AS + SELECT * FROM document_chunks WHERE in_corpus = true;