fix(embeddings): default to OpenAI provider when env vars are configured (#551)#689
Open
evanclan wants to merge 1 commit into
Open
fix(embeddings): default to OpenAI provider when env vars are configured (#551)#689evanclan wants to merge 1 commit into
evanclan wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #551. When
provideris omitted fromget_provider()(the default for MCP tool calls likesemantic_search_nodes), the function used to fall straight back to the local sentence-transformers provider even whenCRG_OPENAI_API_KEYandCRG_OPENAI_BASE_URLwere configured. This made OpenAI-compatible embeddings (e.g., Ollama, vLLM, LocalAI, LiteLLM) unreachable from AI assistants unless they explicitly passedprovider="openai".Problem
semantic_search_nodesand other callers that omitproviderrelied onEmbeddingStoreforwardingprovider=Nonetoget_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
get_provider(), if no explicit provider was given and bothCRG_OPENAI_API_KEYandCRG_OPENAI_BASE_URLare set, route to theopenaibranch instead of local.openaibranch already validatesCRG_OPENAI_MODELand raises a clearValueErrorif it is missing, so callers get actionable feedback rather than a silent fallback.Out of scope
provider="local"is explicitly passed; local still wins in that case.GOOGLE_API_KEY,MINIMAX_API_KEY) and the issue only covered OpenAI-compatible endpoints.prewarm_local_embeddings()startup behavior; that is a separate concern.Test plan
test_none_defaults_to_openai_when_env_configuredto verifyget_provider(None)returns anOpenAIEmbeddingProviderwhen the OpenAI env vars are set.test_none_and_empty_default_to_localstill 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.Related
semantic_search_nodesignoresCRG_OPENAI_*env vars and always falls back to local provider whenprovideris not explicitly passed #551 —semantic_search_nodesignoresCRG_OPENAI_*env vars whenprovideris not passedMade with Cursor