feat(embeddings): support custom OpenAI baseURL for Ollama / OpenAI-compatible providers#82
Open
pylyp-gh wants to merge 3 commits into
Open
feat(embeddings): support custom OpenAI baseURL for Ollama / OpenAI-compatible providers#82pylyp-gh wants to merge 3 commits into
pylyp-gh wants to merge 3 commits into
Conversation
…ompatible providers
Adds an optional `base_url` field under `embedding.openai` in the config
schema (and `OPENAI_BASE_URL` env var fallback). When set, it is passed
to the OpenAI SDK constructor as `baseURL`, allowing doc2vec to embed
documents via any OpenAI-compatible endpoint — Ollama, LM Studio, vLLM,
llama.cpp server, internal LLM gateways, etc.
Conditional spread keeps the default behaviour identical when no base
URL is provided; existing configs continue to hit api.openai.com.
The chosen endpoint is now revealed in the startup log line for clearer
diagnostics ("Using OpenAI ... via http://localhost:11434/v1").
…ripts `npm install --ignore-scripts` (security best-practice — blocks malicious postinstall scripts) skips node-gyp compilation for native modules. The better-sqlite3 binding is therefore never built unless a prebuilt binary exists for the target arch/Node combination. On linux/arm64 (Apple Silicon, ARM Linux runners) no prebuild ships, so runtime fails with "Could not locate the bindings file" the moment any SQLite source tries to open a database. Adding an explicit `npm rebuild better-sqlite3` after install keeps the security guarantee for unrelated scripts while compiling the one native module the tool actually needs.
The reader-side MCP server (mcp/src/index.ts) also instantiated the OpenAI client with apiKey only. It now reads OPENAI_BASE_URL from the environment and threads it into the constructor via conditional spread, mirroring the writer-side fix introduced earlier on this branch. This lets users point both halves of the doc2vec pipeline (the writer CLI for building vector DBs and the MCP server for querying them) at any OpenAI-compatible endpoint — Ollama, LM Studio, vLLM, llama.cpp server, internal LLM gateways — through a single env var per process. Default behaviour unchanged when OPENAI_BASE_URL is unset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional
embedding.openai.base_urlconfig field (andOPENAI_BASE_URLenv var fallback) so doc2vec can use any OpenAI-compatible embedding endpoint, not justapi.openai.com. Concrete use cases: running doc2vec against a local Ollama instance (nomic-embed-text,mxbai-embed-largemodels), self-hosted vLLM / LM Studio / llama.cpp servers, or internal LLM gateways with OpenAI-compatible facades.Why
The OpenAI SDK constructor accepts
baseURLfor endpoint redirection, but doc2vec currently hardcodes it implicitly to the default (https://api.openai.com/v1). Users who run local embedding stacks have had to fork doc2vec or pay for OpenAI even when they have a perfectly capable local model.Change
types.ts— addedbase_url?: stringtoEmbeddingConfig.openai.doc2vec.ts— readembeddingConfig.openai?.base_url || process.env.OPENAI_BASE_URL, spread into thenew OpenAI({ ... })options only when truthy (conditional spread → backwards-compatible).Backwards compatibility
Zero impact for existing configs. The field is optional; when absent, the OpenAI SDK falls back to its default base URL — identical to today's behaviour.
Test plan
base_url) — unchanged: SDK hitsapi.openai.com.base_url: http://localhost:11434/v1+ local Ollama — embeddings generated successfully againstnomic-embed-text(768d).OPENAI_BASE_URLenv var fallback works when config omits the field.Example config