Skip to content

feat: add LiteLLM API base and API key config#1043

Open
lastguru-net wants to merge 1 commit into
basicmachines-co:mainfrom
lastguru-net:feat/litellm-api-base
Open

feat: add LiteLLM API base and API key config#1043
lastguru-net wants to merge 1 commit into
basicmachines-co:mainfrom
lastguru-net:feat/litellm-api-base

Conversation

@lastguru-net

Copy link
Copy Markdown

Summary

  • Add semantic_embedding_api_base / BASIC_MEMORY_SEMANTIC_EMBEDDING_API_BASE for LiteLLM embeddings.
  • Add semantic_embedding_api_key / BASIC_MEMORY_SEMANTIC_EMBEDDING_API_KEY for LiteLLM embeddings.
  • Pass configured api_base and api_key through to LiteLLM embedding calls.
  • Preserve existing provider environment variable behavior by omitting api_key when it is not configured.
  • Update LiteLLM and semantic-search docs with local OpenAI-compatible endpoint examples and reindex guidance.

Why

Fixes #1005.

Basic Memory can already use LiteLLM for embeddings, but there was no first-class way to point it at a custom OpenAI-compatible embedding endpoint. This blocks local/self-hosted embedding setups that need an api_base, such as TEI, vLLM, Ollama-compatible proxies, LiteLLM proxy deployments, or private OpenAI-compatible embedding services.

Relying only on ambient environment variables is awkward for Basic Memory deployments because the semantic embedding endpoint belongs with the rest of Basic Memory config. Some OpenAI-compatible local endpoints still require a placeholder or deployment-specific API key, so semantic_embedding_api_key is needed alongside semantic_embedding_api_base. The configured key must not break existing setups that provide credentials through OPENAI_API_KEY or provider-specific environment variables, so Basic Memory only passes api_key when the config value is explicitly set.

Design Notes

api_base and api_key are request-routing inputs, not Basic Memory vector identity fields. They are intentionally not included in the persisted embedding model key. They are also not added to the provider cache key, because equivalent LiteLLM routing can be supplied through environment variables outside Basic Memory config.

Changing provider, model, dimensions, dimension forwarding, or LiteLLM document/query role settings still changes vector identity and requires reindexing. Changing only api_base is not treated as a Basic Memory vector identity change. Operators remain responsible for reindexing if a different endpoint serves semantically different embeddings under the same configured model/dimensions.

Testing

Both repository test and live test has been completed: the new configuration is applied and worked as expected.

@CLAassistant

CLAassistant commented Jul 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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: 60eb16dd0a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/basic_memory/repository/embedding_provider_factory.py
Add first-class LiteLLM embedding routing configuration for Basic Memory:

- add semantic_embedding_api_base / BASIC_MEMORY_SEMANTIC_EMBEDDING_API_BASE
- add semantic_embedding_api_key / BASIC_MEMORY_SEMANTIC_EMBEDDING_API_KEY
- pass configured api_base and api_key through to LiteLLM embedding calls
- preserve existing environment credential fallback by omitting api_key when unset
- keep LiteLLM routing values out of persisted vector identity
- separate process-local provider cache entries for explicit api_base/api_key using digests only
- update LiteLLM and semantic-search documentation for local OpenAI-compatible endpoints

Why:
Basic Memory already supports LiteLLM embeddings, but it did not have a first-class way to point semantic embeddings at a custom OpenAI-compatible endpoint. That blocks local and self-hosted embedding deployments such as TEI, vLLM, Ollama-compatible proxies, LiteLLM proxy deployments, and private OpenAI-compatible embedding services. Some endpoints also require a placeholder or deployment-specific API key, so api_key needs to be configurable alongside api_base.

The configured routing values are request-routing inputs, not vector identity fields. Changing only api_base/api_key does not automatically require a Basic Memory reindex, though operators still need to reindex if the endpoint serves semantically different embeddings under the same configured model and dimensions.

Fixes basicmachines-co#1005.

Signed-off-by: Dmitry Golubev <lastguru@gmail.com>
@lastguru-net

Copy link
Copy Markdown
Author

@codex review

@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: 222e99699a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/basic_memory/repository/litellm_provider.py
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.

[FEATURE] Add api_base support for LiteLLM semantic embedding providers

2 participants