reports "No API key" even when MEMORIX_EMBEDDING_API_KEY is configured in `.env`
Description
When MEMORIX_EMBEDDING_API_KEY is set in ~/.memorix/.env, running memorix status incorrectly reports:
Failed to init API embedding: No API key for embedding.
The API key is valid and the configuration is correct — the embedding provider works after restarting the background service. However, memorix status always fails to detect the key.
Expected Behavior
memorix status should correctly detect and display the embedding provider status when API key is configured in .env.
Actual Behavior
memorix status reports "No API key" and falls back to BM25 fulltext, even though:
- The API key is valid (verified with direct curl to SiliconFlow API)
- The key is set in
~/.memorix/.envasMEMORIX_EMBEDDING_API_KEY - The background service starts correctly with the same configuration
Root Cause
In src/cli/commands/status.ts, the execution order is incorrect:
// Line 62: getEmbeddingProvider() is called FIRST
const provider = await getEmbeddingProvider();
if (provider) { ... }
// ... 35 lines later ...
// Line 97: loadDotenv() is called AFTER getEmbeddingProvider()
loadDotenv(project.rootPath);
getEmbeddingProvider() (line 62) is called before loadDotenv() (line 97), so when the embedding provider tries to read MEMORIX_EMBEDDING_API_KEY from process.env, the .env file hasn't been loaded yet.
Steps to Reproduce
- Add
MEMORIX_EMBEDDING_API_KEY=your-keyto~/.memorix/.env - Ensure
embedding.provider: apiis set in~/.memorix/memorix.yml - Run
memorix status - Observe: "Failed to init API embedding: No API key"
Environment
- OS: macOS
- Node.js: v24.12.0 (via nvm)
- Memorix version: latest (global npm install)
Fix
Move loadDotenv(project.rootPath) to before the getEmbeddingProvider() call in src/cli/commands/status.ts:
// Load dotenv BEFORE checking embedding provider
const { loadDotenv } = await import('../../config/dotenv-loader.js');
loadDotenv(project.rootPath);
// Then check embedding status
const provider = await getEmbeddingProvider();
Thanks for the clear report — the root cause was exactly the dotenv load order.
Fixed in #47:
memorix statusnow loads.envbefore embedding provider initialization- the same ordering issue was also fixed in
doctorand the TUI health path - added regression tests for project
.env, user.env, and precedence behavior
This is now merged into main. If you update and still see the issue, feel free to reopen with your exact config path / command output.
感谢你把根因写得这么清楚,问题确实就是 dotenv 的加载顺序。
已经通过 #47 修复:
memorix status现在会在初始化 embedding provider 之前先加载.env- 同类顺序问题也一起修到了
doctor和 TUI health path - 还补了 project
.env、user.env以及优先级行为的回归测试
修复已经合入 main。如果你更新后仍然能复现,欢迎继续贴你的配置路径和命令输出。
Closing the loop here with an English-only summary: this was fixed in #47 and is already merged into main.
The fix loads .env before embedding-provider initialization in the affected CLI status/diagnostic paths, and also adds regression coverage for dotenv ordering so this does not drift back.
Thanks again for the precise report.
memorix dashboard is spitting out the same error @AVIDS2
Thanks for the follow-up. I checked the dashboard path and this looks like a remaining standalone-dashboard gap, not the original memorix status fix failing.
The original #46 fix moved dotenv loading before embedding-provider initialization in status, doctor, and the TUI health path. However, the standalone memorix dashboard /api/stats path can still ask the embedding provider for status before the dashboard config route has loaded .env, so it may still surface the same "No API key" symptom.
I will carry this into the next patch so standalone dashboard loads the project/user dotenv before reading embedding status, matching the CLI diagnostics behavior.
Temporary workarounds:
- restart any long-running Memorix/background process after changing
.env - or export the embedding key in the shell that starts
memorix dashboard - or use the control-plane dashboard after
memorix background startif that path is already loading your project config correctly
Thanks for catching the dashboard-specific path.
Thanks again for the dashboard-specific follow-up. I tracked this separately from the original \memorix status\ fix and fixed the remaining standalone dashboard path for the upcoming 1.0.10 patch.
The dashboard now prepares project-scoped config before /api/stats\ reads embedding status:
- loads project .env\ before embedding provider initialization
- initializes project \memorix.yml\ for dashboard routes
- clears project config when switching to a project whose root is unknown, so config does not bleed from the previous project
- adds regression coverage for the standalone dashboard stats path
Validation on my side:
- focused config/dashboard/LLM/TUI tests passed
pm run lint\ passed
pm run build\ passed- full
pm test\ exited successfully
I will update the release notes when 1.0.10 is published.