Skip to main content

get_embedder

Function get_embedder 

Source
pub async fn get_embedder() -> Box<dyn Embedder>
Expand description

Resolve the configured embedder from settings.

Priority chain (first match wins):

  1. OpenAICompatEmbedder — if the user explicitly configured a BYOK provider (semantic_embedding=true + a real embedding_provider_url, i.e. not the cloud-managed sentinel). This takes precedence over a stored cloud token: a user who ran difflore embeddings setup to bring their own key wants that provider used even while logged in.
  2. CloudEmbedder — if the user is logged in to cloud. Best-effort: we don’t probe the network here, we just trust the stored token. On request failure the caller falls back to local SHA1 via embed_text_async.
  3. Sha1Embedder — deterministic offline fallback.

Falls back to Sha1Embedder on any settings error, so callers never have to deal with embedder construction failures. Runtime paths should treat SHA1 as a degraded fallback after cloud/BYOK retries, never as the preferred path when cloud or BYOK is available. probe_active_embedder mirrors this same order — keep the two in sync.