Page 2 of a travel policy says receipts are required for expenses over €25. Page 3 says hotel stays always require a receipt. Page 3 is a scan, so an extractor that reads only the PDF’s text layer picks up the €25 rule and misses the hotel exception.
The pipeline has text to embed. If it treats that as success, someone searching for the hotel rule may only get the €25 rule back.
Check page coverage before chunking
Read the page count from the source PDF before extraction. Keep the outcome for each original page number. The coverage check accepts pages marked Extracted or ConfirmedBlank.
using System;
using System.Collections.Generic;
const int pdfPageCount = 3; // Read this from the source PDF.
var outcomes = new Dictionary<int, PageOutcome>
{
[1] = PageOutcome.Extracted,
[2] = PageOutcome.Extracted,
[3] = PageOutcome.NeedsOcr
};
Console.WriteLine(HasCompleteCoverage(pdfPageCount, outcomes)); // False
static bool HasCompleteCoverage(
int pageCount,
IReadOnlyDictionary<int, PageOutcome> outcomes)
{
if (pageCount <= 0 || outcomes.Count != pageCount)
{
return false;
}
for (int page = 1; page <= pageCount; page++)
{
if (!outcomes.TryGetValue(page, out var outcome))
{
return false;
}
if (outcome != PageOutcome.Extracted && outcome != PageOutcome.ConfirmedBlank)
{
return false;
}
}
return true;
}
enum PageOutcome { Extracted, ConfirmedBlank, NeedsOcr, Failed }
Send page 3 through OCR and run the check again with its updated outcome. A missing result or a failed page also holds the document back. Leave a page unresolved when the extractor returns an empty string and you have yet to determine whether the page is blank.
Use the full page count when readers expect the whole PDF to be searchable. If you index only selected pages, check those page numbers instead.
Check extraction quality separately. A text-layer extractor can pick up a heading and miss the scanned text below it on the same page.