feat: configurable embedding provider, model, and dimensions via environment variables#77
Open
Ashwin-3cS wants to merge 3 commits intoMystenLabs:devfrom
Open
Conversation
Add five env vars so self-hosters can swap in any OpenAI-compatible embedding provider (Jina, Cohere, OpenRouter) and any LLM without touching code Fallback chain: EMBEDDING_API_KEY → OPENAI_API_KEY, EMBEDDING_API_BASE → OPENAI_API_BASE. Mock embedding path respects EMBEDDING_DIMENSIONS so dev/test dimensions stay consistent. Server logs a WARN at boot if the schema column dimension doesn't match EMBEDDING_DIMENSIONS.
Add EMBEDDING_API_KEY, EMBEDDING_API_BASE, EMBEDDING_MODEL, EMBEDDING_DIMENSIONS, and LLM_MODEL to environment-variables.md and self-hosting.md. Includes Jina example values in .env.example and a warning about not mixing embedding dimensions across memories.
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.
Description
The server currently hardcodes
openai/text-embedding-3-smallfor embeddings andopenai/gpt-4o-minifor LLM calls. This limits flexibility for self-hosters who may want to:1024for Jina v3)At the moment, achieving this requires modifying the source code.
Changes
Configuration (
types.rs)Adds five new
Configfields, all read from environment variables:This improves flexibility for developers in the ecosystem by allowing different providers, models, and configurations without modifying source code.
Embedding + LLM usage (
routes.rs)generate_embedding()now uses a fallback chain:EMBEDDING_API_KEY → OPENAI_API_KEYEMBEDDING_API_BASE → OPENAI_API_BASEdimensionsfield to embedding API requestskip_serializing_if = "Option::is_none"for provider compatibilityconfig.llm_modelin all call sitesEMBEDDING_DIMENSIONSfor consistency in dev/testServer startup (
main.rs)WARNifEMBEDDING_DIMENSIONSdoes not match the schema column dimensionEnvironment config (
.env.example)Documentation (
docs/)environment-variables.mdself-hosting.mdDocumentation has been updated to reflect these changes. If any adjustments or clarifications are needed, feel free to point them out and I'll follow up in this PR.
Backwards Compatibility
All new variables have defaults that preserve the current behavior.
Existing deployments with no
.envchanges remain unaffected.Test
EMBEDDING_MODEL=jina-embeddings-v3,EMBEDDING_DIMENSIONS=1024)