Chunk

  • New in v2.0

class Chunk

A finalized, retrieval-ready portion of a document, returned as an item in ChunkedDocument. Treat chunks returned by Document.to_chunks() as read-only. Mutating text or metadata after reading content_hash can leave that cached hash, and caches on the owning ChunkedDocument, out of date. To change chunk boundaries, use ChunkedDocument.reassemble_chunks(); keep application-specific data separately, keyed by the chunk id.

id

The chunk id, formatted as c{n}, where n is its position in this ChunkedDocument. Chunk ids are local to the result and may change when chunks are reassembled with different parameters.

text

The chunk’s Markdown text, rendered from its layout content.

tagged_content

Context-enriched text for embedding. It includes the chunk’s section path, page, and non-paragraph content types where available, followed by its Markdown text. This is separate from text and is included by default in ChunkedDocument.to_dicts() and ChunkedDocument.to_json().

metadata

A ChunkMetadata instance containing page, layout, structure, token-count, and provenance information for this chunk.

content_hash

A lazily computed SHA-256 hash of text after runs of whitespace have been collapsed to one space and leading and trailing whitespace has been removed. The hash is cached. It is stable across rendering-only whitespace changes, but changes when the normalized text changes.

This software is provided AS-IS with no warranty, either express or implied. This software is distributed under license and may not be copied, modified or distributed except as expressly authorized under the terms of that license. Refer to licensing information at artifex.com or contact Artifex Software Inc., 39 Mesa Street, Suite 108A, San Francisco CA 94129, United States for further information.