Home

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

FieldTypeDescription
idstrUnique identifier (uuid) for this chunk within the result.
chunk_indexintZero-based position of this chunk in the document.
textstrThe chunk text, including any serialised table content.
char_countintCharacter count of text.
token_countintToken count. Exact when exact_tokens=True was passed; otherwise a chars / 4 estimate.
page_numberint1-based physical page number where the chunk starts.
page_labelstr | NonePrinted 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.
sectionstrDocument region this chunk belongs to (body, front_matter, an appendix, …). See Sections for the full list.
headingstr | NoneText 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.
pathlist[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_idstr | NoneID of the parent chunk when hierarchical chunking produced nested chunks. None for top-level chunks.
bboxBBox | NoneBounding 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_urllist[str]Unique URLs found within this chunk's text. Empty list when none were detected.
table_idslist[str]IDs of tables whose content appears in this chunk. Use these to look up the full Table object from result.tables.
chart_idslist[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.
extradictAdditional 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)