Add configurable embedding provider support#134
Open
100yenadmin wants to merge 1 commit intogarrytan:masterfrom
Open
Add configurable embedding provider support#134100yenadmin wants to merge 1 commit intogarrytan:masterfrom
100yenadmin wants to merge 1 commit intogarrytan:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an env-driven configuration layer to the embedding subsystem so deployments can switch embedding provider/model/dimensions (defaulting to the current OpenAI setup) and records the embedding model used when writing chunk updates.
Changes:
- Introduce
getEmbeddingConfig()and wireembedBatchto supportopenai(default) andvoyageproviders. - Persist the configured embedding model onto chunk updates in the
gbrain embedcommand. - Add docs and tests covering the new configuration path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| test/embed.test.ts | Adds unit tests for embedding config defaults/overrides and extends env cleanup. |
| src/core/embedding.ts | Implements env-driven embedding config and adds Voyage embeddings implementation. |
| src/commands/embed.ts | Records embedding model on chunk upserts during embedding runs. |
| README.md | Notes embedding provider/model/dimensions env vars in CLI help. |
| INSTALL_FOR_AGENTS.md | Documents optional embedding provider overrides and Voyage API key. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+37
to
+55
| export function getEmbeddingConfig(): EmbeddingConfig { | ||
| const providerRaw = (process.env.EMBEDDING_PROVIDER || DEFAULT_PROVIDER).toLowerCase(); | ||
| const model = process.env.EMBEDDING_MODEL || DEFAULT_MODEL; | ||
| const dimensionsRaw = process.env.EMBEDDING_DIMENSIONS; | ||
| const dimensions = dimensionsRaw ? parseInt(dimensionsRaw, 10) : DEFAULT_DIMENSIONS; | ||
|
|
||
| if (providerRaw !== 'openai' && providerRaw !== 'voyage') { | ||
| throw new Error(`Unsupported embedding provider: ${providerRaw}. Expected openai or voyage.`); | ||
| } | ||
|
|
||
| if (dimensionsRaw && Number.isNaN(dimensions)) { | ||
| throw new Error(`Invalid EMBEDDING_DIMENSIONS: ${dimensionsRaw}`); | ||
| } | ||
| return client; | ||
|
|
||
| return { | ||
| provider: providerRaw, | ||
| model, | ||
| dimensions, | ||
| }; |
Comment on lines
72
to
79
| const updated: ChunkInput[] = chunks.map(c => ({ | ||
| chunk_index: c.chunk_index, | ||
| chunk_text: c.chunk_text, | ||
| chunk_source: c.chunk_source, | ||
| embedding: embeddingMap.get(c.chunk_index), | ||
| model: embeddingConfig.model, | ||
| token_count: c.token_count || Math.ceil(c.chunk_text.length / 4), | ||
| })); |
Comment on lines
122
to
129
| const updated: ChunkInput[] = chunks.map(c => ({ | ||
| chunk_index: c.chunk_index, | ||
| chunk_text: c.chunk_text, | ||
| chunk_source: c.chunk_source, | ||
| embedding: embeddingMap.get(c.chunk_index) ?? undefined, | ||
| model: embeddingConfig.model, | ||
| token_count: c.token_count || Math.ceil(c.chunk_text.length / 4), | ||
| })); |
Comment on lines
+2
to
3
| import { getEmbeddingConfig } from '../src/core/embedding.ts'; | ||
| import type { BrainEngine } from '../src/core/engine.ts'; |
Comment on lines
+38
to
+42
| const providerRaw = (process.env.EMBEDDING_PROVIDER || DEFAULT_PROVIDER).toLowerCase(); | ||
| const model = process.env.EMBEDDING_MODEL || DEFAULT_MODEL; | ||
| const dimensionsRaw = process.env.EMBEDDING_DIMENSIONS; | ||
| const dimensions = dimensionsRaw ? parseInt(dimensionsRaw, 10) : DEFAULT_DIMENSIONS; | ||
|
|
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
Validation
Closes #133