> ## Documentation Index
> Fetch the complete documentation index at: https://ladygraph.io.vn/llms.txt
> Use this file to discover all available pages before exploring further.

# chunking

> Cắt văn bản dài, cấu trúc lỏng lẻo thành các đoạn.

Cắt một văn bản dài, cấu trúc lỏng lẻo thành các đoạn biết đường dẫn phần của mình (xem `ChunkingConfig` để biết các thiết lập).

## `chunking.config`

Phần `chunking:` của ladygraph.yaml: cách một văn bản dài, cấu trúc lỏng lẻo (một tài liệu OCR, một tệp PDF đã chuyển đổi) được cắt thành các đoạn.

#### `ChunkingConfig`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `ranks` | `list[str]` | factory |
| `label_rank` | `bool` | `True` |
| `max_heading_chars` | `int` | `160` |
| `long_heading_ranks` | `list[int]` | `[]` |
| `formula_ranks` | `list[int]` | `[]` |
| `glue` | `str \| None` | `None` |
| `glued_bullets` | `str \| None` | `None` |
| `body_starts_at_rank` | `int \| None` | `None` |
| `appendix_rank` | `int \| None` | `0` |
| `end_pattern` | `str \| None` | `None` |
| `head_lines` | `int` | `0` |
| `stamp_patterns` | `list[str]` | `[]` |
| `replacements` | `dict[str, str]` | `{'&lt;': '<', '&gt;': '>', '&amp;': '&'}` |
| `min_letters` | `int` | `4` |
| `table_group_chars` | `int` | `600` |
| `repair_tables` | `bool` | `True` |
| `damaged_table` | `str` | `'(^\|\\n)(col\\d+\|\\d+(\\.\\d+)?): '` |
| `numeric_columns` | `str \| None` | `None` |
| `repairs` | `list[Repair]` | `[]` |
| `rejoin_broken_sentences` | `bool` | `True` |

#### `Repair`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `pattern` | `str` | required |
| `replace` | `str` | required |

#### `load_chunking_config`

```python theme={null}
load_chunking_config(path: pathlib.Path | str) -> ChunkingConfig | None
```

Phần `chunking:` của một ladygraph.yaml, hoặc None khi tệp không có.

## `chunking.flattener`

Từ một văn bản dài thành các đoạn: phân tích, làm sạch, chia khúc, kiểm tra. `chunk_document` là hàm thuần; `StructuredMarkdownFlattener` cắm nó vào một nguồn markdown.

#### `ChunkOut`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `id` | `str` | required |
| `kind` | `str` | required |
| `path` | `str` | required |
| `section_type` | `str` | required |
| `text` | `str` | required |
| `translate` | `bool` | required |
| `failed` | `list[str]` | factory |
| `maybe_missed_heading` | `list[str]` | factory |
| `repaired` | `bool` | `False` |

#### `chunk_document`

```python theme={null}
chunk_document(doc: str, cfg: ChunkingConfig, embedder=None) -> tuple[list[ChunkOut], dict[str, int]]
```

(các khúc theo thứ tự tài liệu, các bộ đếm).

## `chunking.quality`

Các kiểm tra chất lượng khúc. Chúng đánh dấu một khúc để xem xét; không bao giờ cắt hay thay đổi một khúc.

#### `balanced`

```python theme={null}
balanced(text: str) -> bool
```

#### `failed`

```python theme={null}
failed(kind: str, text: str) -> list[str]
```

Các kiểm tra mà một khúc không đạt, trong số "start", "end", "brackets".

#### `z_dips`

```python theme={null}
z_dips(vectors, sizes: Sequence[int], threshold: float = -1.5) -> list[list[int]]
```

`vectors`: các vector độ dài đơn vị của mọi khối văn bản, theo thứ tự; `sizes`: số khối trong mỗi khúc.

## `chunking.structure`

Cấu trúc: một ngăn xếp tiêu đề dựa trên cấp bậc biến một văn bản dài thành các khúc, mỗi khúc biết đường dẫn phần của mình.

#### `Chunk`

| Trường | Kiểu | Mặc định |
| - | - | - |
| `kind` | `str` | required |
| `path` | `str` | required |
| `section_type` | `str` | required |
| `blocks` | `list` | factory |
| `stamps` | `int` | `0` |

#### `build`

```python theme={null}
build(blocks: list[tuple[str, object, int, 'int | None']], cfg: ChunkingConfig, stats: dict[str, int]) -> list[Chunk]
```

#### `clean`

```python theme={null}
clean(text: str, cfg: ChunkingConfig, stamps: set[str]) -> tuple[str, int]
```

#### `parse`

```python theme={null}
parse(doc: str, cfg: ChunkingConfig, stamps: set[str]) -> list[tuple[str, object, int, 'int | None']]
```

#### `stamp_words`

```python theme={null}
stamp_words(doc: str, cfg: ChunkingConfig) -> set[str]
```

Các từ ASCII và ngày tháng trong các dòng đầu trang: tên người ký, mã, thời gian.

## `chunking.tables`

Các bảng dưới dạng văn bản mà một mô hình đọc được: mỗi ô giữ tên cột của nó, và hư hại do ngắt trang để lại được sửa.

#### `TableRepairer`

Giữ các tiêu đề tốt mà nó đã thấy, theo thứ tự tài liệu.

Khởi tạo bằng `TableRepairer(cfg: ChunkingConfig)`.

| Phương thức | Làm gì |
| - | - |
| `parts(self, blocks: list[list[str]]) -> tuple[list[str], bool]` | — |

#### `fix_row`

```python theme={null}
fix_row(row: list[str], width: int) -> list[str]
```

#### `good`

```python theme={null}
good(header: list[str]) -> bool
```

Một tiêu đề có tên: ô đầu tiên của nó không rỗng hoặc không là một con số trần, và tối đa một ô rỗng.

#### `group`

```python theme={null}
group(lines: list[str], limit: int) -> list[list[int]]
```

#### `names`

```python theme={null}
names(header: list[str]) -> list[str]
```

#### `plain_rows`

```python theme={null}
plain_rows(header: list[str], rows: list[list[str]]) -> list[str]
```

#### `serialise`

```python theme={null}
serialise(header: list[str], rows: list[list[str]], width: int) -> str
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.