Skip to content

feat: per-purpose inference config (LLM / embedder / graph) - #9

Merged
ttupper92618 merged 4 commits into
mainfrom
feat/per-purpose-inference
Mar 14, 2026
Merged

feat: per-purpose inference config (LLM / embedder / graph)#9
ttupper92618 merged 4 commits into
mainfrom
feat/per-purpose-inference

Conversation

@ttupper92618

Copy link
Copy Markdown
Contributor

Summary

  • Adds per-purpose env vars so each inference role (main LLM, embedder, graph LLM) can target a different endpoint, API key, and model independently
  • Adds MEM0_GRAPH_EXTRACTION_STRATEGY env var to select between tool_calling (default) and json_prompting for graph entity extraction
  • All new vars fall back to the shared OPENAI_BASE_URL / OPENAI_API_KEY — existing deployments are unaffected

New environment variables

Variable Purpose Fallback
MEM0_LLM_BASE_URL Main LLM endpoint OPENAI_BASE_URL
MEM0_LLM_API_KEY Main LLM API key OPENAI_API_KEY
MEM0_EMBED_BASE_URL Embedder endpoint OPENAI_BASE_URL
MEM0_EMBED_API_KEY Embedder API key OPENAI_API_KEY
MEM0_GRAPH_LLM_BASE_URL Graph LLM endpoint OPENAI_BASE_URL
MEM0_GRAPH_LLM_API_KEY Graph LLM API key OPENAI_API_KEY
MEM0_GRAPH_EXTRACTION_STRATEGY tool_calling or json_prompting tool_calling

Example: local main LLM + cloud embedder + cloud graph

MEM0_LLM_BASE_URL=http://exo:8000/v1
MEM0_LLM_API_KEY=not-needed
MEM0_LLM_MODEL=llama-3.1-8b

MEM0_EMBED_BASE_URL=https://api.openai.com/v1
MEM0_EMBED_API_KEY=sk-...
MEM0_EMBED_MODEL=text-embedding-3-small

MEM0_GRAPH_LLM_BASE_URL=https://api.openai.com/v1
MEM0_GRAPH_LLM_API_KEY=sk-...
MEM0_GRAPH_LLM_MODEL=gpt-4.1-nano

Test plan

  • npx tsc --noEmit passes
  • With no new vars set: behaves identically to current (all shared OPENAI_*)
  • With per-purpose vars set: each Memory config section uses the correct endpoint/key

🤖 Generated with Claude Code

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/index.ts

// 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/index.ts
Comment on lines +522 to +523
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) },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/index.ts Outdated
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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment thread src/index.ts Outdated
Comment on lines +54 to +57
const GRAPH_EXTRACTION_STRATEGY = process.env.MEM0_GRAPH_EXTRACTION_STRATEGY as
| "tool_calling"
| "json_prompting"
| undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>
@ttupper92618
ttupper92618 merged commit 0a0d7b1 into main Mar 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant