agentmemory icon indicating copy to clipboard operation
agentmemory copied to clipboard

Fix OpenAI embedding provider key selection

Open jinzheng8115 opened this issue 6 months ago • 2 comments

Summary

  • prefer OPENAI_EMBEDDING_API_KEY when creating the OpenAI-compatible embedding provider
  • keep OPENAI_API_KEY as the fallback for existing setups
  • add a regression test covering split LLM key and embedding key setups

Why

When agentmemory is configured with different OpenAI-compatible providers for chat and embeddings, createEmbeddingProvider() was still passing OPENAI_API_KEY into OpenAIEmbeddingProvider. In practice this breaks setups like LLM=DeepSeek and embeddings=DashScope, because the DeepSeek key gets sent to the embedding endpoint.

Verification

  • env -i HOME=/tmp/agentmemory-test-home PATH="$PATH" TERM="$TERM" npm test -- --run test/embedding-provider.test.ts
  • env -i HOME=/tmp/agentmemory-test-home PATH="$PATH" TERM="$TERM" npm run build
  • local runtime verification against a real split-provider setup: LLM=DeepSeek, embeddings=DashScope text-embedding-v4

Summary by CodeRabbit

  • New Features

    • Added support for dedicated OpenAI embedding API key configuration, taking precedence over the general OpenAI API key when both are set.
  • Tests

    • Added test coverage for embedding provider API key precedence behavior.

jinzheng8115 avatar Jun 05 '26 05:06 jinzheng8115

@jinzheng8115 is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jun 05 '26 05:06 vercel[bot]

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request updates the OpenAI embedding provider initialization to prefer OPENAI_EMBEDDING_API_KEY when set, falling back to OPENAI_API_KEY otherwise. A new test verifies this preference behavior.

Changes

OpenAI Embedding API Key Preference

Layer / File(s) Summary
Embedding API key resolution with test coverage
src/providers/embedding/index.ts, test/embedding-provider.test.ts
createEmbeddingProvider() now uses OPENAI_EMBEDDING_API_KEY as the primary source for OpenAI embedding authentication, falling back to OPENAI_API_KEY if the specialized key is not set. A new test verifies that the provider correctly prefers the embedding-specific key when both are configured.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • rohitg00/agentmemory#503: Both PRs update the OpenAI embedding API key resolution to prefer OPENAI_EMBEDDING_API_KEY over OPENAI_API_KEY (main PR in the provider factory/test, retrieved PR in OpenAIEmbeddingProvider constructor/test).

Suggested reviewers

  • rohitg00

Poem

🐰 A key preference emerges, Embedding-wise it surges, Fallback flows with care, Tests ensure it's fair, Configuration merge purges! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and clearly describes the main change: fixing the OpenAI embedding provider to use the correct API key (OPENAI_EMBEDDING_API_KEY with fallback to OPENAI_API_KEY), which is the core modification across both the implementation and test files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Jun 05 '26 05:06 coderabbitai[bot]