Skip to main content

embed_with_fallback

Function embed_with_fallback 

Source
pub fn embed_with_fallback(
    models_dir: &Path,
    text: &str,
    chain: &[LlmBackendKind],
    skip_on_failure: bool,
) -> Result<(Vec<f32>, LlmBackendKind), AppError>
Expand description

Tries each LLM backend in chain in order, returning the first successful embedding. On failure, the diagnostic tail of the last error is preserved in the returned AppError::Embedding so the operator can see WHY every backend failed.

If skip_on_failure is true AND every backend fails, the function returns Ok(Vec::new()) (an empty vector) to signal “persist without embedding” — the call site is then responsible for writing a pending_embeddings row that can be retried later by the embedding retry subcommand.

Defaults the chain to [codex, claude, none] when chain is empty, matching the v1.0.81 behaviour where codex was the implicit default and claude was the implicit fallback.