Markdown for LLMs: Format PDFs for Better RAG Retrieval
npx pdftomarkdown your.pdfconverts page 1 of any PDF, key-free.Docs →Preserve the relationships your questions need
Useful Markdown keeps headings, lists and table relationships visible. Cleaner syntax can help a pipeline preserve context, but retrieval and answer quality still need measurement.
Headings and lists
Retain the source hierarchy when it carries meaning. Headings provide candidate chunk boundaries; ordered lists preserve sequence. Do not treat a visual font change as proof of a semantic heading without checking the document.
Tables need two representations
Use escaped GFM for simple rectangular tables. Keep complex spans or nested content as sanitized HTML rather than fabricating empty cells. Token efficiency depends on the content and tokenizer; no fixed Markdown-versus-HTML saving applies to every document.
Choose a chunking strategy
Heading-based chunks preserve sections but can exceed a model’s limit. Token-bounded splitting handles long passages but may cut through related content. A combined approach can retain section context while bounding size. Keep table headers with rows and do not split fenced code as if its internal headings were document sections.
Track source and version
Carry your document identifier and source reference with every chunk. Markdown line numbers are not PDF page numbers. Retain separate provenance if precise page citations matter.
Evaluate with known questions
Hold the source documents, queries and retrieval settings fixed while comparing chunking choices. Measure whether the correct evidence is retrieved and whether answers remain faithful. No parser or format guarantees higher precision without that evaluation.
Convert a document
Use the tested Python, JavaScript or curl workflow. Choose one input: a public PDF URL, Base64 bytes, or a raw PDF upload. Raw uploads avoid Base64 expansion; all three send the document to an external processor.
The public demo converts page 1 with a watermark, at 3 requests per minute per IP. New accounts receive 20 trial pages once. Further account conversions use paid credits: monthly pages expire, top-ups do not. The API reference owns authentication, limits, replay and retention.