Files
ExperionCrawler/mcp-server/parsers/pdf_parser.py
windpacer 908bfe151f feat: Knowledge Base RAG 시스템 + 채팅 LLM 개선 (Phase 0~5 완료)
- 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 확장
2026-05-13 20:22:27 +09:00

35 lines
1.1 KiB
Python

"""pdf 청킹 — pdfplumber로 페이지/표 추출, 헤딩 분리 실패 시 페이지 단위 fallback."""
from __future__ import annotations
def parse(path: str) -> list[dict]:
import pdfplumber
chunks: list[dict] = []
with pdfplumber.open(path) as pdf:
for pno, page in enumerate(pdf.pages, start=1):
txt = (page.extract_text() or "").strip()
if txt:
chunks.append({
"text": txt[:5000],
"chunk_kind": "page",
"locator": f"page={pno}",
})
try:
tables = page.extract_tables() or []
except Exception:
tables = []
for ti, table in enumerate(tables, start=1):
rows = [[(c or "").strip() for c in row] for row in table if row]
if not rows:
continue
md = "\n".join(" | ".join(r) for r in rows[:200])
chunks.append({
"text": md,
"chunk_kind": "table",
"locator": f"page={pno}; table={ti}",
})
return chunks