Skip to main content

module  pixeltable.functions.document

Pixeltable UDFs for DocumentType.

iterator  document_splitter()

Signature
Iterator over chunks of a document. The document is chunked according to the specified separators. Chunked text will be cleaned with ftfy.fix_text to fix up common problems with unicode sequences. Separators by document format: A separator marked “No effect” is ignored for that format without an error. For example, with separators='page', an HTML document in the same table produces a single chunk. | Separator | HTML, Markdown, Office | PDF | TXT | |---|---|---|noindex: true ---| | 'heading' | Splits at headings | No effect | No effect | | 'paragraph' | Splits at headings and paragraphs | Not supported: the whole insert() fails | No effect | | 'page' | No effect | Splits at pages | No effect | | 'sentence' | Splits at headings, paragraphs and sentences | Splits into sentences | Splits into sentences | | 'token_limit', 'char_limit' | Splits long chunks | Splits long chunks | Splits long chunks | Office documents are PPTX, DOCX and XLSX files. 'token_limit' and 'char_limit' split each chunk that is longer than limit tokens or characters. Outputs: One row per chunk, with the following columns, depending on the specified elements and metadata:
  • text (pxt.String): The text of the chunk. Present if 'text' is specified in elements.
  • image (pxt.Image): The image extracted from the chunk. Present if 'image' is specified in elements.
  • title (pxt.String | None): The content of the <title> element of an HTML document; '' for other formats and for HTML documents without one. Present if 'title' is specified in metadata.
  • heading (Heading | None): The heading hierarchy at the start of the chunk, with the text of each currently open heading level under the keys h1 through h6 (HTML, Markdown and Office documents only). Present if 'heading' is specified in metadata.
  • page (pxt.Int | None): The 0-based page number of the chunk. Set only for PDF documents, and only if separators includes 'page'; otherwise None. Present if 'page' is specified in metadata.
Parameters:
  • separators (pxt.String): separators to use to chunk the document. Options are: 'heading', 'paragraph', 'sentence', 'token_limit', 'char_limit', 'page'. This may be a comma-separated string, e.g., 'heading,token_limit'. Which separators apply depends on the document format; see the table above. If separators includes 'paragraph', processing a PDF document raises an error that fails the whole insert(), or create_view() if the base table already contains a PDF document.
  • elements (pxt.Json[(String): list of elements to extract from the document. Options are: 'text', 'image'. Defaults to ['text'] if not specified. The 'image' element is only supported for PDF documents, and requires separators='page' with no other separators. Any other document format fails with an Expected non-None value error: the whole insert() fails, or create_view() if the base table already contains such a document.
  • limit (Any): the maximum number of tokens or characters in each chunk, if 'token_limit' or 'char_limit' is specified.
  • overlap (Any): the number of tokens or characters shared by consecutive chunks. Can only be specified together with limit, and must be smaller than it. Defaults to 0.
  • metadata (Any): additional metadata fields to include in the output. Options are: 'title' (HTML), 'heading' (HTML, Markdown and Office), 'page' (PDF). The input may be a comma-separated string, e.g., 'title,heading'.
  • skip_tags (Any): list of HTML tags to skip when processing HTML documents.
  • spacy_model (Any): Name of the spaCy model to use for sentence segmentation. This parameter is ignored unless the 'sentence' separator is specified.
  • tiktoken_encoding (Any): Name of the tiktoken encoding to use when counting tokens. This parameter is ignored unless the 'token_limit' separator is specified.
  • tiktoken_target_model (Any): Name of the target model to use when counting tokens with tiktoken. If specified, this parameter overrides tiktoken_encoding. This parameter is ignored unless the 'token_limit' separator is specified.
  • image_dpi (Any): Resolution at which PDF pages are rendered when elements includes 'image'. Must be a positive integer. Defaults to 72, which renders one pixel per PDF point.
Examples: All these examples assume an existing table tbl with a column doc of type pxt.Document. Create a view that splits all documents into chunks of up to 300 tokens:
Create a view that splits all documents along sentence boundaries, including title and heading metadata:
Last modified on December 4, 2026