Fix missing OpenAI embeddings key handling - #1007
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
rcjasub
left a comment
There was a problem hiding this comment.
Requesting changes — the fix moves the missing-key check to module load time instead of scoping it to where the key is actually used, which introduces a regression.
packages/db/src/utils/get-embedding.ts now throws as soon as the module is imported, not when getEmbedding() is called. queries.ts statically imports getEmbedding, and its getDefaultDropdownItems() (lines 38–77) never calls it — it only queries IMPs/seed products directly. So the nav-bar's default (empty-query) search dropdown now hard-crashes whenever OPENAI_EMBEDDINGS_KEY is missing, even though that path never touched embeddings before. It also bypasses the graceful-degradation try/catch already in queries.ts/search.ts, since those only wrap runtime calls, not module evaluation.
Suggestion: move the check inside getEmbedding() (or lazily construct the client on first call), consistent with how connection.ts handles DATABASE_URL — checked lazily, at use time, not at import.
Otherwise the fix is correct and the error message is clear for #1004 — just needs to be scoped narrower before merging. Let me know how that goes.
Description
Fixes #1004
Removes the
NOTAKEYfallback forOPENAI_EMBEDDINGS_KEYin the OpenAI embeddings client setup.Previously, when
OPENAI_EMBEDDINGS_KEYwas missing, the app initialized the OpenAI client with the placeholder valueNOTAKEY, causing inference search to fail later with a generic OpenAI/auth error. This change fails early with a clear missing environment variable error, making the root cause easier to diagnose in logs.Checklist