fix(chunk): _chunk_legal 영어 법령 sliding window fallback

영어/외국 법령(ai_domain Foreign_Law 등)은 '제N조' 패턴이 없어 split 결과가
1개 element만 나옴 → 서문 chunk(첫 1500자)만 생성되고 본문 대부분 손실.

발견: doc 3759 (Industrial Safety, 93KB 영어) → 1개 chunk만 생성.

수정: parts split 결과가 1개 이하면 _chunk_sliding fallback 호출.
한국어 법령(제N조 패턴 있음)은 기존 분할 로직 그대로 작동.

Phase 1.2-D smoke test에서 발견. 재인덱싱 전 fix 필수.
This commit is contained in:
Hyungi Ahn
2026-04-08 12:26:38 +09:00
parent f9af8dd355
commit 731d1396e8

View File

@@ -79,11 +79,20 @@ def _classify_chunk_strategy(doc: Document) -> str:
# ─── Chunking 전략 ───
def _chunk_legal(text: str) -> list[dict]:
"""법령: 제N조 단위로 분할 (상위 조문 컨텍스트 보존)"""
"""법령: 제N조 단위로 분할 (상위 조문 컨텍스트 보존).
영어/외국 법령(ai_domain Foreign_Law 등)은 "제N조" 패턴이 없어 split 결과가
1개 element만 나옴 → 서문 chunk 1개만 생성되고 본문 대부분이 손실되는 버그.
조문 패턴 미검출 시 sliding window fallback으로 처리.
"""
# "제 1 조", "제1조", "제 1 조(제목)" 등 매칭
pattern = re.compile(r"(제\s*\d+\s*조(?:의\s*\d+)?(?:\([^)]*\))?)")
parts = pattern.split(text)
# 조문 패턴 미검출 (영어/외국 법령 등) → sliding window fallback
if len(parts) <= 1:
return _chunk_sliding(text, DEFAULT_WINDOW_CHARS, DEFAULT_OVERLAP_CHARS, "section")
chunks = []
# parts[0] = 조 이전 서문, parts[1], parts[2] = (마커, 본문) pairs
if parts[0].strip() and len(parts[0]) >= MIN_CHUNK_CHARS: