feat: Add output_dimension support for Voyage AI embeddings#2593
Closed
lagiosv wants to merge 1 commit intoHKUDS:mainfrom
Closed
feat: Add output_dimension support for Voyage AI embeddings#2593lagiosv wants to merge 1 commit intoHKUDS:mainfrom
lagiosv wants to merge 1 commit intoHKUDS:mainfrom
Conversation
Voyage AI's OpenAI-compatible API requires `output_dimension` to be passed via `extra_body` parameter instead of the standard `dimensions` parameter used by OpenAI. This change detects Voyage AI by checking if the base_url contains "voyageai.com" and routes the embedding_dim parameter appropriately: - For Voyage AI: passes `output_dimension` via `extra_body` - For OpenAI and others: passes `dimensions` directly (existing behavior) This fixes dimension mismatch issues when using Voyage AI models like voyage-3-large with custom dimensions (e.g., 2048 instead of default 1024). Related issues: #2233, #2230, #2119
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 custom embedding dimensions when using Voyage AI's embedding models through the OpenAI-compatible API.
Problem
LightRAG's OpenAI embedding binding passes the
dimensionsparameter directly to the API. However, Voyage AI's OpenAI-compatible endpoint requires the dimension parameter to be passed asoutput_dimensionvia theextra_bodyparameter.Without this fix:
embedding_dimis configured (e.g., 2048)dimensionsparameterRelated issues: #2233, #2230, #2119
Solution
Detect Voyage AI by checking if
base_urlcontains "voyageai.com" and route the dimension parameter appropriately:output_dimensionviaextra_bodyparameterdimensionsdirectly (existing behavior)Changes
lightrag/llm/openai.pyTesting
Tested with:
voyage-3-largemodelembedding_dim=2048Verified embeddings are correctly 2048-dimensional.
Backwards Compatibility
embedding_dimis explicitly set