Skip to content

feat(embedding): support provider-agnostic OpenAI-compat endpoint#153

Closed
MichaelChristopher wants to merge 1 commit intogarrytan:masterfrom
MichaelChristopher:pr/ollama-env-vars
Closed

feat(embedding): support provider-agnostic OpenAI-compat endpoint#153
MichaelChristopher wants to merge 1 commit intogarrytan:masterfrom
MichaelChristopher:pr/ollama-env-vars

Conversation

@MichaelChristopher
Copy link
Copy Markdown

Summary

Adds environment variable support for configuring embedding providers, enabling local models (Ollama, llama.cpp) and other OpenAI-compatible endpoints without code changes.

New env vars:

  • GBRAIN_EMBED_MODEL — override embedding model (default: text-embedding-3-large)
  • GBRAIN_EMBED_DIMENSIONS — override vector dimensions (default: 1536)
  • OPENAI_BASE_URL — point to non-OpenAI providers (e.g. http://localhost:11434/v1 for Ollama)

The dimensions parameter is only sent for OpenAI-native models (those starting with text-embedding-) to avoid breaking non-OpenAI providers that don't support it.

Motivation

Running gbrain with local embedding models (nomic-embed-text via Ollama) currently requires patching embedding.ts. This PR makes the provider configurable at runtime, which is useful for:

  • Privacy-sensitive deployments
  • Offline/airgapped environments
  • Cost reduction (local vs cloud)

Changes

  • src/core/embedding.ts: 8 insertions, 4 deletions

Read model/dimensions/baseURL from env vars so gbrain can route
embeddings through local Ollama (nomic-embed-text) or any OpenAI-compat
provider instead of hard-coding OpenAI text-embedding-3-large.

Env vars added:
- GBRAIN_EMBED_MODEL (default: text-embedding-3-large)
- GBRAIN_EMBED_DIMENSIONS (default: 1536)
- OPENAI_BASE_URL (for non-OpenAI providers)

The dimensions parameter is only sent when the model name starts with
"text-embedding-" (OpenAI-native Matryoshka truncation). Non-OpenAI
providers do not support this parameter.

Local patch 0001/0004 for Phase B gbrain adoption.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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