module pixeltable.functions.document
Pixeltable UDFs forDocumentType.
iterator document_splitter()
Signature
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 inelements.image(pxt.Image): The image extracted from the chunk. Present if'image'is specified inelements.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 inmetadata.heading(Heading | None): The heading hierarchy at the start of the chunk, with the text of each currently open heading level under the keysh1throughh6(HTML, Markdown and Office documents only). Present if'heading'is specified inmetadata.page(pxt.Int | None): The 0-based page number of the chunk. Set only for PDF documents, and only ifseparatorsincludes'page'; otherwiseNone. Present if'page'is specified inmetadata.
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. Ifseparatorsincludes'paragraph', processing a PDF document raises an error that fails the wholeinsert(), orcreate_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 requiresseparators='page'with no other separators. Any other document format fails with anExpected non-None valueerror: the wholeinsert()fails, orcreate_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 withlimit, 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 overridestiktoken_encoding. This parameter is ignored unless the'token_limit'separator is specified.image_dpi(Any): Resolution at which PDF pages are rendered whenelementsincludes'image'. Must be a positive integer. Defaults to 72, which renders one pixel per PDF point.
tbl with a column doc of type pxt.Document.
Create a view that splits all documents into chunks of up to 300 tokens: