Module: Kreuzberg::VlmFallbackPolicy

Extended by:
T::Helpers, T::Sig
Included in:
VlmFallbackPolicyAlways, VlmFallbackPolicyDisabled, VlmFallbackPolicyOnLowQuality
Defined in:
lib/kreuzberg/native.rb

Overview

Policy controlling when VLM (Vision Language Model) OCR is used as a fallback.

This knob is syntactic sugar over the explicit [‘OcrPipelineConfig`] stage ordering. When `vlm_fallback` is set and `pipeline` is `None`, an equivalent pipeline is synthesised at extraction time:

  • ‘VlmFallbackPolicy::Disabled`

    — no synthesis; single-backend mode (default).

  • ‘VlmFallbackPolicy::OnLowQuality`

    — tries the classical backend first; if the

    result scores below ‘quality_threshold`, tries VLM.

  • ‘VlmFallbackPolicy::Always`

    — skips the classical backend and sends every page

    to the VLM.

When [‘OcrConfig::pipeline`] is explicitly set, `vlm_fallback` is ignored — the explicit pipeline takes precedence. Constructing an [`OcrConfig`] with one of these policies but no `vlm_config` is detected by `OcrConfig::validate` and will surface as a `Validation` error at extraction time, not a panic.

Raises:

  • Both ‘OnLowQuality` and `Always` require [`OcrConfig::vlm_config`] to be `Some`.

Class Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/kreuzberg/native.rb', line 39

def self.from_hash(hash)
  discriminator = hash[:mode] || hash["mode"]
  case discriminator
  when "disabled" then VlmFallbackPolicyDisabled.from_hash(hash)
  when "on_low_quality" then VlmFallbackPolicyOnLowQuality.from_hash(hash)
  when "always" then VlmFallbackPolicyAlways.from_hash(hash)
  else raise "Unknown discriminator: #{discriminator}"
  end
end