Skip to content

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

@destitutus

Description

@destitutus

Problem

Version

2.3.5

Problem

When CRG_OPENAI_API_KEY, CRG_OPENAI_BASE_URL, and CRG_OPENAI_MODEL are configured (e.g. for a local Ollama instance), calling semantic_search_nodes without an explicit provider argument always falls back to keyword-only search instead of using the configured OpenAI-compatible backend.

The root cause is in get_provider() (embeddings.py): when provider=None, the function immediately falls through to the # Default: local branch without checking whether OpenAI env vars are present:

# Default: local
if not _check_available():
    return None
return LocalEmbeddingProvider(model_name=model)

This means embeddings built with --provider openai are effectively unreachable unless every caller explicitly passes provider="openai" ? including all MCP tool invocations from AI assistants, which typically omit optional parameters.

Expected behavior

If CRG_OPENAI_API_KEY and CRG_OPENAI_BASE_URL are set, get_provider(provider=None) should default to the OpenAI-compatible provider rather than local.

Proposed solution

Suggested fix

def get_provider(
    provider: str | None = None,
    model: str | None = None,
) -> EmbeddingProvider | None:
    if provider is None and os.environ.get("CRG_OPENAI_API_KEY") and os.environ.get("CRG_OPENAI_BASE_URL"):
        provider = "openai"
    if provider == "openai":
        ...

This makes the provider selection consistent with how the OpenAI env vars are already used elsewhere in the codebase ? no new env vars needed.

Affected area

None

Alternatives considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions