GeezerVison is showing github.com — feat: v0.5.0 chunks 도구에 include_furniture 파라미터 추가 · DanMeon/rhwp-python@44b558b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/roadmap/v0.5.0/mcp.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -54,7 +54,7 @@ v0.5.0 시점이 sweet spot 인 이유: | 54 | 54 | | `iter_blocks(path, kind, scope, limit)` | `path: str`, `kind: Literal["paragraph", "table", "picture", ...]`, `scope: Literal["body", "furniture", "all"]`, `limit: int \| None` | `list[dict]` | core | | 55 | 55 | | `to_markdown(path)` | `path: str` | `str` | **v0.4.0 view 의존** | | 56 | 56 | | `to_html(path, include_css: bool)` | `path: str`, `include_css: bool = False` | `str` | **v0.4.0 view 의존** | | 57 | | -| `chunks(path, mode, size, overlap)` | `path: str`, `mode: Literal["single", "paragraph", "ir-blocks"]`, `size: int = 500`, `overlap: int = 50` | `list[{page_content, metadata}]` | langchain-text-splitters | | | 57 | +| `chunks(path, mode, size, overlap, include_furniture)` | `path: str`, `mode: Literal["single", "paragraph", "ir-blocks"]`, `size: int = 500`, `overlap: int = 50`, `include_furniture: bool = False` (`mode="ir-blocks"` 에서만 의미 — page_headers / page_footers / footnotes / endnotes 도 chunked Document 로 yield, metadata `scope="furniture"`. 다른 mode 에서는 무시) | `list[{page_content, metadata}]` | langchain-text-splitters | | 58 | 58 |
| 59 | 59 | **도구 명명 규칙**: | 60 | 60 |
| |
Collapse file Copy file name to clipboardExpand all lines: docs/traces/coverage.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -535,6 +535,8 @@ v0.4.0+ 신규 spec 의 인수조건 ↔ 테스트 매핑. 기존 v0.1.0 ~ v0.3. | 535 | 535 | | v0.4.0/view-renderer | AC-9 | `tests/test_view_html.py::test_to_html_include_css_real_fixture_well_formed` | | 536 | 536 | | v0.4.0/view-renderer | AC-9 | `tests/test_view_html.py::test_to_html_include_css_true_has_exactly_one_style_in_head` | | 537 | 537 | | v0.5.0/mcp | — | `tests/test_mcp_server.py::TestChunks::test_default_paragraph_mode` | | | 538 | +| v0.5.0/mcp | — | `tests/test_mcp_server.py::TestChunks::test_include_furniture_appends_furniture_chunks` | | | 539 | +| v0.5.0/mcp | — | `tests/test_mcp_server.py::TestChunks::test_include_furniture_ignored_outside_ir_blocks` | | 538 | 540 | | v0.5.0/mcp | — | `tests/test_mcp_server.py::TestChunks::test_missing_extras_does_not_break_other_tools` | | 539 | 541 | | v0.5.0/mcp | — | `tests/test_mcp_server.py::TestChunks::test_missing_extras_raises_tool_error` | | 540 | 542 | | v0.5.0/mcp | — | `tests/test_mcp_server.py::TestChunks::test_modes_all_supported` | | |
Collapse file Copy file name to clipboardExpand all lines: python/rhwp/mcp/tools.py +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,6 +150,7 @@ def chunks( | 150 | 150 | mode: ChunksMode = "paragraph", | 151 | 151 | size: int = 500, | 152 | 152 | overlap: int = 50, | | 153 | + include_furniture: bool = False, | 153 | 154 | ) -> list[dict[str, Any]]: | 154 | 155 | """HWP/HWPX 를 RAG 청크 리스트로 변환 (LangChain ``RecursiveCharacterTextSplitter``). | 155 | 156 |
| @@ -165,10 +166,15 @@ def chunks( | 165 | 166 |
| 166 | 167 | - ``"single"``: 전체 문서를 단일 Document | 167 | 168 | - ``"paragraph"``: 문단 텍스트별 Document (기본) | 168 | | - - ``"ir-blocks"``: IR Block 단위 (표 구조 보존 + Provenance metadata, | 169 | | - 본문만 — page_headers / footnotes / endnotes 제외) | | 169 | + - ``"ir-blocks"``: IR Block 단위 (표 구조 보존 + Provenance metadata) | 170 | 170 | size: ``RecursiveCharacterTextSplitter`` 의 ``chunk_size`` (문자 수). | 171 | 171 | overlap: 청크 간 오버랩 문자 수. | | 172 | + include_furniture: ``mode="ir-blocks"`` 에서만 의미. True 면 본문 청크 | | 173 | + 다음에 furniture (page_headers / page_footers / footnotes / endnotes) | | 174 | + 도 chunked Document 로 yield 하며, 각 chunk 의 ``metadata`` 에 | | 175 | + ``scope="furniture"`` 가 부여돼 RAG 가 body/furniture 를 분리 색인. | | 176 | + 다른 mode 에서는 무시 (``HwpLoader`` 와 동일 의미). 기본 False — | | 177 | + RAG body 검색 오염 회피. | 172 | 178 |
| 173 | 179 | Returns: | 174 | 180 | ``[{"page_content": str, "metadata": dict}]`` — LangChain Document 의 | @@ -186,7 +192,7 @@ def chunks( | 186 | 192 | # transitive 로 끌어오므로 위 try/except 이 통과하면 같이 import 가능. | 187 | 193 | from rhwp.integrations.langchain import HwpLoader | 188 | 194 |
| 189 | | - loader = HwpLoader(path, mode=mode) | | 195 | + loader = HwpLoader(path, mode=mode, include_furniture=include_furniture) | 190 | 196 | docs = loader.load() | 191 | 197 | splitter = RecursiveCharacterTextSplitter(chunk_size=size, chunk_overlap=overlap) | 192 | 198 | split_docs = splitter.split_documents(docs) | |
Collapse file Copy file name to clipboardExpand all lines: tests/test_mcp_server.py +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -263,6 +263,36 @@ def test_size_overlap_pass_through(self, hwp_sample: Path) -> None: | 263 | 263 | # ^ 작은 청크 사이즈가 더 많은 청크를 생성 (또는 같음 — 짧은 문서 한계) | 264 | 264 | assert len(small) >= len(large) | 265 | 265 |
| | 266 | + def test_include_furniture_appends_furniture_chunks(self, hwp_sample: Path) -> None: | | 267 | + """``mode="ir-blocks"`` + ``include_furniture=True`` 가 furniture chunked Document 추가.""" | | 268 | + pytest.importorskip("langchain_text_splitters") | | 269 | + body_only = tools.chunks(str(hwp_sample), mode="ir-blocks", include_furniture=False) | | 270 | + with_furniture = tools.chunks(str(hwp_sample), mode="ir-blocks", include_furniture=True) | | 271 | + # ^ furniture 가 추가되므로 청크 수가 증가하거나 같음 (샘플에 furniture 가 없으면 같음) | | 272 | + assert len(with_furniture) >= len(body_only) | | 273 | + # ^ aift.hwp 샘플은 page_headers 를 보유 — | | 274 | + # 한 개 이상 추가 청크가 ``scope="furniture"`` 메타로 yield | | 275 | + furniture_chunks = [c for c in with_furniture if c["metadata"].get("scope") == "furniture"] | | 276 | + assert furniture_chunks, ( | | 277 | + "aift.hwp 는 page_headers 를 보유 — include_furniture=True 가 " | | 278 | + "'scope=furniture' 메타로 청크를 yield 해야 함" | | 279 | + ) | | 280 | + | | 281 | + def test_include_furniture_ignored_outside_ir_blocks(self, hwp_sample: Path) -> None: | | 282 | + """``mode="single"`` / ``"paragraph"`` 에서 ``include_furniture`` 는 silently 무시.""" | | 283 | + pytest.importorskip("langchain_text_splitters") | | 284 | + for mode in ("single", "paragraph"): | | 285 | + without = tools.chunks(str(hwp_sample), mode=mode) # type: ignore[arg-type] | | 286 | + with_flag = tools.chunks( | | 287 | + str(hwp_sample), | | 288 | + mode=mode, | | 289 | + include_furniture=True, # type: ignore[arg-type] | | 290 | + ) | | 291 | + # ^ ir-blocks 외 모드에서는 HwpLoader 가 include_furniture 를 무시 — 결과 동일 | | 292 | + assert len(without) == len(with_flag), ( | | 293 | + f"mode={mode!r} should ignore include_furniture (HwpLoader 동일 의미)" | | 294 | + ) | | 295 | + | 266 | 296 | @pytest.mark.spec("v0.5.0/mcp#AC-7") | 267 | 297 | def test_missing_extras_raises_tool_error( | 268 | 298 | self, hwp_sample: Path, monkeypatch: pytest.MonkeyPatch | |
|