Skip to content

fix(config): apply VOYAGE_API_KEY after merging config layers - #453

Merged
HananKavitzAmat merged 1 commit into
chunkhound:mainfrom
mayuriphad:voyage-key-after-merge
Oct 25, 2026
Merged

HananKavitzAmat merged 1 commit into
chunkhound:mainfrom
mayuriphad:voyage-key-after-merge

Conversation

@mayuriphad

Copy link
Copy Markdown
Contributor

Fixes #448

VOYAGE_API_KEY was only used when the voyageai provider came from an environment variable. The fallback lives in EmbeddingConfig.load_from_env, which only sees env values. A provider set in .chunkhound.json, in the global config or with --provider voyageai is merged in later, so the key was never filled in, and chunkhound index failed with:

Error: Missing required configuration: embedding.api_key (set VOYAGE_API_KEY or CHUNKHOUND_EMBEDDING__API_KEY)

Config.__init__ now applies the fallback once more after all layers (env, global, local, --config, CLI, kwargs) are merged. It only runs when the env layer is enabled, the merged provider is voyageai and no layer supplied an api_key. An API key from any layer still takes precedence, and the openai provider never picks up VOYAGE_API_KEY. The existing env-only fallback in load_from_env is unchanged.

Tests (tests/test_config_integration.py):

  • test_voyage_api_key_used_for_provider_from_local_config: provider from .chunkhound.json
  • test_voyage_api_key_used_for_provider_from_cli: --provider voyageai
  • test_voyage_api_key_does_not_override_configured_key
  • test_voyage_api_key_not_used_for_openai_provider

The first two fail on main and pass with the change. On my machine tests/test_config_integration.py passes (35 tests), and so do tests/config, tests/remote_config and tests/unit/test_embedding_config_provider_check.py (154 passed). ruff format --check and mypy are clean on config.py. I'm on Windows, where the chunkhound_native extension can't load, so I stubbed it for these config-only tests. tests/test_smoke.py gives the same 8 failures with and without this change; they come from CLI subprocesses that need the native module.

The VOYAGE_API_KEY fallback ran inside EmbeddingConfig.load_from_env,
where only environment values are known. When the voyageai provider
came from .chunkhound.json, a global config or --provider, the fallback
never saw it, and indexing failed with 'Missing required configuration:
embedding.api_key (set VOYAGE_API_KEY ...)' although the variable was
set.

Apply the fallback once more after all layers are merged. A key from any
layer still wins, and other providers are not affected.

Fixes #448

Signed-off-by: mayuriphad <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 25, 2026 06:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@HananKavitzAmat

Copy link
Copy Markdown
Collaborator

This looks good to me.
The problem, which is prexisting, is that the two env variables are logicaly the same and we should merge them. There should be only one env var CHUNKHOUND_EMBEDDING__API_KEY. I will open a follow up issue.

@HananKavitzAmat
HananKavitzAmat added this pull request to the merge queue Oct 25, 2026
Merged via the queue into chunkhound:main with commit 829ec58 Oct 25, 2026
25 checks passed
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 7, 2026
Config() merges the first file among get_global_config_candidates()
(~/.config/chunkhound/chunkhound.json and friends). A test that builds a
Config without an embedding section therefore inherits whatever provider
the machine is configured with. On a machine whose global config selects
voyageai with the key supplied by VOYAGE_API_KEY, 47 realtime tests error
and 21 fail in EmbeddingProviderFactory ("Missing: api_key"). With chunkhound#453
applied and the key set, the same tests instead build a real Voyage
provider. Neither happens in CI, which has no global config.

A session-scoped autouse fixture pins CHUNKHOUND_GLOBAL_CONFIG_FILE to an
existing empty file, so the global layer is empty for every test. Tests
that exercise global-config discovery already set or delete the variable
themselves (remote_config's _isolate, clean_environment,
test_config_integration).

Realtime set on Windows with that global config: 21 failed / 71 passed /
34 skipped / 47 errors before, 139 passed / 34 skipped after. The config
tests fail the same 5 tests with and without the fixture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz pushed a commit to fstrasz/chunkhound that referenced this pull request Nov 7, 2026
…ound#453)

The VOYAGE_API_KEY fallback ran inside EmbeddingConfig.load_from_env,
where only environment values are known. When the voyageai provider
came from .chunkhound.json, a global config or --provider, the fallback
never saw it, and indexing failed with 'Missing required configuration:
embedding.api_key (set VOYAGE_API_KEY ...)' although the variable was
set.

Apply the fallback once more after all layers are merged. A key from any
layer still wins, and other providers are not affected.

Fixes chunkhound#448

Signed-off-by: mayuriphad <[email protected]>
(cherry picked from commit 829ec58)
huangyingting pushed a commit to repomesh/chunkhound that referenced this pull request Nov 9, 2026
…ound#486)

Config() merges the first file among get_global_config_candidates()
(~/.config/chunkhound/chunkhound.json and friends). A test that builds a
Config without an embedding section therefore inherits whatever provider
the machine is configured with. On a machine whose global config selects
voyageai with the key supplied by VOYAGE_API_KEY, 47 realtime tests error
and 21 fail in EmbeddingProviderFactory ("Missing: api_key"). With chunkhound#453
applied and the key set, the same tests instead build a real Voyage
provider. Neither happens in CI, which has no global config.

A session-scoped autouse fixture pins CHUNKHOUND_GLOBAL_CONFIG_FILE to an
existing empty file, so the global layer is empty for every test. Tests
that exercise global-config discovery already set or delete the variable
themselves (remote_config's _isolate, clean_environment,
test_config_integration).

Realtime set on Windows with that global config: 21 failed / 71 passed /
34 skipped / 47 errors before, 139 passed / 34 skipped after. The config
tests fail the same 5 tests with and without the fixture.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

VOYAGE_API_KEY is ignored when the provider comes from .chunkhound.json or --provider

3 participants