Home / Use cases / Split a PDF into Chunks for a Vector Database

Updated

Split a PDF into Chunks for a Vector Database (with Page Numbers)

A good RAG pipeline cites the page an answer comes from. Generic splitters cut across headings and lose the page numbers.

Try it now on Apify Document to Markdown & JSON (PDF, DOCX, PPTX, HTML, OCR) · $0.004 per one document converted, first 50 pages included · failed items are free

How to do it, step by step

  1. Send the PDF URLs with Chunking on.
  2. Set Chunk max words (250–400) and overlap (about 40 words).
  3. For each chunk, store text as content and headings, page_start, page_end and the document URL as metadata.
  4. Show the page in your answers: “source: paper.pdf, p. 4”.

The exact input used for the example below:

{
  "urls": [
    "https://arxiv.org/pdf/2005.11401"
  ],
  "chunking": true,
  "chunkMaxWords": 250,
  "includePages": false,
  "maxPages": 20
}

Real result

Run Xksd7EosAp2y9XFcx on 2026-12-05: status SUCCEEDED, 1 item(s), 5.5 s of run time. Output shortened for reading (long text cut with “…”).

19 pages became 64 chunks of at most 250 words, each with its heading path and page range.

[
  {
    "url": "https://arxiv.org/pdf/2005.11401",
    "title": "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks",
    "pageCount": 19,
    "wordCount": 10297,
    "chunks": [
      {
        "index": 0,
        "text": "Patrick Lewis†‡, Ethan Perez(cid:63),\n\nAleksandra Piktus†, Fabio Petroni†, Vladimir Karpukhin†, Naman Goyal†, Heinrich Küttler†,\n\nMike Lewis†, Wen-tau Yih†, Tim Rocktäschel†‡, Sebastian Riedel†‡, Douwe Kiela†\n\n†Facebook AI Research; ‡University College London; (cid:63)New York University;\nplewis@fb.…",
        "word_count": 35,
        "headings": [
          "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks"
        ],
        "page_start": 1,
        "page_end": 1
      },
      {
        "index": 1,
        "text": "Patrick Lewis†‡, Ethan Perez(cid:63), Aleksandra Piktus†, Fabio Petroni†, Vladimir Karpukhin†, Naman Goyal†, Heinrich Küttler†, Mike Lewis†, Wen-tau Yih†, Tim Rocktäschel†‡, Sebastian Riedel†‡, Douwe Kiela† †Facebook AI Research; ‡University College London; (cid:63)New York University; plewis@fb.com…",
        "word_count": 250,
        "headings": [
          "Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks"
        ],
        "page_start": 1,
        "page_end": 1
      },
      "… 62 more"
    ]
  }
]

Try it now with your own input

FAQ

What overlap should I use?

10 to 15 % of the chunk size keeps sentences that straddle a boundary retrievable from both sides.

Are tables chunked?

Tables stay whole inside a chunk as Markdown, and are also available as JSON per page.

Long documents?

The first 50 pages are included in the document price; extra pages cost $0.0001 each.

Related