Commit 45f8e19
committed
fix(embed): allow separate OPENAI_EMBEDDING_BASE_URL + OPENAI_EMBEDDING_API_KEY
The OpenAI-compat embedding provider previously read OPENAI_BASE_URL and
OPENAI_API_KEY only, which the chat-LLM path (src/providers/openai.ts)
also reads. That couples both calls to the same endpoint — so operators
who want, say, chat completions on a fast hosted provider (Novita /
DeepInfra) and embeddings on a self-hosted vLLM cluster (Qwen3-Embedding-8B
on a dedicated GPU) had to either move both to the same endpoint or run
agentmemory against a single provider with whatever embedding model it
happens to expose.
Add two embedding-scoped overrides with fallback to the existing vars:
OPENAI_EMBEDDING_BASE_URL → falls back to OPENAI_BASE_URL → default
OPENAI_EMBEDDING_API_KEY → falls back to OPENAI_API_KEY → required
The fallback chain keeps existing setups working without any .env
changes. New setups can mix and match — common patterns:
# vLLM (self-hosted GPU, free, batchable) for embeddings + Novita (DeepSeek V4 Flash) for chat
OPENAI_BASE_URL=https://api.novita.ai/v3/openai
OPENAI_API_KEY=sk-novita-...
OPENAI_EMBEDDING_BASE_URL=https://embed.your.lan
OPENAI_EMBEDDING_API_KEY=local-no-auth # endpoints that ignore Authorization
OPENAI_EMBEDDING_MODEL=Qwen3-Embedding-8B
OPENAI_EMBEDDING_DIMENSIONS=4096
# Local Ollama for embeddings + remote for chat
OPENAI_BASE_URL=https://api.openai.com
OPENAI_API_KEY=sk-...
OPENAI_EMBEDDING_BASE_URL=http://localhost:11434
OPENAI_EMBEDDING_API_KEY=ollama
OPENAI_EMBEDDING_MODEL=nomic-embed-text
The separate API key matters because most local endpoints
(Ollama / LM Studio / llama.cpp / vLLM) ignore Authorization entirely
but Node fetch still requires a non-empty Bearer token. Setting
OPENAI_EMBEDDING_API_KEY=anything-truthy unblocks that case without
revealing the real OPENAI_API_KEY to whatever's on localhost.
No code-paths other than the embedding provider are touched. Reviewed
against the 17 existing test cases in test/embedding-provider.test.ts;
no regression (the 6 pre-existing failures on main are env-pollution
when ~/.agentmemory/.env has API keys set, unrelated to this change).1 parent 29e6ebd commit 45f8e19
2 files changed
Lines changed: 44 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
61 | 75 | | |
62 | 76 | | |
63 | 77 | | |
| |||
69 | 83 | | |
70 | 84 | | |
71 | 85 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
75 | 106 | | |
76 | 107 | | |
77 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
0 commit comments