feat(search): hier decomposition schema + corpus_chunks view (Hier-Decomp-1 c1)

PR-DocSrv-Hierarchical-Decomposition-1 c1 (G1).
- migration 282: document_chunks ADD parent_id/level/node_type/is_leaf/in_corpus
  (단일 statement ALTER, additive, IF NOT EXISTS). legacy 행 = in_corpus=true/is_leaf=false 기본값.
- migration 283: corpus_chunks 뷰 (WHERE in_corpus=true) = 검색 코퍼스 단일 choke point.
  c2 에서 retrieval 을 이 뷰로 rewire. node_type 은 hint, replace 는 is_leaf 사용.

검증: schema_migrations 282/283, 30952 행 in_corpus=true 보존, corpus_chunks 30952,
/health 200, restarts=0. dry-run(BEGIN/ROLLBACK) 선검증 후 적용.

plan: hierarchical-decomposition-tiered-nesting-marmot.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hyungi
2026-05-24 12:47:41 +00:00
parent 0854c72c70
commit 7971e69e3e
2 changed files with 21 additions and 0 deletions
@@ -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;
+7
View File
@@ -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;