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’stitle, to filter or prefix when searching several papers.blocksare the ids of the editable JSON (and--json),pagescount 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
--tokenizeryour embedding model’stokenizer.json(from its Hugging Face repository) orcl100k_base/o200k_basefor OpenAI’s models.tokensthen 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 from | nomic-embed v1.5, 1024 / 2048 tokens retrieved | Qwen3-Embedding 0.6B, 1024 / 2048 | Time, 100 papers (CPU) |
|---|---|---|---|
kakemono (-f chunks) | 0.611 / 0.738 | 0.581 / 0.753 | 9.5 s |
docling + its HybridChunker | 0.608 / 0.734 | 0.536 / 0.705 | 2032 s |
unstructured (fast) + chunk_by_title | 0.461 / 0.596 | 0.446 / 0.626 | 153 s |
| pypdf, cut every 512 tokens | 0.388 / 0.559 | 0.450 / 0.621 | 38 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