feat: add OpenAI-compatible embeddings backend support#39
Open
feat: add OpenAI-compatible embeddings backend support#39
Conversation
Add a generic "openai" backend that works with any service exposing the OpenAI /v1/embeddings wire format (OpenAI, Voyage AI, Azure OpenAI, Together AI, etc.). - New embedder implementation with Bearer token auth, rate-limit (429) retry, and configurable base URL via OPENAI_BASE_URL - Register OpenAI (text-embedding-3-small/large, ada-002) and Voyage AI (voyage-code-3, voyage-3-large) models in KnownModels - Extend config with BackendOpenAI, OPENAI_API_KEY validation at load - Wire backend in factory and health check with 401 detection - Full test coverage matching existing backend test patterns https://claude.ai/code/session_012e2TZ36P7dcbmBd2HjQrQk
|
|
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
This PR adds support for OpenAI-compatible embedding APIs (OpenAI, Voyage AI, Azure OpenAI, Together AI, etc.) as a new embedder backend alongside the existing Ollama and LM Studio implementations.
Key Changes
New OpenAI embedder implementation (
internal/embedder/openai.go):Embedderinterface for OpenAI-compatible/v1/embeddingsendpointsComprehensive test coverage (
internal/embedder/openai_test.go):Configuration updates (
internal/config/config.go):BackendOpenAIconstant and configuration fields (OpenAIBaseURL,OpenAIAPIKey)OPENAI_API_KEYenvironment variable validationtext-embedding-3-smallmodel for OpenAI backendModel registry expansion (
internal/embedder/models.go,internal/embedder/models_test.go):text-embedding-3-small,text-embedding-3-large,text-embedding-ada-002,voyage-code-3,voyage-3-largeEmbedder factory (
cmd/embedder.go):newEmbedder()to instantiate OpenAI embedder when backend is "openai"Health check improvements (
cmd/stdio.go):Documentation (
CLAUDE.md):Implementation Details
sethvargo/go-retryfor exponential backoff retry logic with configurable max retrieshttps://claude.ai/code/session_012e2TZ36P7dcbmBd2HjQrQk