feat: per-purpose inference config (LLM / embedder / graph) - #9
Conversation
Each purpose can now target a different endpoint/provider via: - MEM0_LLM_BASE_URL / MEM0_LLM_API_KEY (main LLM) - MEM0_EMBED_BASE_URL / MEM0_EMBED_API_KEY (embedder) - MEM0_GRAPH_LLM_BASE_URL / MEM0_GRAPH_LLM_API_KEY (graph LLM) - MEM0_GRAPH_EXTRACTION_STRATEGY (tool_calling or json_prompting) All fall back to shared OPENAI_BASE_URL / OPENAI_API_KEY when not set, so existing deployments are unaffected. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2ceb9093e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| // Main LLM (fact extraction, memory decisions) | ||
| const LLM_BASE_URL = process.env.MEM0_LLM_BASE_URL || OPENAI_BASE_URL; | ||
| const LLM_API_KEY = process.env.MEM0_LLM_API_KEY || OPENAI_API_KEY; |
There was a problem hiding this comment.
Derive auth diagnostics from per-purpose API keys
By introducing MEM0_LLM_API_KEY/MEM0_EMBED_API_KEY/MEM0_GRAPH_LLM_API_KEY, deployments can now authenticate without setting OPENAI_API_KEY, but authMode and openaiApiKeyConfigured are still computed from process.env.OPENAI_API_KEY only. In that valid configuration, /health and startup diagnostics will incorrectly report local-default and false, which can mislead operators and monitoring when triaging production incidents. Please compute diagnostics from the effective keys (or expose per-purpose auth diagnostics) instead of the legacy shared variable.
Useful? React with 👍 / 👎.
authMode and health diagnostics now reflect per-purpose keys (MEM0_LLM_API_KEY, MEM0_EMBED_API_KEY, MEM0_GRAPH_LLM_API_KEY) instead of only the shared OPENAI_API_KEY. Base URLs are also reported per-purpose. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6b3832a39
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| apiKeyConfigured: { llm: HAS_LLM_API_KEY, embed: HAS_EMBED_API_KEY, graphLlm: HAS_GRAPH_LLM_API_KEY }, | ||
| baseUrl: { llm: sanitizeBaseUrl(LLM_BASE_URL), embed: sanitizeBaseUrl(EMBED_BASE_URL), graphLlm: sanitizeBaseUrl(GRAPH_LLM_BASE_URL) }, |
There was a problem hiding this comment.
Preserve legacy health diagnostics fields
This change swaps diagnostics.openaiApiKeyConfigured/diagnostics.openaiBaseUrl for diagnostics.apiKeyConfigured/diagnostics.baseUrl in the health payloads, which is a breaking response-shape change for existing monitors and clients that read the old keys (the same replacement is also present in /v2/health). Because this commit is framed as per-purpose config support rather than a versioned API contract change, dropping the legacy fields will cause production integrations to see missing values immediately after deploy; keep the old fields as aliases (or explicitly version the schema) to avoid regressions.
Useful? React with 👍 / 👎.
Restores openaiApiKeyConfigured and openaiBaseUrl alongside the new per-purpose apiKeyConfigured/baseUrl objects so existing monitors and integrations that read the old keys continue working. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 987d3c9f16
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const HAS_LLM_API_KEY = Boolean(process.env.MEM0_LLM_API_KEY || process.env.OPENAI_API_KEY); | ||
| const HAS_EMBED_API_KEY = Boolean(process.env.MEM0_EMBED_API_KEY || process.env.OPENAI_API_KEY); | ||
| const HAS_GRAPH_LLM_API_KEY = Boolean(process.env.MEM0_GRAPH_LLM_API_KEY || process.env.OPENAI_API_KEY); | ||
| const AUTH_MODE = (HAS_LLM_API_KEY || HAS_EMBED_API_KEY || HAS_GRAPH_LLM_API_KEY) ? "api_key" : "local-default"; |
There was a problem hiding this comment.
Exclude disabled graph auth from global auth mode
AUTH_MODE now turns api_key on whenever MEM0_GRAPH_LLM_API_KEY is set, even if graph memory is disabled (NEO4J_URL/NEO4J_PASSWORD unset). In that configuration the service can still be running fully local for the active LLM/embed paths, but /health and startup diagnostics report api_key, which creates false-positive auth diagnostics for operators. Gate the graph key contribution on GRAPH_ENABLED so auth mode reflects only active inference paths.
Useful? React with 👍 / 👎.
| const GRAPH_EXTRACTION_STRATEGY = process.env.MEM0_GRAPH_EXTRACTION_STRATEGY as | ||
| | "tool_calling" | ||
| | "json_prompting" | ||
| | undefined; |
There was a problem hiding this comment.
Validate graph extraction strategy env before use
MEM0_GRAPH_EXTRACTION_STRATEGY is force-cast to a union type without runtime validation, so any non-empty typo (for example tool-calls) is accepted and later passed through to graphStore.extractionStrategy when graph is enabled. Because this setting is documented as a 2-value enum, forwarding unchecked strings can cause runtime graph-write failures from misconfiguration instead of a clear startup/config error.
Useful? React with 👍 / 👎.
…NABLED - MEM0_GRAPH_EXTRACTION_STRATEGY is now validated at startup; typos log a warning and fall back to "tool_calling" instead of silently passing through - AUTH_MODE only considers graph LLM API key when graph memory is actually enabled (NEO4J_URL + NEO4J_PASSWORD set) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
MEM0_GRAPH_EXTRACTION_STRATEGYenv var to select betweentool_calling(default) andjson_promptingfor graph entity extractionOPENAI_BASE_URL/OPENAI_API_KEY— existing deployments are unaffectedNew environment variables
MEM0_LLM_BASE_URLOPENAI_BASE_URLMEM0_LLM_API_KEYOPENAI_API_KEYMEM0_EMBED_BASE_URLOPENAI_BASE_URLMEM0_EMBED_API_KEYOPENAI_API_KEYMEM0_GRAPH_LLM_BASE_URLOPENAI_BASE_URLMEM0_GRAPH_LLM_API_KEYOPENAI_API_KEYMEM0_GRAPH_EXTRACTION_STRATEGYtool_callingorjson_promptingtool_callingExample: local main LLM + cloud embedder + cloud graph
Test plan
npx tsc --noEmitpassesOPENAI_*)🤖 Generated with Claude Code