Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chunks for retrieval (RAG)

kakemono convert paper.pdf -o paper.jsonl (or --format chunks) cuts the text into chunks ready to embed, one JSON object per line:

{"id":3,"text":"I. INTRODUCTION\n\nThe discovery of the binary pulsar system PSR B1913+16 by Hulse and Taylor ...",
 "tokens":439,"title":"Observation of Gravitational Waves from a Binary Black Hole Merger",
 "section":["I. INTRODUCTION"],"blocks":[12,13],"pages":[0]}
  • Along the structure. A chunk holds the blocks of one section, up to --chunk-tokens (default 512); a block is cut only when it does not fit in one chunk, at sentence ends. Tables give their caption and rows (cells joined by |), formulas their LaTeX ($$...$$).
  • Headed by the section path (3 Model > 3.2 Attention), not by the paper title: within one paper a title on every chunk only blurs the embeddings. The title is in each chunk’s title, to filter or prefix when searching several papers. blocks are the ids of the editable JSON (and --json), pages count from 0.
  • Sized in tokens. By default an estimate that needs no tokenizer: 15 to 20% above the count of real subword tokenizers, so that a chunk seldom passes a model’s limit. To count exactly, give --tokenizer your embedding model’s tokenizer.json (from its Hugging Face repository) or cl100k_base / o200k_base for OpenAI’s models. tokens then counts without special tokens ([CLS], <s>), which most models add.

Measured on Qasper (questions on 100 NLP papers; share of the gold evidence in the retrieved text, two embedding models; see eval/qasper/):

Chunks fromnomic-embed v1.5, 1024 / 2048 tokens retrievedQwen3-Embedding 0.6B, 1024 / 2048Time, 100 papers (CPU)
kakemono (-f chunks)0.611 / 0.7380.581 / 0.7539.5 s
docling + its HybridChunker0.608 / 0.7340.536 / 0.7052032 s
unstructured (fast) + chunk_by_title0.461 / 0.5960.446 / 0.626153 s
pypdf, cut every 512 tokens0.388 / 0.5590.450 / 0.62138 s

docling ties with nomic and is 4 to 5 points behind with Qwen3 (a difference outside the 95% interval of a bootstrap over papers); pypdf and unstructured are 13 to 22 points behind with both. Times are conversion and chunking, without embedding, one paper after another on 4 cores.

kakemono convert paper.pdf -o paper.jsonl --chunk-tokens 256
kakemono convert paper.pdf -o paper.jsonl --tokenizer path/to/bge-m3/tokenizer.json