Converter tool

Text Chunker for RAG

Break a PDF, Word, Markdown or text file into overlapping chunks for embedding, with heading paths, page ranges and estimated token counts, and save them as JSONL or CSV.

A new chunk starts at every # heading and records its heading path; inside a section, whole paragraphs are packed. PDF and Word text has no # headings, so it is chunked by paragraph and the paths stay empty. The overlap repeats the end of each chunk at the start of the next, as whole sentences where they fit, otherwise as whole words.

PDF text is read from the file's text layer with pdf.js and Word text with mammoth, both running in this tab; scanned pages without a text layer give no text, because there is no OCR. Nothing you load or paste is uploaded: until you download them, the text and the chunks exist only in this tab's memory, and they are gone when you reload or close the page.

Preview

Output Preview

Load a file or paste text, pick the split mode and size, then press Make chunks to see the size spread and the first 10 chunks here.

Text Chunker for RAG

Operator: Abdulla Al Fahad. How tools are built and checked

Retrieval-augmented generation answers a question from pieces of your documents: the question is compared with stored chunks, and only the closest few are pasted into the model's prompt. How a document is cut decides what can be found. A chunk that stops halfway through a sentence, or that glues the end of one topic to the start of another, matches questions badly and hands the model half an answer. This tool cuts a PDF, a Word file, a Markdown file or plain text into chunks below a size you choose, puts every cut between two words, and writes the chunks as JSONL or CSV with an id, an estimated token count and metadata for each one.

You can cut along Markdown headings, along paragraphs, along sentences, or into plain fixed-size windows, with an overlap that repeats the end of each chunk at the start of the next. Before anything is saved, the page shows how many chunks were made, a bar chart of their sizes against your limit and the first ten chunks with the repeated text shaded, so a setting that turns a handbook into four hundred 30-token scraps is caught before it reaches your vector store.

Key features

  • Reads PDF text layers, Word .docx bodies, Markdown and plain text, or text pasted into the box
  • Four split modes: Markdown headings then paragraphs, paragraphs, sentences, or fixed size
  • Limit in estimated tokens (default 500) or in characters, with an overlap (default 50 tokens)
  • Cuts only between words; Chinese, Japanese and Korean characters count as words of their own
  • Heading path for every chunk in Markdown mode, and the first and last page for PDF chunks
  • Overlap built from whole sentences where they fit, otherwise from whole words
  • Size chart with a separate bar for any chunk over the limit, and a preview of the first ten chunks
  • JSONL and CSV downloads with ids built from the file name, such as handbook-0001

Accepted files, chunk fields and size units

Accepted input: a PDF with a text layer (up to 50 MB), a Word .docx (up to 25 MB), or Markdown and plain-text files (.md, .txt) of up to 10 MB; pasted text has the same 10 MB ceiling. The type is decided by the file's opening bytes rather than its name. PDF text is read page by page with pdf.js, lines are rejoined into paragraphs, and a word broken with a hyphen at a line end is put back together when the next line starts in lowercase. Word files are read with mammoth's raw-text mode, which gives the main body as one paragraph per block. A .txt or .md file opening with a UTF-16 byte-order mark is decoded as UTF-16 and any other as UTF-8; when its bytes break the UTF-8 rules, the chunker decodes them with the Windows-1252 table instead and adds a note to the result summary, so you can check accented letters before anything is indexed.

The JSONL download has one object per line with the fields id, text, tokens_estimate, chars and metadata, in that order. metadata always holds source (the file name, or pasted-text) and chunk_index, which counts from 1. In Markdown mode it adds heading_path, a list of the headings above the chunk; for a PDF it adds page_start and page_end. These field names belong to this tool. Vector databases and retrieval frameworks each document their own import format, so read that documentation and rename fields where it asks for something different.

The CSV download has the columns id, chunk_index, tokens_estimate, chars, source, heading_path, page_start, page_end and text, with the long text column last so the rest stays readable in a spreadsheet. The heading path is joined with " > ", fields that contain commas, quotes or line breaks are quoted, records end in CRLF, and the CSV is written as plain UTF-8 with nothing in front of the header row. Chunk text is written exactly as it appears in the source, line breaks and Markdown included.

Sizes are measured either in estimated tokens, using the same character-and-word estimate as the other AI tools on this site, or in characters, counted as Unicode code points so an emoji counts once. Chunk sizes run from 20 to 16,000 estimated tokens or from 80 to 64,000 characters, and the overlap must stay under half the chunk size.

How it works

In every mode except fixed size, the text is first divided into blocks at blank lines. Lines that start with one to six # signs and a space are headings and become blocks of their own, and fenced code blocks between ``` or ~~~ lines stay whole even when they contain blank lines, so a comment line such as "# install" inside a shell snippet is not mistaken for a heading.

Each block that fits the limit is kept whole. A block that is too big is cut at sentence ends; code, tables and lists are cut at line ends instead. A sentence or line that is still too big is cut between words. For a cut at a sentence end, the chunker needs one of . ! ? or … (closing quotes or brackets may follow it), then whitespace, then a word that does not begin with a lowercase letter, so "approx. five" stays together; 。!? close a sentence even with no space after them. Common abbreviations such as Dr., e.g., No. and Jan., and single initials like J., are never treated as sentence ends.

The pieces are then packed in order: a chunk takes as many as fit under the limit, measured on the exact slice of text it will hold, spaces and line breaks included. In paragraph mode the pieces are whole paragraphs where possible; in sentence mode they are sentences, so chunks fill closer to the limit and may begin mid-paragraph; in fixed mode they are single words. A heading is never left as the last line of a chunk when text follows it, and the paragraph after a heading is cut small enough to share a chunk with it.

In Markdown mode each heading opens a section and no chunk spans two sections, so every chunk can carry an exact heading path such as Greenhouse handbook > Watering > Holiday weeks. A section that holds only its heading line is joined to the next one instead of becoming a chunk on its own.

For the overlap, the tool looks at the end of the previous chunk and takes the longest run of whole sentences that stays within the overlap size. If even the last sentence is longer than that, it takes whole words instead. The overlap is shortened, or dropped, when the next piece of new text would not otherwise fit, because every chunk including its overlap stays under the limit. Overlap is carried across section boundaries too, so the first chunk of a section can open with the last sentence of the section before it.

Every chunk is a slice of the extracted text, so its start and end offsets map straight onto the page offsets recorded while the PDF was read, which is where page_start and page_end come from.

Common use cases

  • Preparing a staff handbook PDF for a question-answering assistant, with page numbers kept so answers can cite the page
  • Turning a folder of Markdown documentation, one file at a time, into chunks that remember which section they came from
  • Checking how a long Word report would be cut before writing any embedding code
  • Comparing paragraph and sentence splitting on the same contract to see which keeps clauses together
  • Producing a CSV of chunks for a colleague to review in a spreadsheet before they are indexed

How to use this tool

  1. Pick a PDF, .docx, .md or .txt file with Choose file or by dragging it onto the dashed box, or paste text into the text box. Press Use sample text to try a short Markdown handbook first.
  2. Choose how to split. Markdown headings suit notes, documentation and READMEs; paragraphs suit reports and PDFs; sentences give more even sizes; fixed size ignores structure.
  3. Set the chunk size and overlap. Pick estimated tokens to match an embedding model's input limit, or characters if your pipeline counts characters.
  4. Press Make chunks and read the summary: the chunk count, the smallest, median and largest sizes, and the size chart. Look at the preview to see where cuts fell.
  5. If chunks are too small or cut in odd places, change the mode or size and press Make chunks again.
  6. Download JSONL or CSV and load it with your vector database's or framework's own import tools.

Example

returns-policy.md, split by Markdown headings at 60 estimated tokens with a 10-token overlap

# Returns policy

You can return most items within 30 days of delivery. Items must be unused and in the original packaging.

## Refunds

Refunds go back to the original payment method within 5 working days of the parcel reaching our warehouse. Delivery charges are refunded only when the item arrived faulty.

## Exceptions

Opened software, gift cards and made-to-measure curtains cannot be returned.

returns-policy-chunks.jsonl (3 lines)

{"id":"returns-policy-0001","text":"# Returns policy\n\nYou can return most items within 30 days of delivery. Items must be unused and in the original packaging.","tokens_estimate":29,"chars":123,"metadata":{"source":"returns-policy.md","chunk_index":1,"heading_path":["Returns policy"]}}
{"id":"returns-policy-0002","text":"be unused and in the original packaging.\n\n## Refunds\n\nRefunds go back to the original payment method within 5 working days of the parcel reaching our warehouse. Delivery charges are refunded only when the item arrived faulty.","tokens_estimate":52,"chars":225,"metadata":{"source":"returns-policy.md","chunk_index":2,"heading_path":["Returns policy","Refunds"]}}
{"id":"returns-policy-0003","text":"refunded only when the item arrived faulty.\n\n## Exceptions\n\nOpened software, gift cards and made-to-measure curtains cannot be returned.","tokens_estimate":30,"chars":136,"metadata":{"source":"returns-policy.md","chunk_index":3,"heading_path":["Returns policy","Exceptions"]}}

Tips for best results

  • Start with Markdown mode for anything that has # headings. The heading path is often the most useful metadata for filtering and for showing users where an answer came from.
  • Keep the chunk size below your embedding model's documented input limit with room to spare: the counts here are estimates, not the output of your model's tokenizer.
  • If the median chunk in the summary is far below your limit in Markdown mode, the document has many short sections. Switch to paragraphs if you would rather pack them together.
  • An overlap of about a tenth of the chunk size is a common starting point. Larger overlaps store more repeated text and make near-duplicate search results more likely.
  • For a PDF, open the first chunk in the preview and look for running headers or page numbers mixed into the text; they come from the PDF's text layer and are not removed.
  • Rename the source file before loading it if you want different ids: the id prefix is made from the file name, lowercased, with other characters turned into hyphens.

Common pitfalls

Token counts are estimates from characters and words, not from your model's tokenizer. Code, long numbers or text in other languages may split into more tokens than the estimate assumes, in which case a chunk of 500 by this measure is larger to the model.

Scanned PDFs have no text layer, and this tool does not run OCR. A scan gives no text at all, and a PDF with a few scanned pages lists those pages as empty.

PDF text comes back in the order it is stored in the file. Two-column layouts, sidebars and footnotes can come out interleaved with the main text, and tables lose their columns.

Headers, footers and page numbers that repeat on every page are kept, because the tool cannot tell them apart from body text. They add noise to many chunks of a long PDF.

Word headings are not detected: mammoth's raw-text mode drops styles, so a .docx is chunked by paragraph even in Markdown mode, and heading paths stay empty. Underlined Markdown headings (a line of === or --- under the title) are not detected either.

Text in languages written without spaces between words, other than Chinese, Japanese and Korean, has no safe place to cut inside a paragraph, so a long Thai or Khmer paragraph can end up as one oversize chunk.

When the CSV is opened in a spreadsheet, a chunk that starts with =, +, - or @ may be treated as a formula. Use the JSONL file for anything a program will read.

Common errors and how to fix them

"… is password-protected. Remove the password (Unlock PDF on this site can do it if you know the password), then choose the unlocked copy."
pdf.js cannot reach the text of a password-locked PDF. Make an unlocked copy with the password and load that copy.
"handbook.pdf has no selectable text on any of its 12 pages, so it is probably scanned images."
Every page came back empty, which is what a scan looks like. Make the PDF searchable with an OCR program, check that you can select text in a PDF viewer, then load it again.
"… is an older .doc file or a password-protected Word file."
Both use the old OLE container, which mammoth cannot read. Open the file in Word, remove any password, save it as Word Document (.docx) and choose the new copy.
"Keep the overlap below half the chunk size…"
With an overlap of half the size or more, most of every chunk would be repeated text. Lower the overlap or raise the chunk size; switching between tokens and characters scales both by four.
"These settings would make more than 200,000 chunks."
That only happens with a very large file and a very small chunk size. Raise the chunk size, lower the overlap, or split the file and chunk each part.

Best practices

  • Decide the chunk size from the embedding model and the kind of question, not from habit: short factual questions tend to suit smaller chunks, and questions about procedures or reasoning larger ones.
  • Keep the downloaded JSONL alongside the source file, so the same chunks can be re-embedded later without being regenerated.
  • Store heading_path and page_start with each vector, so answers can point to a section or page.
  • Look at the over-the-limit bar in the size chart. Oversize chunks usually hold a long link or a block of encoded data that is better removed from the source.
  • When you change chunking settings for a document that is already indexed, replace all of its chunks; mixing chunks from two settings leaves overlapping, duplicated passages.

Choosing a chunk size and an overlap

The overlap eats into each chunk. With a size of 500 estimated tokens and an overlap of 50, a typical chunk carries about 450 tokens of new text, so a handbook of about 90,000 estimated tokens comes out at roughly 200 chunks. Halve the size to 250 with the same overlap and each chunk brings about 200 new tokens, which more than doubles the count to around 450 chunks and the number of vectors you store.

Smaller chunks tend to match narrow questions more precisely but carry less context into the prompt; larger chunks carry more context but can blur several topics into one vector. The size chart helps here: if most bars sit near the limit in sentence or fixed mode, the size is doing the cutting; if they are spread low in Markdown or paragraph mode, the document's own structure is.

What the heading path records

The path lists the headings above a chunk from the top level down. Under # Greenhouse handbook, ## Watering and ### Holiday weeks, a chunk from the holiday section gets ["Greenhouse handbook", "Watering", "Holiday weeks"]. When the next ## heading appears, the deeper levels are dropped, so a chunk under ## Ventilation gets ["Greenhouse handbook", "Ventilation"]. Text before the first heading has an empty path, and trailing # marks on a heading line are removed from its title.

Because overlap crosses section boundaries, the first chunk of a section may open with a sentence from the section before. The path always describes the section the chunk's new text belongs to.

Page numbers for PDF chunks

While the PDF is read, the position where each page's text starts is recorded. A chunk's page_start is the page holding its first character, overlap included, and page_end the page holding its last. A paragraph that runs across a page break is split there, because each page's text is read separately, so a chunk that spans pages 3 and 4 usually holds the end of one paragraph and the start of the next.

Frequently asked questions

What if my embedding model rejects a chunk as too long?

Lower the chunk size, press Make chunks again and download a fresh file. Chunks are sized by an estimate, so one that sits near the limit in the size chart can still be over your model's real input limit. A chunk the summary flags as over the limit holds a single unbroken word, such as a pasted data blob; remove it from the source instead.

Can I chunk several files into one JSONL?

Chunk each file separately and join the downloaded JSONL files end to end; one object per line means they concatenate cleanly. The ids stay unique as long as the source file names differ, because each id starts with the file name.

Does this tool create embeddings or send text to an AI service?

No. It only cuts text and writes files. Extraction and chunking run in your browser tab and nothing you load or paste is uploaded. Until you download them, the extracted text and the chunks exist only in the tab's memory, and they are gone when you reload or close the page. Creating embeddings is a separate step in your own pipeline.

Why are some chunks much smaller than the limit?

In Markdown mode a short section becomes a short chunk, because chunks never span two sections. In paragraph mode a chunk ends when the next whole paragraph would not fit. Sentence or fixed mode packs chunks closer to the limit.

Why does chunk_index start at 1?

So it matches the chunk numbers in the preview and the number at the end of each id: chunk 1 is returns-policy-0001.