tirth8205/code-review-graph · error · RuntimeError

Embedding provider '{provider}' is unavailable in this envir

Error message

Embedding provider '{provider}' is unavailable in this environment.

What it means

refresh_embeddings() constructed the embedding store but found it unavailable (no resolvable provider) in the current environment — e.g. the required API key env var is missing — so it raises RuntimeError rather than partially refreshing.

Source

Thrown at code_review_graph/embeddings.py:1376

            "SELECT DISTINCT provider FROM embeddings ORDER BY provider",
        ).fetchall()
    except sqlite3.OperationalError as exc:
        if "no such column" in str(exc).lower() and "provider" in str(exc).lower():
            raise ValueError(
                "Embedding refresh refused: existing rows have no provider identity; "
                "run an explicit embed to migrate and rebuild the index.",
            ) from exc
        raise
    identities = {str(row["provider"]) for row in rows}

    embedding_store = EmbeddingStore(
        graph_store.db_path,
        provider=provider,
        model=model,
    )
    try:
        if not embedding_store.available or embedding_store.provider is None:
            raise RuntimeError(
                f"Embedding provider '{provider}' is unavailable in this environment.",
            )
        resolved_identity = embedding_store.provider.name
        if provider == "minimax":
            resolved_model = resolved_identity.partition(":")[2]
            if model != resolved_model:
                raise ValueError(
                    f"MiniMax refresh model must be '{resolved_model}', got '{model}'.",
                )
        if identities != {resolved_identity}:
            existing = ", ".join(sorted(identities))
            raise ValueError(
                "Embedding refresh refused: existing embeddings use "
                f"{existing}; requested provider resolves to {resolved_identity}.",
            )

        purged = embedding_store.purge_orphans()
        all_nodes: list[GraphNode] = []

View on GitHub (pinned to b58668751a)

Solutions

  1. Export the key the provider needs (VOYAGE_API_KEY, MINIMAX_API_KEY, GOOGLE_API_KEY, or the CRG_OPENAI_* trio)
  2. Confirm with the provider's env check (printenv) before re-running refresh
  3. If the environment truly can't reach the provider, run refresh from a machine that can

Example fix

# before
refresh_embeddings(gs, provider='voyage', model='voyage-3-lite')  # no key
# after
export VOYAGE_API_KEY=pa-...
refresh_embeddings(gs, provider='voyage', model='voyage-3-lite')
Defensive patterns

Strategy: validation

Validate before calling

REQUIRED = {"voyage": ["VOYAGE_API_KEY"], "minimax": ["MINIMAX_API_KEY"], "google": ["GOOGLE_API_KEY"], "openai": ["CRG_OPENAI_API_KEY", "CRG_OPENAI_BASE_URL", "CRG_OPENAI_MODEL"]}
for var in REQUIRED.get(provider, []):
    if not os.environ.get(var):
        raise RuntimeError(f"{var} missing; refresh would fail")

Try / catch

try:
    refresh_embeddings(gs, provider=p, model=m)
except RuntimeError as e:
    if "unavailable in this environment" in str(e):
        log.error("export the provider's API key before refresh")
        raise
    raise

Prevention

When it happens

Trigger: Calling refresh_embeddings(provider='voyage') without VOYAGE_API_KEY set (analogously for openai/google/minimax keys), so embedding_store.available is False or provider is None.

Common situations: Running refresh on a machine/CI job that lacks the secrets used when the index was originally embedded, or rotating to a new environment without re-exporting env vars.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28). Data as JSON: /api/errors/6fd68456709ca2ac. Report an issue: GitHub.