Skip to content

Reference

Warnings

Every warning code: when it happens and what to do about it.

Warnings describe problems that didn’t stop chunking. They’re returned in the result’s warnings array. Doc-chunk never logs them.

interface ChunkWarning {
code: ChunkWarningCode;
message: string;
chunkIndex?: number;
}

chunkIndex is set when the warning is about one chunk, and is that chunk’s index.

Code Chunks chunkIndex When
EMPTY_DOCUMENT None No The document has no text.
NO_TEXT_LAYER None No A PDF has a page without a text layer, or almost no text.
OVERSIZED_BLOCK Normal Yes A row, item, line, or word longer than size was cut.
LARGE_CHUNK Normal Yes A strategy with no size limit made a chunk of more than 8,000 characters.

The document is empty, or contains only whitespace. The result has no chunks.

Message: The document has no text to chunk.

What to do: check the source. A Word or PowerPoint file that contains only images also converts to Markdown with little or no text.

A PDF has at least one page without a text layer, because it’s scanned or is only an image, or a page mostly covered by an image, or fewer than 100 characters of text in total. The result has no chunks, even if other pages have text. EMPTY_DOCUMENT is not added as well. Images on pages that also have text don’t cause this warning: they’re ignored.

Messages:

This PDF appears to be scanned; OCR is not supported.
This PDF appears to be scanned; OCR is not supported. Pages without a text layer: 3, 4 of 12.

The second form lists the pages, when the converter reports them.

What to do: Doc-chunk doesn’t do OCR. Run the PDF through an OCR tool, then chunk the text it produces.

A single table row, list item, code line, or word was longer than size, so it was cut at the size limit instead of at a boundary. The chunk at chunkIndex contains one of the pieces.

Message: Chunk 4 is a hard cut of a row, item, line, or word longer than size.

What to do: usually nothing. This happens with long URLs, base64 data, or minified code. If the pieces are too small to be useful, raise size.

A strategy without a size limit made a chunk of more than 8,000 characters. This applies to heading, paragraph, sentence, and sentence-window without size, and to hierarchical with by: "heading". Strategies with a size limit never add it.

Message: Chunk 2 has 12480 characters, more than 8000. Set "size" to split it.

What to do: set size to split large sections, paragraphs, or blocks. Most embedding models accept far less than 8,000 characters.

import { chunkDocument } from "docchunk";
const { chunks, warnings } = await chunkDocument({ path: "report.pdf" });
for (const warning of warnings) {
console.warn(`${warning.code}: ${warning.message}`);
}