Files
hyungi_document_server/migrations/286_chunk_section_analysis.sql
hyungi cfadaaffd9 feat(search): hier section per-leaf analysis scaffold (Section-Summary-1 c1)
chunk_section_analysis 테이블(migration 286) + ORM model + pilot script.
document_chunks(retrieval-hot)와 분리된 절-레벨 분석 축. domain 상속,
section_type 절-전용 역할 enum, status로 skip 박제, source_content_hash로 stale 탐지.
script-only(scripts mount, rebuild 불필요). LLM 0 dry-run 검증 = 5225 147 analyze + 17 skip.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 13:45:30 +00:00

38 lines
2.2 KiB
SQL

-- 286_chunk_section_analysis.sql
-- PR-DocSrv-Hier-Section-Summary-1: per-절(leaf) Mac mini 분석 결과 저장 테이블.
--
-- document_chunks(retrieval-hot: ivfflat + 2 gin + 6 btree)와 분리된 "절-레벨 분석 축".
-- hot 테이블 무손상 + builder/replace 재작성과 무관. 검색 코퍼스와 완전 분리(additive).
--
-- 컬럼 설계 (사용자 review 2026-05-24):
-- status : summarized | skipped_tiny | failed — skip 도 행으로 박제(미처리 vs 의도 skip 구분)
-- summary/section_type/domain/confidence : 분석 결과 (skip/failed 행은 NULL 가능)
-- section_type : 절-전용 역할 enum (느슨한 text, CHECK 미설정 — pilot 관찰 후 조임)
-- domain : doc-level taxonomy path(d.ai_domain) 상속 스냅샷
-- model/prompt_version: 모델·프롬프트 변경 추적
-- source_content_hash : 분석 시점 leaf chunk_content_hash 스냅샷 — 원문 변경(재분해) stale 탐지
--
-- chunk_id = FK CASCADE: chunk_section_analysis 는 document_chunks 에 종속된 분석 데이터.
-- parent_id(자기참조 트리, cascade 모호성 회피 위해 app-level)와 달리 여기는 단순 1:1 종속 → FK 정당.
--
-- UNIQUE(chunk_id, prompt_version): 같은 절을 같은 프롬프트로 1행. 원문 변경 시 동일 키 ON CONFLICT 갱신.
-- (chunk_id 단독 조회는 이 복합 UNIQUE 의 leftmost prefix btree 로 커버 → 별 인덱스 불필요)
--
-- ⚠ 단일 statement (migration runner exec_driver_sql). BEGIN/COMMIT/ROLLBACK 금지.
CREATE TABLE IF NOT EXISTS chunk_section_analysis (
id BIGSERIAL PRIMARY KEY,
chunk_id BIGINT NOT NULL REFERENCES document_chunks(id) ON DELETE CASCADE,
status TEXT NOT NULL,
summary TEXT,
section_type TEXT,
domain TEXT,
confidence REAL,
model TEXT,
prompt_version TEXT NOT NULL,
source_content_hash TEXT,
error TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (chunk_id, prompt_version)
);