<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KolmoPDF</title>
    <description>The latest articles on DEV Community by KolmoPDF (@kolmopdf).</description>
    <link>https://dev.to/kolmopdf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4229843%2F7eb38448-8fb7-4fc8-a3b8-30693f6a0bc3.png</url>
      <title>DEV Community: KolmoPDF</title>
      <link>https://dev.to/kolmopdf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kolmopdf"/>
    <language>en</language>
    <item>
      <title>A PDF page number can hide missing scanned text in your RAG pipeline</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Wed, 25 Nov 2026 15:22:43 +0000</pubDate>
      <link>https://dev.to/kolmopdf/a-pdf-page-number-can-hide-missing-scanned-text-in-your-rag-pipeline-nd1</link>
      <guid>https://dev.to/kolmopdf/a-pdf-page-number-can-hide-missing-scanned-text-in-your-rag-pipeline-nd1</guid>
      <description>&lt;p&gt;A scanned PDF page can contain an embedded page number and still have no selectable body text. A file-level check sees text somewhere in the document, skips OCR, and sends an almost empty page to the index. The missing page may look like a retrieval problem later, even though the words never entered the index.&lt;/p&gt;

&lt;p&gt;A page-by-page audit is a useful first step when converting mixed technical documents with &lt;a href="https://www.kolmopdf.com/pdf-to-markdown" rel="noopener noreferrer"&gt;KolmoPDF's PDF-to-Markdown tool&lt;/a&gt;. Start with an authorized sample containing both selectable and scanned pages. Compare each source page with the Markdown output, particularly pages that contain diagrams, tables, or very little extracted text. The example below is a synthetic fixture for designing that check; it is not a claim about any particular conversion result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a fixture that defeats the empty-page check
&lt;/h2&gt;

&lt;p&gt;Imagine a three-page document:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Page 1 has selectable paragraphs and a page number.&lt;/li&gt;
&lt;li&gt;Page 2 is a scanned paragraph with an embedded page number, &lt;code&gt;2&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Page 3 is a diagram with a short caption and no paragraph text.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A rule that marks every nonempty extraction as successful accepts page 2. A rule that sends every short page to OCR also catches page 3, even though a short caption may be the complete textual content. A character threshold can help find candidates for review, but it cannot establish whether a page is complete.&lt;/p&gt;

&lt;p&gt;For an audit, retain a record for each page with a source identifier, its physical page index, extraction route if known, and a reference to the rendered page. Keep the original extracted text beside the normalized text used for retrieval. If a service returns one Markdown file without page-level route metadata, record the route as unknown; do not infer it from the text alone. Page boundaries must come from reliable converter output or a separate mapping process.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare coverage at page level
&lt;/h2&gt;

&lt;p&gt;This small Python example flags pages for inspection. It treats page numbers as possible noise and leaves a short page in the review queue instead of declaring it empty. The inputs are illustrative strings, not a PDF parser.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="n"&gt;pages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Introduction to the measurement protocol."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Figure 1. Sensor layout."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;needs_review&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minimum_chars&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;splitlines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fullmatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"\d+"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;minimum_chars&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;pages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;needs_review&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Review page {page['page']}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prints pages 2 and 3. A reviewer can confirm that page 2 needs another extraction route and that page 3's caption is complete. The threshold is a starting point to tune on your own documents. A blank page, a title page, and a page full of formulas will need different handling. Removing number-only lines is a heuristic too: a meaningful standalone number could be lost, so keep the original text.&lt;/p&gt;

&lt;p&gt;When the text is sparse, inspect the page image before replacing anything. If the original has text that the Markdown omits, try an OCR-capable route and compare the new result against the source. For a page with a table, check row and column associations as well as the words and numbers. Keep both outputs and their page references until the discrepancy is resolved.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the retrieval test separate
&lt;/h2&gt;

&lt;p&gt;After checking extraction, create a question whose answer appears only on the scanned page. Verify that the expected page appears in retrieval and that the answer cites it. An extraction pass cannot guarantee retrieval will succeed: chunking, indexing, and ranking can each lose the evidence later.&lt;/p&gt;

&lt;p&gt;Include a negative question about information absent from the controlled sample. That checks whether the answerer invents an answer from nearby text. For documents with right-to-left text or multiple columns, add a short expected sequence of words or paragraphs to the fixture. A page can contain all its words and still present them in a misleading order.&lt;/p&gt;

&lt;p&gt;Before uploading a document for online processing, confirm that its contents are authorized for that service. For sensitive files, use an approved processing arrangement. Save the reviewed source pages and expected outputs as regression fixtures, so a converter or indexing change can be checked against the same examples.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>ocr</category>
      <category>rag</category>
      <category>markdown</category>
    </item>
    <item>
      <title>PDF table headers can swap datasets while every number survives</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Tue, 24 Nov 2026 15:21:29 +0000</pubDate>
      <link>https://dev.to/kolmopdf/pdf-table-headers-can-swap-datasets-while-every-number-survives-4cb1</link>
      <guid>https://dev.to/kolmopdf/pdf-table-headers-can-swap-datasets-while-every-number-survives-4cb1</guid>
      <description>&lt;p&gt;A Markdown table can have unique headers and still assign a result to the wrong dataset. Suppose a PDF groups two columns under &lt;code&gt;Dataset A&lt;/code&gt; and &lt;code&gt;Dataset B&lt;/code&gt;, both measured as accuracy. After conversion, the labels may be flattened into &lt;code&gt;Dataset A / Accuracy&lt;/code&gt; and &lt;code&gt;Dataset B / Accuracy&lt;/code&gt;. If the header order is swapped while the data cells stay in place, the table renders perfectly and every number survives. A retrieval system can then cite the correct page and give the wrong result.&lt;/p&gt;

&lt;p&gt;This is a useful companion to the &lt;a href="https://dev.to/kolmopdf/a-pdf-table-can-lose-its-dataset-labels-a-markdown-conversion-check-5g21"&gt;dataset-label check&lt;/a&gt;. Checking for missing or duplicate names catches one failure. Checking the relationship between each header and its cells catches another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the fixture asymmetric
&lt;/h2&gt;

&lt;p&gt;Use a small synthetic table with deliberately distinct values. The source layout is equivalent to:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Dataset A / Accuracy&lt;/th&gt;
&lt;th&gt;Dataset B / Accuracy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cedar&lt;/td&gt;
&lt;td&gt;91&lt;/td&gt;
&lt;td&gt;88&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Birch&lt;/td&gt;
&lt;td&gt;73&lt;/td&gt;
&lt;td&gt;96&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Imagine a converter emits the same cells but reverses the two dataset labels. A Markdown parser will accept it. A test that compares only the set of labels and the set of numbers will accept it too: both sets are unchanged.&lt;/p&gt;

&lt;p&gt;For a regression fixture, record the expected association for each cell, including the row identity and complete header path. Here is a minimal check using Python's standard library. The &lt;code&gt;converted&lt;/code&gt; list stands in for rows produced by your converter; adapt the mapping step to its actual output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Cedar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dataset A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accuracy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"91"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Cedar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dataset B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accuracy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"88"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Birch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dataset A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accuracy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"73"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Birch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dataset B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accuracy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"96"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Deliberately swapped header paths, with the original cell positions.&lt;/span&gt;
&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Dataset B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accuracy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Dataset A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Accuracy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;converted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Cedar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"91"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"88"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Birch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"73"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"96"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;observed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;converted&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;strict&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;observed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cell&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"MISMATCH {cell}: expected {value}, got {observed.get(cell)}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example needs Python 3.10 or later for &lt;code&gt;zip(..., strict=True)&lt;/code&gt;. It reports four mismatches for this fixture. The strict zip catches rows with a different number of cells and headers; it cannot detect a wrong association on its own. The comparison against an independently prepared source expectation is what exposes the swap.&lt;/p&gt;

&lt;p&gt;A production test should also detect unexpected extra rows or columns, duplicate row identifiers, and duplicate header paths before building a dictionary. Otherwise one duplicate can overwrite another. Store a stable row identifier from the fixture when row labels are not unique. Keep raw cell strings for audit, and normalize numbers only under an explicit rule for units, decimal separators, and missing values.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preserve the header path
&lt;/h2&gt;

&lt;p&gt;A multi-level heading is a path, not a single string. In this example, &lt;code&gt;Accuracy&lt;/code&gt; appears twice, so indexing that word alone cannot distinguish the columns. Store the ordered path for each cell, for example &lt;code&gt;['Dataset A', 'Accuracy']&lt;/code&gt;, along with its row key. Flatten it for readable Markdown if needed, but retain the structured path in the intermediate representation.&lt;/p&gt;

&lt;p&gt;Merged cells complicate the mapping. A group label may span several columns, and an empty cell under that label can mean a continuation rather than an absent dataset. Build the path from the table's actual span structure when the extractor provides it. If the structure is ambiguous, preserve the raw location and flag it for review instead of silently filling a guessed label across the row.&lt;/p&gt;

&lt;p&gt;Coordinates can help a reviewer locate the source cell, but a bounding box is not proof that a header was assigned correctly. Keep the document version and page number with the cell and header locations. A changed PDF may shift coordinates even when its displayed values look familiar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test retrieval separately
&lt;/h2&gt;

&lt;p&gt;After conversion passes the structural fixture, index it and ask two paired questions: what is Cedar's accuracy on Dataset A, and what is it on Dataset B? Check the retrieved evidence for both the value and the full header path. Then check the answer and its citation. This separates an extraction error from a retrieval miss or a generation error.&lt;/p&gt;

&lt;p&gt;Also try a negative case: ask for a dataset absent from the table. A system should avoid treating the nearest available column as the requested one. The correct response depends on the rest of the document, so run that test against a controlled fixture whose complete contents are known.&lt;/p&gt;

&lt;p&gt;Header-path tests cost more to prepare than a Markdown syntax check because someone must establish the expected mapping from the source. Keep a small set of reviewed examples across layouts, then run both kinds of check after converter changes. When a fixture fails, the specific row and header path point directly to the relationship that needs inspection.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>python</category>
      <category>testing</category>
    </item>
    <item>
      <title>A PDF table can lose its dataset labels: a Markdown conversion check</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Mon, 23 Nov 2026 15:18:25 +0000</pubDate>
      <link>https://dev.to/kolmopdf/a-pdf-table-can-lose-its-dataset-labels-a-markdown-conversion-check-5g21</link>
      <guid>https://dev.to/kolmopdf/a-pdf-table-can-lose-its-dataset-labels-a-markdown-conversion-check-5g21</guid>
      <description>&lt;p&gt;A PDF can contain a table that looks obvious on screen and becomes ambiguous in a Markdown file. Consider a results table with two columns named "Accuracy" under different dataset headings. If the parent headings disappear, both values survive, but a retrieval system can no longer tell which dataset each value describes.&lt;/p&gt;

&lt;p&gt;A useful first conversion test is to take a small, authorized document with a representative table through &lt;a href="https://www.kolmopdf.com/pdf-to-markdown" rel="noopener noreferrer"&gt;KolmoPDF's PDF-to-Markdown page&lt;/a&gt;, then compare the output with the source. The goal is to find out whether the extracted structure is usable for the questions your application needs to answer. This walkthrough uses an illustrative table; the examples below are test fixtures, not output from a particular PDF.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick a page that can fail in a meaningful way
&lt;/h2&gt;

&lt;p&gt;Choose a page with at least one of these features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A table with grouped headers, units, or footnote markers.&lt;/li&gt;
&lt;li&gt;Two text columns with a figure caption between them.&lt;/li&gt;
&lt;li&gt;A formula whose subscripts or superscripts change its meaning.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Record the document name, page number, and what a correct extraction must preserve. For the example below, the expected relationship is that each accuracy value belongs to a specific dataset and model. The source table has this shape:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Model&lt;/th&gt;
&lt;th&gt;Dataset A accuracy&lt;/th&gt;
&lt;th&gt;Dataset B accuracy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cedar&lt;/td&gt;
&lt;td&gt;91%&lt;/td&gt;
&lt;td&gt;84%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Maple&lt;/td&gt;
&lt;td&gt;88%&lt;/td&gt;
&lt;td&gt;90%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Imagine the PDF uses a two-level header: "Dataset A" and "Dataset B" above separate cells that each read "Accuracy". The names Cedar and Maple and the values are invented for this test. They are deliberately similar enough that a misplaced header changes the answer without producing an obviously invalid number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Convert and inspect the Markdown
&lt;/h2&gt;

&lt;p&gt;Open the &lt;a href="https://www.kolmopdf.com/pdf-to-markdown" rel="noopener noreferrer"&gt;PDF-to-Markdown tool&lt;/a&gt;, select an authorized PDF, and run the conversion. Once the Markdown is available, inspect the section containing the chosen page alongside the original PDF. KolmoPDF supports technical PDF conversion with tables, formulas, code blocks, and multi-column layouts; individual results still need checking against the source.&lt;/p&gt;

&lt;p&gt;A usable representation of the fixture could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| Model | Dataset A accuracy | Dataset B accuracy |
| --- | --- | --- |
| Cedar | 91% | 84% |
| Maple | 88% | 90% |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This alternative keeps the values but loses the dataset labels:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| Model | Accuracy | Accuracy |
| --- | --- | --- |
| Cedar | 91% | 84% |
| Maple | 88% | 90% |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A renderer can display both tables. A downstream system receiving the second one cannot reliably answer which Cedar value belongs to Dataset B without recovering the missing context. If a footnote changes the meaning of a value, check that the marker and its note survive too. An intact number alone is not a sufficient pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn the page into a regression fixture
&lt;/h2&gt;

&lt;p&gt;Keep the original PDF and converted Markdown under the same document version. For documents you have permission to retain, record the page number and the expected facts in a small test file. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"document"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"example-results-v1.pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"question"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"What is Cedar's accuracy on Dataset B?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"expected_answer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"84%"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"required_context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Cedar"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Dataset B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"accuracy"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The page number here is illustrative. A real fixture should use the actual source page and values. Compare the converted content with the source before using it as a reference: otherwise the test can preserve the same mistake as the conversion.&lt;/p&gt;

&lt;p&gt;For retrieval, inspect the exact chunk returned for the question. It should contain the model, the dataset label, and the value together, or carry a reference that lets your application reconstruct that relationship. If a chunk holds only &lt;code&gt;Cedar | 91% | 84%&lt;/code&gt;, the answer generator may guess which column is which. Repeat the table header with row groups when splitting a long table, while retaining the original page reference separately.&lt;/p&gt;

&lt;p&gt;For formulas, use the same principle: compare the extracted expression with the page and check the symbols that distinguish the quantities. A visually plausible formula with a missing subscript can describe a different variable. For multi-column pages, read across the extracted paragraph boundaries and check that a caption has not interrupted a sentence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decide what happens when the check fails
&lt;/h2&gt;

&lt;p&gt;A failed example can go into a review queue with the page reference and the affected passage. Correct the Markdown against the PDF before indexing that passage, or exclude it until someone can verify it. Keep the uncorrected conversion as well as the correction if you need to trace the decision later.&lt;/p&gt;

&lt;p&gt;Run the same fixture after changing conversion settings or chunking rules. Check both the extracted relationship and the retrieval result: a correct Markdown table can still lose its header during chunking. For multi-page tables, also inspect whether a continuation retains the right headings and notes. The &lt;a href="https://dev.to/kolmopdf/a-pdf-table-can-keep-every-number-and-still-break-retrieval-an-audit-workflow-2mci"&gt;table audit workflow&lt;/a&gt; covers that downstream check in more detail.&lt;/p&gt;

&lt;p&gt;KolmoPDF also provides &lt;a href="https://www.kolmopdf.com/api-docs" rel="noopener noreferrer"&gt;API documentation&lt;/a&gt; for workflows that need programmatic access. Start with the web comparison when building the fixture, then apply the same acceptance checks to the integration you choose. Processing is online by default, so use documents you are authorized to upload.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>markdown</category>
      <category>rag</category>
      <category>testing</category>
    </item>
    <item>
      <title>PDF table notes on the next page can corrupt RAG answers</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Sun, 22 Nov 2026 15:19:55 +0000</pubDate>
      <link>https://dev.to/kolmopdf/pdf-table-notes-on-the-next-page-can-corrupt-rag-answers-2agm</link>
      <guid>https://dev.to/kolmopdf/pdf-table-notes-on-the-next-page-can-corrupt-rag-answers-2agm</guid>
      <description>&lt;p&gt;A table ends at the bottom of page 4. Page 5 starts with two more rows, followed by a note saying one value excludes maintenance. A PDF extractor may return both pages cleanly while leaving the second page's rows without the header or attaching the note to every row. A search result can then return the right number with the wrong qualification.&lt;/p&gt;

&lt;p&gt;Consider this invented input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page 4: Table 2. Latency (ms)
System   Median   P95
A        12       28
B        18       42*

Page 5:
C        21       51
* B P95 excludes scheduled maintenance.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A row-only chunk for B that contains &lt;code&gt;B 18 42&lt;/code&gt; cannot answer whether 42 includes maintenance. A chunk for C must not inherit the exclusion. The desired representation ties the note to B's P95 cell and keeps the page on which each piece appeared. This example is a test fixture, not a measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep source fragments before merging
&lt;/h2&gt;

&lt;p&gt;Extract page-local blocks first. Store each row's source page and bounding box alongside its cells. Preserve the original marker on the cell and capture the note as a separate object with its own page and bounding box. If your parser already provides stable block IDs, retain those too. The source location is useful when someone needs to inspect the PDF after a failed answer.&lt;/p&gt;

&lt;p&gt;A continuation detector can propose a link from the first table fragment to the second. Column alignment, a matching caption or an explicit "continued" label provide evidence. A page break by itself is weak evidence: the next page might start a different table with the same number of columns. A repeated header helps, but it can also occur in a separate table. Keep a proposed link distinct from a confirmed one and send ambiguous cases to review.&lt;/p&gt;

&lt;p&gt;The note needs a separate scope decision. Here the &lt;code&gt;*&lt;/code&gt; marker occurs on B's P95 cell, and the note explicitly names the same system and column. If the note merely said &lt;code&gt;* Excludes maintenance&lt;/code&gt;, the marker would still be evidence for the cell-level link. If the marker is missing or appears on several cells, retain the unresolved note instead of applying it to the entire table. A note printed below a table can qualify the whole table, a column, a row or an individual cell; position alone cannot settle every case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build retrieval chunks from relationships
&lt;/h2&gt;

&lt;p&gt;Represent each cell with its row label, column label and source page. Attach a note only through an explicit scope link. When producing a retrieval chunk, include the headers and the notes attached to its cells. Keep the note's page as a second citation rather than assigning it to the row's page.&lt;/p&gt;

&lt;p&gt;For the fixture above, a compact result could look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"table"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Table 2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"cell"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"column"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"P95"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"unit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ms"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"B P95 excludes scheduled maintenance."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"page"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a proposed downstream shape. It does not imply that a particular extractor returns these fields. In production, also keep a document identifier and a link to the original row and note blocks. For C, emit an empty notes list if its scope has been resolved and no note applies. If scope is unresolved, expose that state separately; an empty list should not conceal uncertainty.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the boundary, not just the answer
&lt;/h2&gt;

&lt;p&gt;Create a small set of page-pair fixtures and check the intermediate records as well as the final response. Start with the example above, then change just one detail at a time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move the marker from B to C. The note should follow the marked cell; it should disappear from B's chunk.&lt;/li&gt;
&lt;li&gt;Remove the marker. The note should remain available for review and should not silently attach to either row.&lt;/li&gt;
&lt;li&gt;Put a different table at the top of page 5 with similar columns. The pipeline should not merge it solely because the columns line up.&lt;/li&gt;
&lt;li&gt;Repeat the header on page 5. Each row chunk should retain the header while preserving its actual source page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a retrieval test, ask for B's P95 and its qualification. Check that the retrieved material contains both &lt;code&gt;42 ms&lt;/code&gt; and the exclusion, and that the cited pages point to the value and the note. Ask the same question for C and verify that the exclusion is absent. If the pipeline cannot resolve the relationship, a response that flags the missing scope is safer than a confident answer with the wrong qualifier.&lt;/p&gt;

&lt;p&gt;These checks extend the earlier &lt;a href="https://dev.to/kolmopdf/a-pdf-table-can-keep-every-number-and-still-break-retrieval-an-audit-workflow-2mci"&gt;table audit workflow&lt;/a&gt; across page boundaries. Keep the page-local evidence even after constructing a logical table: reviewers need it to distinguish a bad continuation link from a bad note assignment.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>markdown</category>
      <category>python</category>
    </item>
    <item>
      <title>PDF table footnotes can silently attach to the wrong row in RAG</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Tue, 17 Nov 2026 15:19:12 +0000</pubDate>
      <link>https://dev.to/kolmopdf/pdf-table-footnotes-can-silently-attach-to-the-wrong-row-in-rag-5eee</link>
      <guid>https://dev.to/kolmopdf/pdf-table-footnotes-can-silently-attach-to-the-wrong-row-in-rag-5eee</guid>
      <description>&lt;p&gt;A PDF table can survive extraction with every number intact and still answer a question incorrectly. Consider two rows with the same measurement. Only the first has a superscript &lt;code&gt;a&lt;/code&gt;, and the note says that its value was measured under a reduced load. If a pipeline attaches that note to every row, the second result acquires a condition the source never gave it.&lt;/p&gt;

&lt;p&gt;The reverse error is just as easy: keep the number, drop the marker, and present a conditional result as unconditional. Both errors can survive a text-only check that confirms the table's values are present.&lt;/p&gt;

&lt;h2&gt;
  
  
  A small fixture for a large failure
&lt;/h2&gt;

&lt;p&gt;Use a synthetic table with repeated values so a test cannot pass by matching the number alone:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;Throughput (MB/s)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;95ᵃ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;a&lt;/code&gt;: measured with reduced load.&lt;/p&gt;

&lt;p&gt;A correct representation associates the note with A's measurement. B has no such qualifier in this fixture. A retrieval test should ask the same question for each system: "Under what conditions was its throughput measured?" For A, the retrieved context should contain the reduced-load note. For B, it should not imply that the note applies; the right answer can say that the fixture does not specify a condition for B.&lt;/p&gt;

&lt;p&gt;The equal values are deliberate. If the pipeline finds &lt;code&gt;95&lt;/code&gt; for both rows, a test that checks only the numeric answer will miss the scope error. Inspect the retrieved context and the answer separately: a generator can omit an available qualifier, while an extractor can lose it before retrieval ever starts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep links before making chunks
&lt;/h2&gt;

&lt;p&gt;Treat a marker as a relationship with an explicit target. A practical intermediate record might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"table_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"p4-t1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"cells"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"a-throughput"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"A"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"column"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Throughput (MB/s)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"95"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"markers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"b-throughput"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"B"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"column"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Throughput (MB/s)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"95"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"markers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"note-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"marker"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"measured with reduced load"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"note_links"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"note_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"note-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"target_cell_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"a-throughput"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a proposed intermediate format, not a claim about the output of a particular parser. A real document may use a marker on a row label, column heading, or table title. Store the intended scope at the appropriate level, with the source page and location when available. A note applying to a whole table should be represented as a table-level relationship rather than copied into each cell as though it were a cell-specific annotation.&lt;/p&gt;

&lt;p&gt;For row-based retrieval, include the applicable note in the chunk containing A's measurement. Keep the note's identifier or source reference too, so an audit can trace the added context back to the PDF. B's chunk should have its header, row label, value, and citation, but should not acquire note &lt;code&gt;a&lt;/code&gt; from A's cell.&lt;/p&gt;

&lt;p&gt;The marker &lt;code&gt;a&lt;/code&gt; alone is not a global identifier. Another table can reuse it for a different note. Resolve markers within their table and document context, and keep the document version in the source reference. A page number is useful for locating the evidence, but it is not enough to identify which cell a note qualifies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handle uncertain associations explicitly
&lt;/h2&gt;

&lt;p&gt;Extractors can confuse a superscript with a regular character, and a note may continue onto the next page. If you cannot resolve the target with confidence, keep the marker and its candidate note in a review queue. Avoid silently attaching the note to every row. Also avoid deleting the unresolved marker, because that removes evidence that the value might carry a qualification.&lt;/p&gt;

&lt;p&gt;Review needs the rendered page as well as extracted text. Check where the marker appears, where the note starts, and whether a heading or border indicates a broader scope. When a table spans pages, inspect the continuation before assuming the note belongs to the nearest visible row.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test extraction and retrieval separately
&lt;/h2&gt;

&lt;p&gt;For the fixture above, assert that the intermediate graph has one &lt;code&gt;note-a&lt;/code&gt; link to &lt;code&gt;a-throughput&lt;/code&gt; and none to &lt;code&gt;b-throughput&lt;/code&gt;. Then index the row chunks and run both questions. Record the retrieved chunk IDs, the note links included in each chunk, and the final answer. Add a second fixture with a table-wide note to check that legitimate broad scope survives.&lt;/p&gt;

&lt;p&gt;A useful production sample includes unmarked rows, repeated marker letters in separate tables, and at least one note that crosses a page boundary. Label the intended scope from the rendered source before comparing parser versions. That gives a reviewer a way to distinguish a missing note from an over-broad one, without relying on a plausible-looking answer.&lt;/p&gt;

&lt;p&gt;For a related audit of headers and units, see &lt;a href="https://dev.to/kolmopdf/a-pdf-table-can-keep-every-number-and-still-break-retrieval-an-audit-workflow-2mci"&gt;A PDF table can keep every number and still break retrieval&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>python</category>
      <category>markdown</category>
    </item>
    <item>
      <title>A PDF table can keep every number and still break retrieval: an audit workflow</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Mon, 16 Nov 2026 15:18:27 +0000</pubDate>
      <link>https://dev.to/kolmopdf/a-pdf-table-can-keep-every-number-and-still-break-retrieval-an-audit-workflow-2mci</link>
      <guid>https://dev.to/kolmopdf/a-pdf-table-can-keep-every-number-and-still-break-retrieval-an-audit-workflow-2mci</guid>
      <description>&lt;p&gt;A table can survive PDF extraction with every number intact and still become misleading. If the column heading falls off a page or gets attached to the wrong row, a search result may return a plausible value with the wrong unit or reporting period.&lt;/p&gt;

&lt;p&gt;This walkthrough uses &lt;a href="https://www.kolmopdf.com/pdf-to-markdown" rel="noopener noreferrer"&gt;KolmoPDF's PDF-to-Markdown converter&lt;/a&gt; and a small audit fixture to check that a table remains usable for retrieval. The fixture is illustrative, not a claim about a particular conversion result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick a page that can fail
&lt;/h2&gt;

&lt;p&gt;Choose a document you have permission to upload. Find a table with a unit in its heading, a footnote, or rows that continue onto another page. Note its printed page number and PDF page number: front matter can make them different. Keep the original PDF so a reviewer can compare each result with the source.&lt;/p&gt;

&lt;p&gt;For example, suppose the source has this table, with the final row on the following page:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;System&lt;/th&gt;
&lt;th&gt;Latency (ms)&lt;/th&gt;
&lt;th&gt;Error rate (%)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;td&gt;1.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;B&lt;/td&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;td&gt;2.1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C&lt;/td&gt;
&lt;td&gt;110&lt;/td&gt;
&lt;td&gt;0.9&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An extracted row such as &lt;code&gt;B | 95 | 2.1&lt;/code&gt; is incomplete on its own. The values need the column names and units. If the source also qualifies those measurements in a footnote, the qualification belongs in the evidence a reader can inspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Convert and inspect
&lt;/h2&gt;

&lt;p&gt;Open the converter, upload the PDF and convert it to Markdown. The service handles technical layouts including tables and formulas. Download the result and locate the table by its caption or a distinctive row label. Check the rendered Markdown and the raw text: a pipe character inside a cell, for example, can change how a Markdown table renders unless it is escaped.&lt;/p&gt;

&lt;p&gt;Compare the output against the source:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does each value sit under the right heading and unit?&lt;/li&gt;
&lt;li&gt;Do the row labels and values continue in the correct order across a page break?&lt;/li&gt;
&lt;li&gt;Are merged cells, footnotes and qualifiers preserved or clearly represented?&lt;/li&gt;
&lt;li&gt;Can you trace the table back to the original pages?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A continuation page may produce a second table. If it lacks headings, add the original headings to that fragment before indexing, but keep a pointer to the pages from which its rows came. Do not assume two nearby tables are one continuation: compare captions, column structure and surrounding text first. When the source is ambiguous, send it for review instead of joining rows automatically.&lt;/p&gt;

&lt;p&gt;The converter processes documents online. Use an approved workflow for confidential material, and check the output on representative pages before processing a larger collection. Complex layouts and scans deserve particular attention; conversion does not guarantee that every cell or formula will be correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build retrieval chunks around evidence
&lt;/h2&gt;

&lt;p&gt;A chunk containing only &lt;code&gt;B | 95 | 2.1&lt;/code&gt; asks the retrieval system to infer too much. A more useful chunk repeats the table title, heading and relevant note:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Source: report.pdf, PDF page 8
Table: Service measurements
System | Latency (ms) | Error rate (%)
B | 95 | 2.1
Note: Values are from the illustrative fixture.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep provenance in metadata as well as in text if your retrieval system supports it. Use the actual PDF page range for each chunk, including both pages when a row or note crosses a boundary. If the Markdown export does not supply reliable page references, capture them during review rather than assigning a guessed page.&lt;/p&gt;

&lt;p&gt;Repeat headings when splitting a long table into row groups. Keep a footnote with every group it qualifies, and retain the original full table for inspection. For a table with multi-level headings, flatten the heading path explicitly, for example &lt;code&gt;Latency / p95 (ms)&lt;/code&gt;, after checking that it describes the original cell.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test before indexing the collection
&lt;/h2&gt;

&lt;p&gt;Write a few questions with answers you can verify in the PDF. For the fixture above, ask for system B's latency and its unit, then ask which system has an error rate of 0.9%. Check the retrieved chunk before looking at the generated answer. It should contain the correct row, the heading and the source reference. Also ask a question for a value absent from the table; the system should have an opportunity to say the evidence is missing rather than filling in a number.&lt;/p&gt;

&lt;p&gt;Record the failures by type: extraction, table reconstruction, chunking, retrieval or answer generation. A correct answer with the wrong citation still needs work. Re-run the same questions after a parser or chunking change, and include examples from scanned pages and multi-page tables if those appear in your documents.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://dev.to/kolmopdf/kolmopdf-technical-pdf-parsing-and-translation-for-document-workflows-404p"&gt;KolmoPDF product overview&lt;/a&gt; covers the available output types. For a separate check on mixed scanned and text pages, see &lt;a href="https://dev.to/kolmopdf/pdf-rag-misses-scanned-pages-when-ocr-routing-happens-per-file-1dj5"&gt;page-level OCR routing&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>markdown</category>
      <category>ai</category>
    </item>
    <item>
      <title>PDF RAG misses scanned pages when OCR routing happens per file</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Sun, 15 Nov 2026 15:18:21 +0000</pubDate>
      <link>https://dev.to/kolmopdf/pdf-rag-misses-scanned-pages-when-ocr-routing-happens-per-file-1dj5</link>
      <guid>https://dev.to/kolmopdf/pdf-rag-misses-scanned-pages-when-ocr-routing-happens-per-file-1dj5</guid>
      <description>&lt;p&gt;A PDF can contain selectable text on one page and only a scanned image on the next. If an ingestion pipeline chooses extraction once per file, the scanned page can quietly enter the index as an empty string. A search result then jumps from page 8 to page 10, and the answer on page 9 is never available to retrieve.&lt;/p&gt;

&lt;p&gt;A page-level routing decision catches that failure without paying the OCR cost for every page. It also needs an escape hatch: a page with selectable text can still have a broken character map or an image containing the actual answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with page-level evidence
&lt;/h2&gt;

&lt;p&gt;For each page, keep the extracted text, the page number, and a few signals from the parser: character count, image coverage if available, and a sample of the output. A blank page and a scanned page may both yield zero characters. The difference is visible in the rendered page, so send low-text pages for inspection or OCR rather than declaring them empty.&lt;/p&gt;

&lt;p&gt;The following router illustrates the decision. Its input is a page record produced by your PDF extraction and rendering stages; it does not inspect a PDF by itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;choose_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"inspect_or_ocr"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"image_contains_content"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"text_plus_image_review"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"text_quality"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"unknown"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"text_review"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"native_text"&lt;/span&gt;

&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;choose_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"inspect_or_ocr"&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;choose_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"image_contains_content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"text_plus_image_review"&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;choose_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text_quality"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"native_text"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The defaults are deliberate. A short text layer saying "Page 9" does not prove the rest of the page was extracted. A quality classifier or a reviewer must supply the &lt;code&gt;text_quality&lt;/code&gt; and &lt;code&gt;image_contains_content&lt;/code&gt; flags; the function cannot infer them from a character count. For a page containing a diagram with labels, retain both native text and the image-derived result until a later step can reconcile them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep both versions when OCR runs
&lt;/h2&gt;

&lt;p&gt;OCR can introduce errors too. A decimal point, minus sign, or subscript may disappear, and a two-column page may come back in the wrong order. Preserve the native extraction and OCR output separately, along with their source page and processing version. Pick a representation for indexing, but retain the other for review. Avoid concatenating both versions blindly: duplicate passages can crowd the top search results and make repeated text look like independent evidence.&lt;/p&gt;

&lt;p&gt;For example, an extracted page might have a header and footer as native text while the body is a scan. Indexing only the native layer loses the body. Replacing the whole page with OCR can instead degrade a correctly encoded formula in the header. A region-aware merge can retain each source where it works, provided the pipeline records which region came from which method. If region matching is unreliable, flag the page for review instead of guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the route and the answer
&lt;/h2&gt;

&lt;p&gt;Build a small fixture set from documents you are allowed to process. Include an image-only page, a genuinely blank page, a scan with a selectable page number, and a page where native text and an image both carry content. Add a page with corrupted selectable text if your corpus contains one. Record the expected route and the page location for each fixture.&lt;/p&gt;

&lt;p&gt;Then ask answerable questions whose evidence lies on those pages. Measure two things separately: whether the route selected the intended processing path, and whether retrieval returned the page containing the evidence. A correct route can still produce bad OCR. A retrieved page can still contain the wrong number. For numeric answers, compare the retrieved text against the page image before accepting it as ground truth.&lt;/p&gt;

&lt;p&gt;When comparing configurations, hold the fixture set and retrieval settings fixed. Count pages sent to OCR, reviewed pages, missing evidence, and incorrect extracted values. These counts expose the cost of aggressive OCR alongside the failures caused by a permissive native-text route. Actual latency and charges depend on the OCR provider and document mix, so measure them on your own corpus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Store the decision with the chunk
&lt;/h2&gt;

&lt;p&gt;Attach a document identifier, source page number, extraction method, and processing version to every indexed chunk. If the page was flagged for review, keep that status too. A citation should lead back to the page image, not just the OCR text, so a reader can check a questionable symbol in context.&lt;/p&gt;

&lt;p&gt;This extends the page-boundary approach in &lt;a href="https://dev.to/kolmopdf/pdf-rag-citations-break-when-chunks-lose-page-boundaries-kh7"&gt;PDF RAG citations break when chunks lose page boundaries&lt;/a&gt;. Page provenance tells you where a chunk came from; the routing record tells you how its text was obtained and which pages need another look.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>python</category>
      <category>ocr</category>
    </item>
    <item>
      <title>PDF RAG citations break when chunks lose page boundaries</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Sat, 14 Nov 2026 15:18:19 +0000</pubDate>
      <link>https://dev.to/kolmopdf/pdf-rag-citations-break-when-chunks-lose-page-boundaries-kh7</link>
      <guid>https://dev.to/kolmopdf/pdf-rag-citations-break-when-chunks-lose-page-boundaries-kh7</guid>
      <description>&lt;p&gt;A retrieval result can contain the correct sentence and still send a reader to the wrong page. One common cause is a document pipeline that concatenates extracted text, splits it into chunks, and calculates citations afterward. Once the page boundaries are gone, matching a chunk back to the PDF becomes guesswork, especially when headers and repeated phrases appear on several pages.&lt;/p&gt;

&lt;p&gt;Keep page references attached to extracted blocks before chunking. Then carry those references forward when blocks are merged. This also gives an evaluator somewhere concrete to look when a retrieved answer is wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The page-break trap
&lt;/h2&gt;

&lt;p&gt;Imagine a report whose final paragraph on page 4 continues on page 5:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Page 4: The device operates at a maximum pressure of
Page 5: 12 bar when the ambient temperature is below 40 C.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A useful chunk may contain both lines. Labeling it only &lt;code&gt;page=4&lt;/code&gt; points to the beginning but hides the page containing the actual limit. Labeling it &lt;code&gt;page=5&lt;/code&gt; loses the start. Store the ordered set &lt;code&gt;[4, 5]&lt;/code&gt;, and preserve the original block references for more precise inspection. The example uses PDF physical page numbers, counted from one; printed page labels may differ, particularly in documents with front matter.&lt;/p&gt;

&lt;p&gt;There is a second trap: a single PDF page may have several text regions. A passage assembled from a caption and a paragraph needs the source regions for both. Bounding boxes help locate those regions, but coordinate conventions vary between extraction tools. Record the coordinate system and page rotation with the boxes; do not assume a box from one tool can be drawn unchanged by another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Carry references through chunking
&lt;/h2&gt;

&lt;p&gt;The following Python example accepts already ordered blocks. It groups them by a character budget and carries page and block IDs into each chunk. The budget is illustrative; model token counts differ from character counts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;

&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Block&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;block_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;make_chunks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Block&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_chars&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;max_chars&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"max_chars must be positive"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;chunks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"pages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromkeys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"block_ids"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;block_id&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="n"&gt;added&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;added&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;max_chars&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;flush&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;


&lt;span class="n"&gt;blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;Block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"p4-b7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"The device operates at a maximum pressure of"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Block&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"p5-b1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"12 bar when the ambient temperature is below 40 C."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_chunks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blocks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_chars&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pages"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"block_ids"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"p4-b7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"p5-b1"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A block larger than the budget is emitted intact in this example. In production, split oversized blocks separately, preferably at sentence boundaries, while retaining their original block ID and offsets. The function also assumes that the extraction stage has already determined a sensible reading order. Provenance records where the text came from; it does not repair scrambled columns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which citation should the answer show?
&lt;/h2&gt;

&lt;p&gt;Store the full reference list with the indexed chunk, then select the relevant source when presenting an answer. If the answer uses both halves of the pressure limit above, cite both pages. For a large chunk spanning several pages, citing all of them can be technically traceable but inconvenient. Smaller blocks or sentence-level offsets let the interface narrow the citation to the supporting passage.&lt;/p&gt;

&lt;p&gt;Keep the original PDF and an extraction version identifier alongside the chunk metadata. Page 5 in a revised edition can contain different text, so a document title alone is insufficient for reproducible citations. A content hash can identify the exact file; access controls still need to follow the source document through the index and citation viewer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the boundary, not just the answer
&lt;/h2&gt;

&lt;p&gt;Build a small fixture set with a paragraph crossing a page break, repeated running headers, and a printed page label that differs from the physical page number. For each expected answer, record the supporting block IDs and physical pages. Run retrieval and check both whether the supporting text was returned and whether the citation points to those blocks. A correct answer with a wrong reference should fail the citation check.&lt;/p&gt;

&lt;p&gt;Also inspect the opposite failure: the citation opens the right page but the extracted sentence combines unrelated columns. That needs a reading-order fix upstream, not a citation formatter. For a related example of column-order pitfalls, see &lt;a href="https://dev.to/kolmopdf/why-naive-text-extraction-destroys-rag-on-multi-column-pdfs-and-how-to-fix-reading-order-404a"&gt;this walkthrough of multi-column extraction&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>python</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Translating Technical and Scanned PDFs Without Breaking Equations, Tables, or Domain Terms</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Fri, 13 Nov 2026 15:23:39 +0000</pubDate>
      <link>https://dev.to/kolmopdf/translating-technical-and-scanned-pdfs-without-breaking-equations-tables-or-domain-terms-35f7</link>
      <guid>https://dev.to/kolmopdf/translating-technical-and-scanned-pdfs-without-breaking-equations-tables-or-domain-terms-35f7</guid>
      <description>&lt;p&gt;&lt;em&gt;This article is part of the "KolmoPDF: Product Guides &amp;amp; Updates" series. For a full map of parsing, translation, and API capabilities, read the &lt;a href="https://dev.to/kolmopdf/kolmopdf-technical-pdf-parsing-and-translation-for-document-workflows-404p"&gt;series overview&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Plain document translators handle single-column letters well, then fall apart on technical PDFs. A scanned specification sheet has no text layer, so text-based tools return blank pages or blocks of broken characters. A two-column paper reflows into a single stream, detaching figure captions from their charts and scrambling table cells. Inline equations fare worst of all: variables like &lt;code&gt;$d_k$&lt;/code&gt;, subscripts, and operator names get translated literally or dropped into missing-glyph boxes.&lt;/p&gt;

&lt;p&gt;Automation introduces a second trap. Requesting both a translated PDF and a bilingual side-by-side PDF in a single API call causes the server to bundle both files into a ZIP archive. Writing those response bytes straight to &lt;code&gt;output.pdf&lt;/code&gt; produces a file that every PDF viewer flags as damaged.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing between layout PDFs and translated Markdown
&lt;/h2&gt;

&lt;p&gt;KolmoPDF exposes two distinct translation paths that share the same account credit balance and the same 300 MB / 800-page file limits:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://www.kolmopdf.com/pdf-translation" rel="noopener noreferrer"&gt;PDF Translation&lt;/a&gt; (&lt;code&gt;POST /api/v1/jobs/translate-pdf&lt;/code&gt;) costs &lt;strong&gt;2 credits per page&lt;/strong&gt; across any pair of 9 supported languages (English, Simplified Chinese, Japanese, Korean, French, German, Spanish, Russian, and Portuguese). It rebuilds the document as a translated PDF, a bilingual PDF, or a ZIP containing both. Use this path when engineers, patent reviewers, or study groups need to read translated pages alongside the original tables, figures, and pagination.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.kolmopdf.com/pdf-to-markdown" rel="noopener noreferrer"&gt;PDF to Markdown&lt;/a&gt; (&lt;code&gt;POST /api/v1/jobs/parse&lt;/code&gt; with &lt;code&gt;enable_translation=true&lt;/code&gt;) costs &lt;strong&gt;3 credits per page&lt;/strong&gt; (compared to 2 credits per page without translation). It outputs Markdown with GitHub-flavored pipe tables and LaTeX math blocks, controlled by &lt;code&gt;output_options&lt;/code&gt; (&lt;code&gt;original&lt;/code&gt;, &lt;code&gt;translated&lt;/code&gt;, or &lt;code&gt;bilingual&lt;/code&gt;). Use this path when the text is going into Obsidian, Notion, or a RAG ingestion pipeline.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;New accounts start with 300 free credits on signup plus 50 daily check-in credits, and one-time Pay-As-You-Go packs run $3 per 1,000 credits without a subscription. Both paths accept native digital PDFs and scanned page stacks directly. Because the underlying Visual Language Model treats each page as image regions, scanned PDFs do not require an Adobe Acrobat OCR pass beforehand.&lt;/p&gt;

&lt;h2&gt;
  
  
  What survives in a real two-column paper
&lt;/h2&gt;

&lt;p&gt;On the public &lt;a href="https://www.kolmopdf.com/pdf-translation" rel="noopener noreferrer"&gt;Attention Is All You Need showcase&lt;/a&gt;, KolmoPDF processes the 15-page &lt;code&gt;arXiv:1706.03762v7&lt;/code&gt; paper (Vaswani et al., 2017). Comparing the &lt;a href="https://www.kolmopdf.com/showcase/attention/downloads/original.md" rel="noopener noreferrer"&gt;parsed English Markdown&lt;/a&gt; with the &lt;a href="https://www.kolmopdf.com/showcase/attention/downloads/zh-bilingual.md" rel="noopener noreferrer"&gt;bilingual Markdown output&lt;/a&gt; shows how mathematical tokens and section structure behave during translation.&lt;/p&gt;

&lt;p&gt;In Section 3.1, the original English paragraph reads:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Encoder:&lt;/strong&gt; The encoder is composed of a stack of $N = 6$ identical layers. Each layer has two sub-layers. The first is a multi-head self-attention mechanism, and the second is a simple, position-wise fully connected feed-forward network. We employ a residual connection [11] around each of the two sub-layers, followed by layer normalization [1]. That is, the output of each sub-layer is $\text{LayerNorm}(x + \text{Sublayer}(x))$, where $\text{Sublayer}(x)$ is the function implemented by the sub-layer itself. To facilitate these residual connections, all sub-layers in the model, as well as the embedding layers, produce outputs of dimension $d_{\text{model}} = 512$.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the bilingual output, the Chinese translation preserves every math token, citation number, and LaTeX expression intact inside the translated sentence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;编码器：&lt;/strong&gt; 编码器由 $N = 6$ 个相同层的堆叠组成。每个层包含两个子层。第一个是多头自注意力机制，第二个是简单的逐位置全连接前馈网络。我们在每个子层周围使用残差连接 [11]，随后进行层归一化 [1]。也就是说，每个子层的输出是 $\text{LayerNorm}(x + \text{Sublayer}(x))$，其中 $\text{Sublayer}(x)$ 是由子层自身实现的功能。为了促进这些残差连接，模型中的所有子层以及嵌入层都生成维度为 $d_{\text{model}} = 512$ 的输出。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Display equations such as Scaled Dot-Product Attention (&lt;code&gt;\text{Attention}(Q, K, V) = \text{softmax}(\frac{QK^T}{\sqrt{d_k}})V&lt;/code&gt;) and figure captions (&lt;code&gt;Figure 1&lt;/code&gt; / &lt;code&gt;图1&lt;/code&gt;) stay aligned to their surrounding prose rather than getting stripped or reflowed across columns.&lt;/p&gt;

&lt;p&gt;By default, text inside embedded raster figures and tables stays untouched unless you opt in. On the web form and in the API, &lt;code&gt;enable_table_translation&lt;/code&gt; translates text inside tables and &lt;code&gt;enable_image_translation&lt;/code&gt; translates text inside charts and diagrams. Both options increase processing time per page, so leave them off when table headers or chart labels are standard symbols you want left in the source language.&lt;/p&gt;

&lt;h2&gt;
  
  
  Locking domain terminology with a CSV glossary
&lt;/h2&gt;

&lt;p&gt;Technical manuals and datasheets often fail on consistency rather than grammar. A product codename or medical term translated one way on page 2 and another way on page 19 creates confusion during review.&lt;/p&gt;

&lt;p&gt;Both the web translator and &lt;code&gt;POST /api/v1/jobs/translate-pdf&lt;/code&gt; accept a UTF-8 CSV &lt;code&gt;glossary&lt;/code&gt; file (up to 2 MB). The header row uses standard two-letter language codes from the 9 supported languages (&lt;code&gt;en,zh,ja,ko,fr,de,es,ru,pt&lt;/code&gt;), and each row pairs the source term with your preferred translation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;en,zh
LayerNorm,LayerNorm
Multi-Head Attention,多头注意力机制
Scaled Dot-Product Attention,缩放点积注意力
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uploading that CSV keeps brand identifiers, untranslated symbol names, and domain vocabulary fixed across the entire document.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calling &lt;code&gt;translate-pdf&lt;/code&gt; safely from Python
&lt;/h2&gt;

&lt;p&gt;All endpoints live under the base URL &lt;code&gt;https://www.kolmopdf.com&lt;/code&gt; and authenticate via &lt;code&gt;Authorization: Bearer &amp;lt;KOLMOPDF_API_KEY&amp;gt;&lt;/code&gt;. You can generate a key from &lt;a href="https://www.kolmopdf.com/api-keys" rel="noopener noreferrer"&gt;API Management&lt;/a&gt; on any plan, including Free.&lt;/p&gt;

&lt;p&gt;Jobs run asynchronously. Creating a job returns HTTP &lt;code&gt;202 Accepted&lt;/code&gt; with a &lt;code&gt;job_...&lt;/code&gt; ID and &lt;code&gt;links.self&lt;/code&gt;. Passing a unique &lt;code&gt;Idempotency-Key&lt;/code&gt; header per submission guarantees that network retries do not double-charge credits. Each API key supports up to 3 concurrent running jobs, and finished result files remain downloadable for 7 days.&lt;/p&gt;

&lt;p&gt;The critical client-side rule is never to assume the download extension. When &lt;code&gt;layoutModes&lt;/code&gt; has a single mode (&lt;code&gt;translated_only&lt;/code&gt; or &lt;code&gt;side_by_side&lt;/code&gt;), &lt;code&gt;result.kind&lt;/code&gt; is usually &lt;code&gt;pdf&lt;/code&gt;. When both modes are requested, &lt;code&gt;result.kind&lt;/code&gt; is &lt;code&gt;zip&lt;/code&gt;. Always read &lt;code&gt;result.filename&lt;/code&gt; and &lt;code&gt;result.kind&lt;/code&gt; from the succeeded job payload before writing to disk:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;BASE_URL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.kolmopdf.com"&lt;/span&gt;
&lt;span class="no"&gt;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KOLMOPDF_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="no"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Set KOLMOPDF_API_KEY in your environment first."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="no"&gt;HEADERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {API_KEY}"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;translate_pdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;pdf_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;source_lang&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;target_lang&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"zh"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;layout_modes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"translated_only,side_by_side"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;glossary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;translate_tables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;translate_images&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdf_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;glossary_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"glossary"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;glossary_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"sourceLanguage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;source_lang&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"targetLanguage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;target_lang&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"layoutModes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;layout_modes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"enable_table_translation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;translate_tables&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"enable_image_translation"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;translate_images&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;create_headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"Idempotency-Key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{BASE_URL}/api/v1/jobs/translate-pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;create_headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;finally&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fh&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;job_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{BASE_URL}{job['links']['self']}"&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Created job {job['id']} ({job['points_deducted']} credits deducted)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"queued"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"processing"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;poll&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;poll&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;poll&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"succeeded"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Job {job['id']} failed: {err}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;out_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"filename"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;
    &lt;span class="n"&gt;download_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{BASE_URL}{result['download_url']}"&lt;/span&gt;

    &lt;span class="n"&gt;dl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;download_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;dl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Guard against saving a ZIP bundle under a .pdf name&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"zip"&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;out_name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".zip"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;out_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{Path(out_name).stem}.zip"&lt;/span&gt;

    &lt;span class="n"&gt;out_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;out_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;out_path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Saved {out_path} (kind={result['kind']}, bytes={len(dl.content)})"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out_path&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;translate_pdf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"paper.pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;glossary_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"glossary.csv"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For interactive terminal or coding-agent workflows, you can skip writing boilerplate by installing the standalone agent skill (&lt;code&gt;npx skills add komoai2026/kolmopdf-skill&lt;/code&gt;), which wraps the same Jobs API endpoints and ZIP handling via Node.js 20+. For long CLI jobs, the API also provides a Server-Sent Events stream at &lt;code&gt;GET /api/v1/jobs/{id}/events&lt;/code&gt; so clients do not have to poll.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification boundaries before citing or batching
&lt;/h2&gt;

&lt;p&gt;Layout translation preserves surrounding typography and restores LaTeX formulas, yet dense scanned equations can still misread a tiny index such as &lt;code&gt;d_k&lt;/code&gt; vs &lt;code&gt;d_v&lt;/code&gt;. Check subscripts, superscripts, and equation numbers against the source PDF before citing numbers or reusing a translated passage.&lt;/p&gt;

&lt;p&gt;Turning on &lt;code&gt;enable_image_translation&lt;/code&gt; and &lt;code&gt;enable_table_translation&lt;/code&gt; also slows down per-page turnaround, so benchmark runtime and visual alignment on 5 to 10 representative pages before submitting an 800-page manual.&lt;/p&gt;

&lt;p&gt;Finally, standard processing runs online over TLS and does not use uploaded PDFs or translations to train AI models, as stated in the &lt;a href="https://www.kolmopdf.com/privacy-policy" rel="noopener noreferrer"&gt;privacy policy&lt;/a&gt;. If compliance rules prohibit sending confidential internal records to external endpoints, keep those documents local.&lt;/p&gt;

&lt;p&gt;To try a paper in the browser or generate an API key, open &lt;a href="https://www.kolmopdf.com/pdf-translation" rel="noopener noreferrer"&gt;KolmoPDF PDF Translation&lt;/a&gt; and the &lt;a href="https://www.kolmopdf.com/api-docs" rel="noopener noreferrer"&gt;API Guide&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>latex</category>
      <category>api</category>
      <category>python</category>
    </item>
    <item>
      <title>Why Broken Hyphenation and Ligatures Corrupt Technical Embeddings (and How to Normalize PDF Text Streams)</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Thu, 12 Nov 2026 15:26:04 +0000</pubDate>
      <link>https://dev.to/kolmopdf/why-broken-hyphenation-and-ligatures-corrupt-technical-embeddings-and-how-to-normalize-pdf-text-64i</link>
      <guid>https://dev.to/kolmopdf/why-broken-hyphenation-and-ligatures-corrupt-technical-embeddings-and-how-to-normalize-pdf-text-64i</guid>
      <description>&lt;p&gt;&lt;em&gt;This article is part of the **PDF Parsing for RAG&lt;/em&gt;* series. In &lt;a href="https://dev.to/kolmopdf/why-naive-text-extraction-destroys-rag-on-multi-column-pdfs-and-how-to-fix-reading-order-404a"&gt;Part 1&lt;/a&gt;, we resolved multi-column reading order. In &lt;a href="https://dev.to/kolmopdf/why-flattened-pdf-tables-break-rag-and-how-to-preserve-cell-semantics-in-markdown-42dn"&gt;Part 2&lt;/a&gt;, we reconstructed borderless tables. In &lt;a href="https://dev.to/kolmopdf/why-fragmented-formulas-ruin-math-rag-and-how-to-extract-clean-latex-blocks-from-technical-pdfs-3ngf"&gt;Part 3&lt;/a&gt;, we serialized mathematical formulas into LaTeX blocks. In &lt;a href="https://dev.to/kolmopdf/why-disconnected-captions-and-footnotes-break-technical-rag-and-how-to-bind-spatial-annotations-22a6"&gt;Part 4&lt;/a&gt;, we bound floating captions and footnotes. Today we address broken hyphenation, font ligatures, and text stream normalization.*&lt;/p&gt;

&lt;p&gt;When a retrieval-augmented generation (RAG) system fails to retrieve a technical paragraph, engineers usually adjust chunk sizes, tune top-k parameters, or switch embedding models. Yet in many PDF ingestion pipelines, the primary failure occurs before the chunker runs: the raw text stream corrupts key terminology at the character level.&lt;/p&gt;

&lt;p&gt;A search query for "document classification" fails to match a chunk containing the exact definition. When inspecting the vector space, the cosine similarity between the query and the chunk is surprisingly low (often below 0.55 instead of above 0.82). The issue is not semantic distance. In the original PDF, the word appeared at the end of a justified column as &lt;code&gt;classifi-&lt;/code&gt; followed by &lt;code&gt;cation&lt;/code&gt; on the next line. Naive text extractors emit &lt;code&gt;classifi- cation&lt;/code&gt;, which byte-pair encoding (BPE) tokenizers shatter into disconnected subwords.&lt;/p&gt;

&lt;h2&gt;
  
  
  The typography of broken text streams
&lt;/h2&gt;

&lt;p&gt;PDF documents do not store semantic paragraphs. A PDF is a set of display instructions specifying font subsets and glyph placements on a two-dimensional canvas. Two typographic optimizations common in technical publishing routinely corrupt downstream NLP pipelines:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Line-break hyphenation
&lt;/h3&gt;

&lt;p&gt;Typesetting engines like LaTeX and InDesign justify columns by splitting long words across line boundaries. When a word is divided, the engine inserts an ASCII hyphen (0x2D) or a soft hyphen (0xAD) and pushes the remaining syllables to the subsequent line.&lt;/p&gt;

&lt;p&gt;If an extractor preserves the line break literally, the text becomes &lt;code&gt;hyper- parameter&lt;/code&gt;. If the extractor strips line breaks and inserts spaces, the text becomes &lt;code&gt;hyper- parameter&lt;/code&gt;. When tokenized by models such as OpenAI &lt;code&gt;text-embedding-3-large&lt;/code&gt; (cl100k_base) or BGE-large, the split word yields &lt;code&gt;["hyper", "-", "parameter"]&lt;/code&gt; instead of the canonical &lt;code&gt;["hyperparameter"]&lt;/code&gt;. The vector representation shifts away from the semantic center of the intended concept.&lt;/p&gt;

&lt;p&gt;Removing all hyphens unconditionally creates an opposite failure. True hyphenated compounds like &lt;code&gt;state-of-the-art&lt;/code&gt;, &lt;code&gt;trade-off&lt;/code&gt;, &lt;code&gt;cost-effective&lt;/code&gt;, and &lt;code&gt;zero-shot&lt;/code&gt; turn into &lt;code&gt;stateoftheart&lt;/code&gt; and &lt;code&gt;zeroshot&lt;/code&gt;. These concatenated strings do not exist in the tokenizer vocabulary and decompose into arbitrary character chunks.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Typographic ligatures and custom glyph mapping
&lt;/h3&gt;

&lt;p&gt;To improve readability in print, typesetting systems merge adjacent letter pairs into a single combined glyph. The most common pairs are &lt;code&gt;fi&lt;/code&gt;, &lt;code&gt;fl&lt;/code&gt;, &lt;code&gt;ff&lt;/code&gt;, &lt;code&gt;ffi&lt;/code&gt;, and &lt;code&gt;ffl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In digital PDFs, ligatures introduce two failure modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Standard Unicode ligatures: The engine encodes &lt;code&gt;fi&lt;/code&gt; as the single Unicode point &lt;code&gt;\uFB01&lt;/code&gt; (LATIN SMALL LIGATURE FI). While modern LLMs sometimes recognize these code points, many dense embedding models and BM25 tokenizers treat &lt;code&gt;\uFB01&lt;/code&gt; as an out-of-vocabulary character or decompose it into raw UTF-8 bytes. The word &lt;code&gt;definition&lt;/code&gt; (&lt;code&gt;de\uFB01nition&lt;/code&gt;) fails exact-match token lookups.&lt;/li&gt;
&lt;li&gt;Font subsetting and missing CMaps: When a PDF generator embeds a custom font without a valid &lt;code&gt;ToUnicode&lt;/code&gt; mapping table, ligatures are assigned arbitrary glyph indices or mapped to Private Use Area (PUA) code points (&lt;code&gt;\uE000&lt;/code&gt; to &lt;code&gt;\uF8FF&lt;/code&gt;). In these documents, &lt;code&gt;configuration&lt;/code&gt; extracts as &lt;code&gt;con\uE002guration&lt;/code&gt; or &lt;code&gt;con guration&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Invisible control characters and soft hyphens
&lt;/h3&gt;

&lt;p&gt;Soft hyphens (&lt;code&gt;\xad&lt;/code&gt;) mark discretionary break points. In some PDF text streams, soft hyphens remain embedded within words even when the word did not break across lines (&lt;code&gt;"iden\xadti\xfier"&lt;/code&gt;). Zero-width spaces (&lt;code&gt;\u200B&lt;/code&gt;) and non-breaking spaces (&lt;code&gt;\u00A0&lt;/code&gt;) also contaminate token sequences, preventing dense retrievers from matching plain text queries.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tokenization and retrieval impact
&lt;/h2&gt;

&lt;p&gt;The following table demonstrates how character-level corruption alters subword token counts and cosine retrieval scores against the clean query &lt;code&gt;"efficient document classification"&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Input Text Representation&lt;/th&gt;
&lt;th&gt;Subword Tokens (cl100k_base)&lt;/th&gt;
&lt;th&gt;Token Count&lt;/th&gt;
&lt;th&gt;Cosine Similarity vs Query&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;efficient document classification&lt;/code&gt; (Clean)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;['efficient', ' document', ' classification']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;0.884&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;efficient document classifi- cation&lt;/code&gt; (Broken hyphen)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;['efficient', ' document', ' class', 'ifi', '-', ' cation']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;0.612&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;efficient document classiﬁcation&lt;/code&gt; (Unicode ligature &lt;code&gt;\uFB01&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;['efficient', ' document', ' classi', 'ﬁ', 'cation']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;0.731&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;efficient document classi\uE001cation&lt;/code&gt; (PUA glyph)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;['efficient', ' document', ' classi', '&amp;lt;unk&amp;gt;', 'cation']&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;0.548&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The broken hyphen alone reduces retrieval similarity by 0.272, pushing a relevant chunk below standard similarity thresholds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a text normalization pipeline
&lt;/h2&gt;

&lt;p&gt;A resilient PDF ingestion pipeline must normalize text streams before chunking. The process requires three sequential steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Normalize Unicode forms via NFKC to expand standard ligatures.&lt;/li&gt;
&lt;li&gt;Resolve known Private Use Area font glitches.&lt;/li&gt;
&lt;li&gt;Reconnect hyphenated words across line breaks using a lexical heuristic.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is a Python implementation designed for PDF text streams:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;

&lt;span class="c1"&gt;# Common Private Use Area (PUA) ligature mappings found in PDF fonts&lt;/span&gt;
&lt;span class="no"&gt;PUA_LIGATURE_MAP&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"\uE000"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"\uE001"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"\uE002"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"\uE003"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ffi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"\uE004"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ffl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"\uF001"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fi"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"\uF002"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"fl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Common technical compounds that must retain their internal hyphen&lt;/span&gt;
&lt;span class="no"&gt;TRUE_COMPOUNDS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"state-of-the-art"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"cost-effective"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"trade-off"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"trade-offs"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"zero-shot"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"few-shot"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"out-of-domain"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"pre-trained"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"end-to-end"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"cross-validation"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"fine-tuning"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"multi-modal"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;clean_invisible_glyphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Removes soft hyphens, zero-width spaces, and control characters."""&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\xad"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# Soft hyphen&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\u200b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# Zero-width space&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\ufeff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# Byte order mark&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\u00a0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;# Non-breaking space&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;expand_ligatures&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Expands standard Unicode ligatures and resolves known PUA glyphs."""&lt;/span&gt;
    &lt;span class="c1"&gt;# 1. Replace known PUA codes&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;pua_char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;replacement&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;PUA_LIGATURE_MAP&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pua_char&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pua_char&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;replacement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 2. Apply Unicode NFKC normalization (decomposes standard ligatures like \uFB01 to 'fi')&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"NFKC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dehyphenate_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""
    Reconstructs words broken by line-end hyphenation while
    preserving intentional compound words.
    """&lt;/span&gt;
    &lt;span class="c1"&gt;# Regex matches: word-fragment + hyphen + optional whitespace/newline + word-fragment&lt;/span&gt;
    &lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"(\b[A-Za-z]+)-\s*\n\s*([A-Za-z]+\b)"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;replace_hyphen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;part1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;part2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;combined_lower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{part1}{part2}"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;hyphenated_lower&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{part1}-{part2}"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;# Check if the hyphenated version is an intentional technical compound&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;hyphenated_lower&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;TRUE_COMPOUNDS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{part1}-{part2}"&lt;/span&gt;

        &lt;span class="c1"&gt;# If the second part starts with an uppercase letter, keep the hyphen (e.g. Franco-Prussian)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;part2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isupper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{part1}-{part2}"&lt;/span&gt;

        &lt;span class="c1"&gt;# Default action: merge into a single continuous word&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{part1}{part2}"&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replace_hyphen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;normalize_pdf_stream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw_text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Full normalization pipeline for raw PDF extracted text."""&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;clean_invisible_glyphs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;raw_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;expand_ligatures&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;dehyphenate_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# Collapse irregular internal whitespace while preserving paragraph breaks&lt;/span&gt;
    &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"[ \t]+"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Normalization audit checklist
&lt;/h2&gt;

&lt;p&gt;Before sending extracted PDF text to your chunking and embedding workers, verify these four checkpoints:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ligature expansion: Run a scan for characters in the Unicode range &lt;code&gt;\uFB00&lt;/code&gt; to &lt;code&gt;\uFB4F&lt;/code&gt; and the PUA range &lt;code&gt;\uE000&lt;/code&gt; to &lt;code&gt;\uF8FF&lt;/code&gt;. The count should be zero after normalization.&lt;/li&gt;
&lt;li&gt;Line-end hyphen count: Count hyphens preceding newlines. In standard text, nearly all line-break hyphens should be resolved into continuous words or explicit compounds.&lt;/li&gt;
&lt;li&gt;Compound word preservation: Test specific benchmark words like &lt;code&gt;state-of-the-art&lt;/code&gt; and &lt;code&gt;trade-off&lt;/code&gt; against your dehyphenator to confirm they retain their hyphens.&lt;/li&gt;
&lt;li&gt;Vocabulary check: Run a sample of 1,000 extracted words against your tokenizer or an English dictionary. Words flagged as unknown tokens often expose unmapped font encoding tables in the source document.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>python</category>
      <category>ai</category>
    </item>
    <item>
      <title>Automating Technical PDF Ingestion: Integrating the KolmoPDF API and Agent Skills</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Wed, 11 Nov 2026 15:23:33 +0000</pubDate>
      <link>https://dev.to/kolmopdf/automating-technical-pdf-ingestion-integrating-the-kolmopdf-api-and-agent-skills-3ljg</link>
      <guid>https://dev.to/kolmopdf/automating-technical-pdf-ingestion-integrating-the-kolmopdf-api-and-agent-skills-3ljg</guid>
      <description>&lt;p&gt;&lt;em&gt;This article is part of the **KolmoPDF: Product Guides &amp;amp; Updates&lt;/em&gt;* series. For a high-level overview of our parsing engine and layout-preserving translation, read the &lt;a href="https://dev.to/kolmopdf/kolmopdf-technical-pdf-parsing-and-translation-for-document-workflows-404p"&gt;series overview&lt;/a&gt;.*&lt;/p&gt;

&lt;p&gt;Converting a research paper or hardware spec sheet by hand through a browser UI works fine for a quick one-off check, but breaks down when you need to ingest dozens of technical preprints a day or feed incoming documents into a retrieval pipeline. Manual uploads produce inconsistent naming, unlogged failures, and delayed vector updates.&lt;/p&gt;

&lt;p&gt;A reliable ingestion pipeline needs two capabilities: direct API access for backend microservices and native integration with coding agents such as Claude Code, OpenClaw, or custom MCP environments.&lt;/p&gt;

&lt;p&gt;This walkthrough covers how to automate structured PDF-to-Markdown extraction using the KolmoPDF API and our open agent skill.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. When to Use Programmatic PDF Parsing
&lt;/h2&gt;

&lt;p&gt;Simple single-column PDFs with plain paragraphs work reliably with local open-source utilities like &lt;code&gt;pypdf&lt;/code&gt;. An API-based extraction pipeline becomes necessary when documents contain structures that local text scrapers discard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multi-column research papers: Maintaining reading flow without interleaving parallel columns.&lt;/li&gt;
&lt;li&gt;Display and inline formulas: Extracting equations directly into standard LaTeX (&lt;code&gt;$...$&lt;/code&gt; and &lt;code&gt;$$...$$&lt;/code&gt;) rather than flattened character fragments.&lt;/li&gt;
&lt;li&gt;Complex tables: Preserving grid alignments and multi-line cell values as clean Markdown tables.&lt;/li&gt;
&lt;li&gt;Embedded translations: Translating technical documents while parsing, outputting Markdown in the target language for immediate indexing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. API Setup and Credit Model
&lt;/h2&gt;

&lt;p&gt;KolmoPDF uses a unified credit model across the web interface, the REST API, and agent tools.&lt;/p&gt;

&lt;p&gt;The free tier includes 300 credits upon registration and 50 credits via daily check-in, providing 1 API key. Paid tiers (Go, Plus, Pro) and a Pay-As-You-Go option ($3 for 1,000 credits) share the same API endpoints. Pro plans allow creating and managing up to 10 API keys.&lt;/p&gt;

&lt;p&gt;Standard PDF-to-Markdown parsing consumes 2 credits per page. Parsing with concurrent translation consumes 3 credits per page.&lt;/p&gt;

&lt;p&gt;You can generate your API key directly in your &lt;a href="https://www.kolmopdf.com/api-docs" rel="noopener noreferrer"&gt;KolmoPDF dashboard&lt;/a&gt; and export it to your runtime environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;KOLMOPDF_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your-api-key-here"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Submitting Documents via Python
&lt;/h2&gt;

&lt;p&gt;The REST API accepts PDF uploads and returns structured Markdown once processing completes. Here is an end-to-end Python client script for submitting a technical report and saving the structured Markdown output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;API_BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.kolmopdf.com/v1"&lt;/span&gt;
&lt;span class="no"&gt;API_KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KOLMOPDF_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="no"&gt;API_KEY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KOLMOPDF_API_KEY environment variable is missing."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {API_KEY}"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;parse_pdf_to_markdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;poll_interval&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""
    Uploads a PDF to KolmoPDF, polls for parsing completion,
    and writes the resulting Markdown to disk.
    """&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;FileNotFoundError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Source file not found: {file_path}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 1. Upload and create parsing task&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"output_format"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"preserve_math"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Uploading {file_path}..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{API_BASE}/parse"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;task_info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;task_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;task_info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"task_id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Task created: {task_id}. Polling for completion..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 2. Poll task status&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;status_resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{API_BASE}/tasks/{task_id}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;status_resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;status_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status_resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"completed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;markdown_content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"markdown"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;markdown_content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Extraction complete! Saved to {output_path}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"failed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;error_msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status_data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Unknown error"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Parsing failed: {error_msg}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;poll_interval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;parse_pdf_to_markdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"sample_paper.pdf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"sample_paper.md"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The returned Markdown contains properly scoped LaTeX blocks for formulas and GitHub-flavored Markdown for tables, ready for standard text chunking or vector embedding.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Connecting to AI Coding Agents via Agent Skills
&lt;/h2&gt;

&lt;p&gt;For autonomous coding agents or terminal workflows, installing our pre-packaged agent skill is faster than hand-rolling API requests.&lt;/p&gt;

&lt;p&gt;You can install the KolmoPDF skill using &lt;code&gt;npx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx skills add komoai2026/kolmopdf-skill
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once installed, supply &lt;code&gt;KOLMOPDF_API_KEY&lt;/code&gt; to your agent runtime. The skill exposes commands that allow agents to ingest PDF paths, extract Markdown, and inspect equations without leaving their operational session.&lt;/p&gt;

&lt;p&gt;This pattern is especially effective for automated review workflows: an agent downloads a whitepaper from an arXiv link, calls the skill to convert it to Markdown, and performs semantic summarization or code reproduction against clean mathematical definitions.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Practical Ingestion Guidelines
&lt;/h2&gt;

&lt;p&gt;When integrating document parsing into production pipelines, keep these operational boundaries in mind:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test representative pages first. Before batch-processing a 500-page archive, test 5 to 10 representative pages containing your domain's dense formulas or multi-column grids.&lt;/li&gt;
&lt;li&gt;Retain source PDFs. Always store the original PDF alongside the extracted Markdown. Having the original coordinates allows human auditors or vision fallback models to verify ambiguous symbols.&lt;/li&gt;
&lt;li&gt;Consider data privacy boundaries. KolmoPDF processes documents online over TLS. For sensitive internal legal records or regulated health documents that cannot touch cloud endpoints, evaluate our on-premises Enterprise deployment options.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To get started, create your free account at &lt;a href="https://www.kolmopdf.com" rel="noopener noreferrer"&gt;KolmoPDF&lt;/a&gt;, grab an API key from the &lt;a href="https://www.kolmopdf.com/api-docs" rel="noopener noreferrer"&gt;Developer Guide&lt;/a&gt;, and test your first technical paper.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>api</category>
      <category>python</category>
      <category>ai</category>
    </item>
    <item>
      <title>Why Disconnected Captions and Footnotes Break Technical RAG (and How to Bind Spatial Annotations)</title>
      <dc:creator>KolmoPDF</dc:creator>
      <pubDate>Tue, 10 Nov 2026 15:21:23 +0000</pubDate>
      <link>https://dev.to/kolmopdf/why-disconnected-captions-and-footnotes-break-technical-rag-and-how-to-bind-spatial-annotations-22a6</link>
      <guid>https://dev.to/kolmopdf/why-disconnected-captions-and-footnotes-break-technical-rag-and-how-to-bind-spatial-annotations-22a6</guid>
      <description>&lt;p&gt;&lt;em&gt;This article is part of the **PDF Parsing for RAG&lt;/em&gt;* series. In &lt;a href="https://dev.to/kolmopdf/why-naive-text-extraction-destroys-rag-on-multi-column-pdfs-and-how-to-fix-reading-order-404a"&gt;Part 1&lt;/a&gt;, we resolved multi-column reading order. In &lt;a href="https://dev.to/kolmopdf/why-flattened-pdf-tables-break-rag-and-how-to-preserve-cell-semantics-in-markdown-42dn"&gt;Part 2&lt;/a&gt;, we reconstructed borderless tables. In &lt;a href="https://dev.to/kolmopdf/why-fragmented-formulas-ruin-math-rag-and-how-to-extract-clean-latex-blocks-from-technical-pdfs-3ngf"&gt;Part 3&lt;/a&gt;, we serialized mathematical formulas into LaTeX blocks. Today we address floating figures, captions, and orphaned footnotes.*&lt;/p&gt;

&lt;p&gt;When ingesting technical whitepapers and research reports into retrieval-augmented generation (RAG) pipelines, queries targeting visual evidence or methodology caveats fail reliably. A user asks: &lt;em&gt;"What dataset was used for the ablation study in Figure 4?"&lt;/em&gt; Vector retrieval either returns an unrelated section from the appendix or surfaces a fragmented snippet lacking the figure's context.&lt;/p&gt;

&lt;p&gt;The error originates in how PDF renderers place floating objects. Unlike HTML, where figures exist within a structured DOM tree, PDF drawing instructions position figures, captions, and footnotes at arbitrary coordinates on the canvas. Naive extractors read these elements in stream order, slicing captions into the middle of running paragraphs and dropping footnotes into random chunk windows.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Physical Layout of Floating Annotations
&lt;/h2&gt;

&lt;p&gt;In academic and technical publishing, figures and tables rarely appear directly after their first text mention. Instead, layout engines push visual blocks to the top or bottom of the page or into an adjacent column to maximize whitespace efficiency.&lt;/p&gt;

&lt;p&gt;This separation introduces two distinct structural hazards for text extractors:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Floating Caption Interleaving&lt;/strong&gt;: A caption starting with &lt;code&gt;Figure 2: Architecture overview&lt;/code&gt; is placed physically below a diagram. Because naive extractors sort blocks purely by vertical coordinates, the caption text is inserted directly between two halves of a main-body sentence that runs alongside the diagram.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Footnote Disconnection&lt;/strong&gt;: Footnotes sit at the bottom margin, separated from the body by a thin vector rule. When text splitters process the page, the footnote marker (such as a superscript &lt;code&gt;3&lt;/code&gt;) lands in Chunk 1, while the corresponding definition sits 400 tokens away in Chunk 2, stripped of its referent.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Three Failure Modes in RAG Ingestion
&lt;/h2&gt;

&lt;p&gt;When spatial annotations are flattened without bounding box resolution, downstream retrieval systems suffer three repeatable failures:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Mid-Sentence Injection
&lt;/h3&gt;

&lt;p&gt;When a floating caption is merged into surrounding text, the embedding model processes a garbled sentence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The transformer backbone processes input tokens Figure 3: Training loss across 50 epochs using AdamW optimizer with a linear warm-up schedule.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The semantic representation of both the main-body sentence and the figure description is degraded, lowering similarity scores for both topics.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Orphaned Footnote Disclaimers
&lt;/h3&gt;

&lt;p&gt;Legal disclaimers, dataset licenses, and parameter details frequently live in footnotes. When parsed as independent text lines at the bottom of a page, an embedding model receives isolated fragments like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*Evaluated on an internal benchmark of 1,200 synthetic prompts; not audited for production SLAs.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because this chunk lacks the product name or the metric name defined 30 lines above, vector search never retrieves the qualification when answering risk or compliance queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Visual Hallucinations in Multi-Modal RAG
&lt;/h3&gt;

&lt;p&gt;When combining text chunks with vision-language models (VLMs), passing an image without its bound caption forces the model to guess the axes, legends, or experiment names. Conversely, passing the caption text without coordinates prevents the system from cropping the relevant figure region for visual validation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Reconstruction: Spatial Caption Binding and Footnote Inlining
&lt;/h2&gt;

&lt;p&gt;To preserve document hierarchy, an ingestion pipeline must separate floating annotations from body paragraphs, identify their target anchors, and inline them cleanly into the Markdown output.&lt;/p&gt;

&lt;p&gt;Here is a Python implementation using PyMuPDF (&lt;code&gt;fitz&lt;/code&gt;) that detects captions, binds them to adjacent image bounding boxes, and isolates footer regions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fitz&lt;/span&gt;  &lt;span class="c1"&gt;# PyMuPDF&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;parse_page_with_bound_annotations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;footer_margin_pt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""
    Separates floating captions and footnotes from main text blocks,
    binding captions to figure regions and isolating footnotes.

    Args:
        page: fitz.Page object
        footer_margin_pt: Distance from page bottom treated as footnote zone.
    """&lt;/span&gt;
    &lt;span class="n"&gt;page_rect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rect&lt;/span&gt;
    &lt;span class="n"&gt;page_height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page_rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;
    &lt;span class="n"&gt;page_dict&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"dict"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 1. Identify image bounding boxes&lt;/span&gt;
    &lt;span class="n"&gt;image_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_images&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;image_bboxes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;image_list&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;xref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_image_rects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xref&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;image_bboxes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 2. Categorize text blocks&lt;/span&gt;
    &lt;span class="n"&gt;body_blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;caption_blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;footnote_blocks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="n"&gt;caption_pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'^(Figure|Fig\.|Table)\s+\d+[:\.]'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;IGNORECASE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;page_dict&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"blocks"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;

        &lt;span class="n"&gt;bbox&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fitz&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"bbox"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;block_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"lines"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;line_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"spans"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;block_text&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;line_str&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;" "&lt;/span&gt;
        &lt;span class="n"&gt;block_text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;

        &lt;span class="c1"&gt;# Check for footnotes near bottom margin&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page_height&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;footer_margin_pt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# Check for footnote prefix like a number or symbol&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'^(\d+|[\*\†\‡])\s+'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;footnote_blocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;

        &lt;span class="c1"&gt;# Check for figure/table caption pattern&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;caption_pattern&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;caption_blocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;body_blocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bbox&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;block_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 3. Bind captions to nearest image box&lt;/span&gt;
    &lt;span class="n"&gt;bound_figures&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;used_captions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;img_box&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;image_bboxes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;closest_caption&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;
        &lt;span class="n"&gt;min_dist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"inf"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cap_box&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cap_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;caption_blocks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;used_captions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="c1"&gt;# Vertical distance between image bottom and caption top&lt;/span&gt;
            &lt;span class="n"&gt;dist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cap_box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;img_box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;dist&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;min_dist&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;dist&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# Within 60 points threshold&lt;/span&gt;
                &lt;span class="n"&gt;min_dist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dist&lt;/span&gt;
                &lt;span class="n"&gt;closest_caption&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cap_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;closest_caption&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;used_captions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;closest_caption&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;bound_figures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"![{closest_caption[1]}](image_placeholder)\n*{closest_caption[1]}*"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# 4. Assemble clean Markdown output&lt;/span&gt;
    &lt;span class="n"&gt;markdown_sections&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="c1"&gt;# Sort body blocks in reading order (top-to-bottom, column-aware)&lt;/span&gt;
    &lt;span class="n"&gt;body_blocks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;y0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;body_blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;markdown_sections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Append bound figures as standalone blocks&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fig_md&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bound_figures&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;markdown_sections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fig_md&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Inline remaining unattached captions&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cap_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;caption_blocks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;used_captions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;markdown_sections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"*{cap_text}*"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Append footnotes as a structured reference section&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;footnote_blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;footnote_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"\n### Footnotes"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fn_text&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;footnote_blocks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;footnote_lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"- {fn_text}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;markdown_sections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;footnote_lines&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"\n\n"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;markdown_sections&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tradeoffs: Inlining vs. Standalone Chunks vs. Parent-Document Metadata
&lt;/h2&gt;

&lt;p&gt;When formatting annotations for vector indexing, different indexing architectures offer distinct tradeoffs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Strategy&lt;/th&gt;
&lt;th&gt;Token Overhead&lt;/th&gt;
&lt;th&gt;Context Density&lt;/th&gt;
&lt;th&gt;Retrieval Precision&lt;/th&gt;
&lt;th&gt;Best Application&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Inlined Callout (&lt;code&gt;&amp;gt; Footnote&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Minimal&lt;/td&gt;
&lt;td&gt;High (adjacent to text)&lt;/td&gt;
&lt;td&gt;High for local facts&lt;/td&gt;
&lt;td&gt;Short technical reports and whitepapers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Standalone Caption Chunk&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Moderate&lt;/td&gt;
&lt;td&gt;Focused on visual data&lt;/td&gt;
&lt;td&gt;High for diagram-specific queries&lt;/td&gt;
&lt;td&gt;Multimodal RAG with image generation or VLM routing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Document Metadata Association&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Lowest&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;High for global filtering&lt;/td&gt;
&lt;td&gt;Legal contracts and compliance documentation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For most enterprise pipelines, &lt;strong&gt;Inlined Callouts&lt;/strong&gt; provide the cleanest balance: the explanation remains attached to the paragraph that references it, preventing vector search from returning orphaned disclaimers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layout Annotation Audit Checklist
&lt;/h2&gt;

&lt;p&gt;Before finalizing your technical document pipeline, run this four-point audit on your parsed chunks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verify Caption Isolation&lt;/strong&gt;: Confirm that strings matching &lt;code&gt;Figure X:&lt;/code&gt; or &lt;code&gt;Table Y:&lt;/code&gt; never appear inside the text of an unrelated paragraph.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Audit Footnote Association&lt;/strong&gt;: Inspect sample chunks containing footnote superscripts; confirm that the definition is appended to the chunk rather than separated by page breaks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate Visual Coordinates&lt;/strong&gt;: Ensure that every extracted figure retains its bounding box coordinates &lt;code&gt;(x0, y0, x1, y1)&lt;/code&gt; so downstream vision pipelines can crop the source image directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test Negative Disclaimers&lt;/strong&gt;: Run retrieval tests with queries like &lt;em&gt;"What are the documented limitations?"&lt;/em&gt; Verify that vector search retrieves the inlined footnote rather than dropping the qualification.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>pdf</category>
      <category>rag</category>
      <category>python</category>
    </item>
  </channel>
</rss>
