- KB RAG 전체 파이프라인: 업로드, 파싱(xlsx/pdf/docx/text), 임베딩, Qdrant 인덱싱 - KB 관리 UI(14번 탭): 로그인, 문서 목록, 업로드, 삭제, 재인덱스 - OllamaController: 한글 시스템 프롬프트, plant_context.md 외부 파일화, SSE tool_start/tool_result 이벤트 - 프론트: 툴 실행 카드, KB 인용 링크, 표 자동 렌더, 추천 질문 칩 - nl2sql_worker: history_table.recorded_at 사용, tag_metadata 응답 개선 - DB: KB 테이블 5개 DDL + 시드, pgcrypto 확장
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""docx 청킹 — 헤딩 경로 별 청크."""
|
|
from __future__ import annotations
|
|
|
|
|
|
def parse(path: str) -> list[dict]:
|
|
from docx import Document
|
|
|
|
doc = Document(path)
|
|
chunks: list[dict] = []
|
|
|
|
cur_path: list[str] = []
|
|
buf: list[str] = []
|
|
|
|
def flush():
|
|
if buf:
|
|
heading = " / ".join(cur_path) if cur_path else "preface"
|
|
chunks.append({
|
|
"text": "\n".join(buf).strip(),
|
|
"chunk_kind": "heading",
|
|
"locator": f"heading={heading}",
|
|
})
|
|
|
|
for p in doc.paragraphs:
|
|
text = (p.text or "").strip()
|
|
if not text:
|
|
continue
|
|
|
|
style_name = (p.style.name or "").lower() if p.style else ""
|
|
if style_name.startswith("heading"):
|
|
flush()
|
|
buf = []
|
|
try:
|
|
level = int(style_name.split()[-1])
|
|
except (ValueError, IndexError):
|
|
level = 1
|
|
cur_path = cur_path[: max(0, level - 1)] + [text]
|
|
else:
|
|
buf.append(text)
|
|
|
|
flush()
|
|
return chunks
|