Skip to content

fix(embeddings): default to OpenAI provider when env vars are configured (#551)#689

Open
evanclan wants to merge 1 commit into
tirth8205:mainfrom
evanclan:fix/openai-default-provider-551
Open

fix(embeddings): default to OpenAI provider when env vars are configured (#551)#689
evanclan wants to merge 1 commit into
tirth8205:mainfrom
evanclan:fix/openai-default-provider-551

Conversation

@evanclan

Copy link
Copy Markdown

Summary

Fixes #551. When provider is omitted from get_provider() (the default for MCP tool calls like semantic_search_nodes), the function used to fall straight back to the local sentence-transformers provider even when CRG_OPENAI_API_KEY and CRG_OPENAI_BASE_URL were configured. This made OpenAI-compatible embeddings (e.g., Ollama, vLLM, LocalAI, LiteLLM) unreachable from AI assistants unless they explicitly passed provider="openai".

Problem

semantic_search_nodes and other callers that omit provider relied on EmbeddingStore forwarding provider=None to get_provider(). That path immediately dropped to the local default without checking whether OpenAI env vars were present, so configured cloud/local OpenAI endpoints were ignored.

Solution

  • After normalizing the provider name in get_provider(), if no explicit provider was given and both CRG_OPENAI_API_KEY and CRG_OPENAI_BASE_URL are set, route to the openai branch instead of local.
  • The existing openai branch already validates CRG_OPENAI_MODEL and raises a clear ValueError if it is missing, so callers get actionable feedback rather than a silent fallback.

Out of scope

  • Did not change behavior when provider="local" is explicitly passed; local still wins in that case.
  • Did not add defaulting for Google or MiniMax env vars; those require explicit opt-in (GOOGLE_API_KEY, MINIMAX_API_KEY) and the issue only covered OpenAI-compatible endpoints.
  • Did not touch prewarm_local_embeddings() startup behavior; that is a separate concern.

Test plan

  • Added test_none_defaults_to_openai_when_env_configured to verify get_provider(None) returns an OpenAIEmbeddingProvider when the OpenAI env vars are set.
  • Existing test_none_and_empty_default_to_local still passes when no OpenAI env vars are configured.
  • uv run pytest tests/test_embeddings.py -q — 99 passed.
  • uv run --extra dev ruff check code_review_graph/embeddings.py tests/test_embeddings.py — all checks passed.
  • Full CI suite on the PR.

Related

Made with Cursor

…red (tirth8205#551)

When `provider` is omitted but `CRG_OPENAI_API_KEY` and
`CRG_OPENAI_BASE_URL` are set, `get_provider()` now routes to the
OpenAI-compatible provider instead of silently falling back to local.
This fixes `semantic_search_nodes` and other MCP tool invocations that
do not pass an explicit `provider` parameter.

Includes a regression test verifying that `get_provider(None)` returns
an `OpenAIEmbeddingProvider` when the OpenAI env vars are present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: semantic_search_nodes ignores CRG_OPENAI_* env vars and always falls back to local provider when provider is not explicitly passed

1 participant