Chunk
A semantically coherent slice of a document, sized to fit an embedding model's context window (sizes are set by chunking parameters). result.chunks is a list of these, ordered as they appear in the document.
result = docslicer.parse_document("report.pdf")
for chunk in result.chunks:
print(chunk.text)
print(chunk.page_number, chunk.heading)Fields
| Field | Type | Description |
|---|---|---|
id | str | Unique identifier (uuid) for this chunk within the result. |
chunk_index | int | Zero-based position of this chunk in the document. |
text | str | The chunk text, including any serialised table content. |
char_count | int | Character count of text. |
token_count | int | Token count. Exact when exact_tokens=True was passed; otherwise a chars / 4 estimate. |
page_number | int | 1-based physical page number where the chunk starts. |
page_label | str | None | Printed page label where the chunk starts, e.g. "iv", "A-6". Differs from page_number when documents use Roman numerals, lettered appendices, or custom page numbering. None when no label was detected. |
section | str | Document region this chunk belongs to (body, front_matter, an appendix, …). See Sections for the full list. |
heading | str | None | Text of the active heading at the point this chunk was created — the nearest heading above the chunk in document order. None for content before the first heading. |
path | list[str] | Full heading path from the document root to the active heading, e.g. ["Part II", "Item 1A", "Risk Factors"]. Empty list when no heading context is available. |
parent_chunk_id | str | None | ID of the parent chunk when hierarchical chunking produced nested chunks. None for top-level chunks. |
bbox | BBox | None | Bounding box of the chunk on the page. Populated for PDF and for HTML rendered via Playwright; None for DOCX, PPTX, and HTML parsed without Playwright. |
link_url | list[str] | Unique URLs found within this chunk's text. Empty list when none were detected. |
table_ids | list[str] | IDs of tables whose content appears in this chunk. Use these to look up the full Table object from result.tables. |
chart_ids | list[str] | IDs of charts whose content appears in this chunk. Use these to look up the full Chart object from result.charts. DOCX and PPTX only — always empty for PDF and HTML. |
extra | dict | Additional pipeline fields requested via extra_fields on the parse call. Empty dict by default. |
Examples
Filter by section
chunk.section names the document region the chunk came from. Keep body content only:
body_chunks = [c for c in result.chunks if c.section == "body"]See Sections for the full list of values and how they're detected.
Access table content
tables_by_id = {t.id: t for t in result.tables}
for chunk in result.chunks:
if chunk.table_ids:
table = tables_by_id[chunk.table_ids[0]]
print(table.markdown)Use extra fields
result = docslicer.parse_document("report.pdf", extra_fields=["is_bold", "font_size"])
for chunk in result.chunks:
print(chunk.extra["font_size"], chunk.text[:80])Methods
to_dict()
Serialize the chunk to a plain dict. All fields are included.
d = chunk.to_dict()Chunk.from_dict(d)
Reconstruct a Chunk from a dict produced by to_dict().
chunk = Chunk.from_dict(d)