OCR-to-vision routing¶
Docgate's job is to govern an extraction ladder, not to replace its providers.
For a mixed bundle such as a CV, experience letter, PAN card, and Aadhaar card:
- Use
needand a local selection policy to avoid processing irrelevant pages where local evidence is available. - Send selected image-only pages to a lower-cost OCR provider.
- Apply a local
TextQualityGateto the returned transcription. - Escalate only weak output to the next provider, normally a vision model.
- Inspect the receipt: it records selection skips, OCR quality rejections, fallback attempts, cost, and any pages still unknown.
The quality gate is a local minimum-evidence check, not a semantic evaluator.
If it rejects a successful OCR response, docgate records
quality_gate_rejected as a degradation and tries the next provider. The OCR
provider is not treated as unhealthy solely because its text was insufficient.
from decimal import Decimal
import docgate
ocr = docgate.MistralOcrProvider(
api_key="...",
# Set this from your own current Mistral pricing agreement.
cost_per_page=Decimal("0.004"),
)
vision = docgate.OpenAICompatibleProvider(
model="your-vision-model",
api_key="...",
base_url="https://your-host/v1",
cost_per_page=Decimal("0.01"),
)
result = docgate.read(
"employment-bundle.pdf",
need="CV and experience letter",
selection="top_k",
max_paid_pages=3,
providers=[ocr, vision],
quality_gate=docgate.TextQualityGate(
min_characters=40,
min_alphanumeric_characters=25,
min_words=6,
),
budget=Decimal("0.05"),
)
if not result.receipt.complete:
# A policy decision belongs to the application, never docgate.
print(result.receipt.unknown)
The quality gate measures only obvious local evidence, not document meaning. Tune it for the shortest valid document you expect. A short PAN or Aadhaar identifier should use a smaller threshold than a CV or experience letter.