跳到正文
DEV Community· KolmoPDF·· 1 小時前AI 評分59

PDF 頁碼可能掩蓋 RAG 流程中的掃描文字缺失

A PDF page number can hide missing scanned text in your RAG pipeline

AI 導讀

PDF 頁碼可能令文件級檢查誤以為掃描頁已有文字,令 OCR 被跳過,近乎空白的頁面仍進入 RAG 索引。文章建議逐頁比對來源頁與 Markdown,將短頁列入人工檢查而非直接判空,並保留原始抽取文字。完成抽取檢查後,應另行測試只在掃描頁出現答案的問題,以及答案不在文件中的反向問題。

正文

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.

A page-by-page audit is a useful first step when converting mixed technical documents with KolmoPDF's PDF-to-Markdown tool. 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.

Build a fixture that defeats the empty-page check

Imagine a three-page document:

  • Page 1 has selectable paragraphs and a page number.
  • Page 2 is a scanned paragraph with an embedded page number, 2.
  • Page 3 is a diagram with a short caption and no paragraph text.

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.

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.

Compare coverage at page level

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.

import re

pages = [
    {"page": 1, "text": "Introduction to the measurement protocol."},
    {"page": 2, "text": "2"},
    {"page": 3, "text": "Figure 1. Sensor layout."},
]

def needs_review(text, minimum_chars=30):
    lines = [line.strip() for line in text.splitlines() if line.strip()]
    body = " ".join(line for line in lines if not re.fullmatch(r"\d+", line))
    return len(body) < minimum_chars

for page in pages:
    if needs_review(page["text"]):
        print(f"Review page {page['page']}")

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.

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.

Keep the retrieval test separate

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.

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.

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.

來源:DEV Community · dev.to