RAG Text Chunker (Markdown to Chunks, Token Counts) avatar

RAG Text Chunker (Markdown to Chunks, Token Counts)

Pricing

from $0.09 / 1,000 chunks

Go to Apify Store
RAG Text Chunker (Markdown to Chunks, Token Counts)

RAG Text Chunker (Markdown to Chunks, Token Counts)

Split Markdown or text into RAG-ready chunks with exact OpenAI token counts (o200k/cl100k): heading-aware, code blocks kept whole, sentence-boundary overlap, heading path on every chunk. Chunks any dataset from Website to Markdown, PDF to Markdown or your own texts.

Pricing

from $0.09 / 1,000 chunks

Rating

0.0

(0)

Developer

Murat Uzun

Murat Uzun

Maintained by Community

Actor stats

0

Bookmarked

1

Total users

0

Monthly active users

5 days ago

Last modified

Features

Limited permissions

Share

What is RAG Text Chunker?

RAG Text Chunker splits Markdown or plain text into retrieval-ready chunks for vector databases (Pinecone, Qdrant, Weaviate, pgvector, Chroma) and RAG apps, with exact OpenAI token counts (o200k_base for GPT-4o/GPT-5, or cl100k_base for GPT-4 and text-embedding-3). It is heading-aware: every chunk stays inside one section and carries its heading path (Guide > Install > Linux), code blocks are never cut mid-line, oversized paragraphs split at sentence boundaries, tiny fragments are folded into their neighbours, and inline base64 images are dropped. $0.18 per 1,000 chunks on the free plan, down to $0.09 on Gold and above.

Feed it the dataset of a scraping run (Website to Markdown, llms.txt Generator, PDF to Markdown, YouTube transcripts, articles), a list of document URLs (Markdown, text or HTML pages), or paste your own texts, and get one row per chunk ready to embed.

Incremental sync: turn on Only new or changed chunks and re-run on a schedule. Each chunk has a contentHash; the Actor remembers the hashes per document and pushes only chunks whose text changed. Unchanged chunks are not pushed and not charged, and the hashes of chunks that disappeared are listed in the REMOVED_CHUNKS record so you can delete their vectors. When one section of a long page changes, you re-embed that section's chunks, not the whole page.

What does RAG Text Chunker output?

FieldDescription
documentId, url, titleThe source document (documentId is its URL, or document-N)
chunkIndex, chunkCount, chunkIdPosition of the chunk in the document; chunkId = documentId#index
contentHash16 hex characters of SHA-256 of the chunk text; the same text always gives the same hash. Use documentId + contentHash as the vector ID for incremental sync
headingPath, headingsHeadings the chunk sits under, as an array and as A > B > C
textThe chunk text, with the heading path on top and the overlap from the previous chunk
tokens, overlapTokens, charactersExact token count with the chosen tokenizer, tokens of overlap, length
encodingo200k_base or cl100k_base
any Columns to keepFields copied from the source rows, e.g. lang, crawledAt, site

The OUTPUT record of each run has documents, chunks, chunksPushed, chunksUnchanged, chunksRemoved and errorCode. With incremental sync on, REMOVED_CHUNKS lists {documentId, url, contentHash} for every chunk that is gone since the last run.

How to use RAG Text Chunker

  1. Give it text: an Input dataset ID from another run (the text column is found automatically), Document URLs, Documents as JSON, or Texts.
  2. Set Chunk size (default 500 tokens) and Overlap (default 50), and pick the Tokenizer your embedding model uses.
  3. Run, then embed the text column of the dataset and store it with chunkId, url and headings as metadata.

Incremental sync with a vector database

  1. Run once with Only new or changed chunks on and a State store name for your index (for example docs-index). The first run pushes every chunk.
  2. Upsert the rows with ID documentId + '#' + contentHash.
  3. Schedule the same input. Each later run pushes only new or changed chunks. Delete the IDs listed in the run's REMOVED_CHUNKS record.

Documents that are not in a run's input are left alone: their hashes stay in the store and nothing is reported as removed.

Chaining with a crawler

Run Website to Markdown or PDF to Markdown Converter, copy the run's dataset ID, and pass it as Input dataset ID. With Apify integrations or the API you can start the chunker automatically when the crawl finishes.

Example input

{
"inputDatasetId": "NJMrOuJvOh0X9IP4r",
"chunkSize": 400,
"overlap": 40,
"encoding": "o200k_base",
"keepFields": ["lang"]
}

Example output

{
"documentId": "https://crawlee.dev/js/docs/3.10/quick-start",
"url": "https://crawlee.dev/js/docs/3.10/quick-start",
"title": "Quick Start",
"chunkIndex": 4,
"chunkCount": 26,
"chunkId": "https://crawlee.dev/js/docs/3.10/quick-start#4",
"headingPath": [
"Quick Start",
"Crawling"
],
"headings": "Quick Start > Crawling",
"text": "Quick Start > Crawling\n\nYou need to explicitly install it with NPM. 👇\n\n```\nnpm install crawlee puppeteer\n```\n\nRun the following example to perform a recursive crawl of the Crawlee website using the selected crawler.\n\nDon't forget about module imports\n\nTo run ...",
"tokens": 145,
"overlapTokens": 23,
"characters": 589,
"encoding": "o200k_base"
}

In a test on 120 pages of the Crawlee and Apify docs with 400-token chunks and 40-token overlap, the 898 chunks ranged from 23 to 463 tokens (content up to 400, plus heading path and overlap).

How much does it cost?

Pay per result: $0.18 per 1,000 chunks on the free plan, $0.14 on Bronze, $0.115 on Silver and $0.09 on Gold, Platinum and Diamond, plus $0.00005 per run start. In a test with eight long Markdown READMEs (241,000 characters, 300-token chunks) one run wrote 298 chunks, which costs about $0.054 on the free plan. A typical documentation page gives 5 to 10 chunks at 400 tokens. A dataset or URL that cannot be read is listed in the ERRORS record and costs nothing. With incremental sync, unchanged chunks are not pushed and cost nothing: a re-run on unchanged documents costs only the run start. Set Maximum cost per run to cap spend.

Limits

  • Chunk size limits the content; the heading path and the overlap are added on top, so a chunk can be up to about chunk size + overlap + the heading path.
  • Chunking follows Markdown headings (# … ######). Plain text without headings is split by paragraphs and sentences.
  • Tokens are counted with OpenAI's tokenizers; other models (Claude, Gemini, open-source embeddings) count somewhat differently.
  • Datasets are read in batches of 1,000 rows; very large datasets take longer.

Using RAG Text Chunker with AI agents

The Actor is pay-per-event with limited permissions, so AI agents can call it through Apify's MCP server (mcp.apify.com), for example with {"texts": ["# Doc\n\nLong text..."], "chunkSize": 300}, or with inputDatasetId right after a crawl.

FAQ

Why heading-aware chunks? A chunk that mixes two sections embeds to a blurry vector and is hard to cite. Keeping one section per chunk and putting its heading path in the text makes retrieval and citations more precise.

Which chunk size should I use? 300 to 500 tokens with 10 % overlap is a common starting point for question answering; use larger chunks for summarisation.

Part of the webdatatools web-intelligence suite — every Actor is pay-per-event, reads public data without a login, and returns one clean row per entity:

Browse the whole suite at webdatatools, or call ten of these Actors straight from Claude, Cursor or Cline with the webdatatools MCP server.

Website & domain intelligence

Content for AI, LLMs and RAG

Search, video and social

Leads, jobs and company data

Developer, app and research data

Input parameters

FieldTypeDefaultDescription
inputDatasetIdstringDataset of another run to chunk, e.g. from Website to Markdown, llms.txt Generator or PDF to Markdown. The text column is found automatically (markdown, `text
textFieldstringOptional: the dataset column holding the text, if it is not one of the usual names.
documentsarrayOr paste documents as JSON: [{"url": "...", "title": "...", "text": "..."}].
documentUrlsarrayOr URLs of Markdown (.md), text (.txt) or HTML pages. HTML is reduced to its main content and converted to Markdown. Up to 10 MB per document; PDFs are not read.
textsarrayOr paste plain texts or Markdown, one document per item.
chunkSizeinteger500Maximum tokens of content per chunk (heading path and overlap come on top).
overlapinteger50Tokens from the end of the previous chunk repeated at the start of the next, cut at a sentence boundary. 0 for none.
encodingstring"o200k_base"o200k_base: GPT-4o, GPT-4.1, GPT-5, o-series. cl100k_base: GPT-4, GPT-3.5, text-embedding-3.
respectHeadingsbooleantrueNever mix two sections (headings up to the level below) in one chunk.
headingLevelinteger22 = split at # and ## headings; 3 also at ###.
includeHeadingInTextbooleantruePrefix each chunk with "Title > Section" so the embedding knows the context.
keepFieldsarrayOptional: dataset or document fields copied onto every chunk, e.g. lang, crawledAt.
onlyChangedChunksbooleanfalsePush only chunks whose text is new since the last run; unchanged chunks are not charged; removed hashes go to REMOVED_CHUNKS.
stateStoreNamestring"rag-text-chunker-state"Named key-value store that keeps the chunk hashes. Use one name per vector index.

Limitations

  • Token counts are exact only for o200k_base and cl100k_base. Other tokenizers are not supported.
  • Input is Markdown, plain text or an HTML page. PDFs and Office files are not read; convert them first (for example with PDF to Markdown) and pass the dataset. Pages that need JavaScript to show their text come back nearly empty; crawl them with Website to Markdown and pass the dataset.
  • No chunking strategy choice: the splitter is fixed (heading-aware, sentence-boundary overlap).
  • Base64 inline images are dropped from the text.

Errors

Failed sources are listed in the ERRORS record (source, errorCode, error) and are not charged. The run's code is in OUTPUT.errorCode.

CodeMeaningRun status
NOT_FOUNDA document URL returned HTTP 404 or 410SUCCEEDED, other documents are chunked
INVALID_URLNot an http(s) URLSUCCEEDED
UNSUPPORTED_TYPEThe URL is a PDF, image or other non-text fileSUCCEEDED
TOO_LARGEThe document is over 10 MBSUCCEEDED
EMPTY_DOCUMENTThe page has no text to chunkSUCCEEDED
DATASET_READ_FAILEDThe input dataset could not be read (wrong ID or no access)SUCCEEDED
FETCH_FAILEDNetwork error, timeout or HTTP 403/5xx from the siteSUCCEEDED if anything else was chunked
SOURCE_FAILEDNo document could be downloaded because of FETCH_FAILED errorsFAILED
TIME_LIMITThe run timeout was near; chunks already pushed are kept, the rest is listedSUCCEEDED

Run from Python, JavaScript and the CLI

Python (apify-client):

from apify_client import ApifyClient
client = ApifyClient("<APIFY_TOKEN>")
run = client.actor("webdatatools/rag-text-chunker").call(
run_input={"texts": ["# Guide\n\nSome text to split into chunks."], "chunkSize": 300}
)
for chunk in client.dataset(run["defaultDatasetId"]).iterate_items():
print(chunk["chunkIndex"], chunk["tokens"], chunk["headingPath"])

JavaScript (apify-client):

import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: '<APIFY_TOKEN>' });
const run = await client.actor('webdatatools/rag-text-chunker').call({
texts: ['# Guide\n\nSome text to split into chunks.'],
chunkSize: 300,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items.length, items[0].tokens);

Apify CLI:

$apify call webdatatools/rag-text-chunker --input='{"texts":["# Guide\n\nSome text to split into chunks."],"chunkSize":300}'

RAG Text Chunker vs. alternatives

Store pages and price lists read on 29 Nov 2026 (https://apify.com/<id>, pricingInfos of each Actor).

ActorPrice per 1,000 chunks (free plan → top tier)Notes from its Store page
hipersoft/text-splitter-chunker$0.20 → $0.10Recursive or fixed splitting; token count is an estimate (about 4 characters per token)
ucchiii/rag-chunker$0.20 → $0.14Reads crawler datasets, heading path; token count is an estimate (characters / 4)
shoebill-dev27/rag-text-chunker$0.20 (one result is one chunk)Same price on every plan, $0.0005 per run start
raional/text-chunker$0.50Recursive, sentence or token strategies, document URLs; $0.005 per GB run start
codepoetry/markdown-rag-chunker$0.80 → $0.60PDF, Office and web URLs, stable chunk IDs; Skip if unchanged skips a document only when nothing in it changed, otherwise every chunk of the document is pushed again
steady_kahikatea/text-chunker-embeddingsper document plus per chunkChunking plus embeddings, a different unit

This Actor costs $0.18 (free plan) to $0.09 (Gold and above) per 1,000 chunks, the lowest per-chunk price in this table on every plan. It counts tokens with the real OpenAI tokenizers (o200k/cl100k) instead of a characters-divided-by-4 estimate, and it puts the heading path on every chunk. With Only new or changed chunks it pushes just the chunks of a changed document whose text changed and lists the removed chunk hashes; none of the Actors above documents chunk-level change tracking.

Support

Report a document that chunks incorrectly in the Issues tab of this Actor's Store page. Apify platform questions go to https://docs.apify.com.

If the chunker saves you time, please leave a review on its Store page. It helps other RAG builders find it.