Repository navigation
feat(voyage): add multimodal embedding support for voyage-multimodal-3/3.5 - #24972
1 commit merged into
Conversation
…3/3.5 Route voyage-multimodal-* models to the correct /v1/multimodalembeddings endpoint and transform inputs to the Voyage multimodal format. Supports text, image_url, image_base64, video_url, and video_base64 content types. Fixes BerriAI#24957 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds proper multimodal embedding support for Voyage's Key changes:
Issues found:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/llms/voyage/embedding/transformation_multimodal.py | New VoyageMultimodalEmbeddingConfig class — routes to /v1/multimodalembeddings endpoint; has a silent empty-list bug and mixed-type list issue in input conversion, and conflates prompt_tokens with total_tokens in usage. |
| litellm/utils.py | Adds multimodal routing in get_optional_params_embeddings and ProviderConfigManager.get_provider_embedding_config — consistent with existing contextual pattern. |
| litellm/model_prices_and_context_window_backup.json | Adds voyage-multimodal-3.5 pricing entry and adds supports_vision flag to voyage-multimodal-3; pricing matches voyage-multimodal-3. |
| tests/test_litellm/llms/voyage/embedding/test_voyage_multimodal_embedding.py | 32 unit tests with mocked HTTP responses covering URL generation, param mapping, input conversion, response parsing, and config routing — no live network calls. |
| litellm/init.py | TYPE_CHECKING export for VoyageMultimodalEmbeddingConfig added correctly. |
| litellm/_lazy_imports_registry.py | Lazy import registry entries for VoyageMultimodalEmbeddingConfig added correctly. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["litellm.embedding(model='voyage/...')"] --> B{Provider = VOYAGE?}
B -- Yes --> C{is_contextualized_embeddings?}
C -- Yes --> D[VoyageContextualEmbeddingConfig\n/v1/contextualizedembeddings]
C -- No --> E{is_multimodal_embeddings?}
E -- Yes --> F[VoyageMultimodalEmbeddingConfig\n/v1/multimodalembeddings]
E -- No --> G[VoyageEmbeddingConfig\n/v1/embeddings]
F --> H[_convert_input_to_multimodal]
H --> I{input type?}
I -- str --> J[Wrap in text content block]
I -- "List[str]" --> K[Wrap each in text content block]
I -- "List[dict]" --> L[Convert each block via\n_convert_content_block]
I -- "empty list []" --> M["⚠️ Falls through to str(input) = '[]'"]
L --> N{block type?}
N -- text --> O[Pass through]
N -- image_url str --> P[Voyage image_url]
N -- "image_url {url:...}" --> Q[Extract URL → Voyage image_url]
N -- "data: URI" --> R[Convert to image_base64]
N -- video_url/video_base64 --> S[Pass through]
Reviews (1): Last reviewed commit: "feat(voyage): add multimodal embedding s..." | Re-trigger Greptile
| if isinstance(input, list) and len(input) > 0: | ||
| if isinstance(input[0], str): | ||
| return [{"content": [{"type": "text", "text": text}]} for text in input] | ||
|
|
||
| if isinstance(input[0], dict): | ||
| inputs = [] | ||
| for item in input: | ||
| if "content" in item: | ||
| content = item["content"] | ||
| converted = [] | ||
| for block in content: | ||
| converted.append(_convert_content_block(block)) | ||
| inputs.append({"content": converted}) | ||
| else: | ||
| inputs.append({"content": [_convert_content_block(item)]}) | ||
| return inputs | ||
|
|
||
| return [{"content": [{"type": "text", "text": str(input)}]}] |
There was a problem hiding this comment.
Empty list silently produces wrong payload
When input is an empty list ([]), the guard len(input) > 0 is False, so the function falls through to the catch-all at line 134:
return [{"content": [{"type": "text", "text": str(input)}]}]This returns [{"content": [{"type": "text", "text": "[]"}]}] — a single-element request containing the literal string "[]". Depending on the API, this may silently return an embedding for that string rather than raising an error, which is unexpected behavior.
| if isinstance(input, list) and len(input) > 0: | |
| if isinstance(input[0], str): | |
| return [{"content": [{"type": "text", "text": text}]} for text in input] | |
| if isinstance(input[0], dict): | |
| inputs = [] | |
| for item in input: | |
| if "content" in item: | |
| content = item["content"] | |
| converted = [] | |
| for block in content: | |
| converted.append(_convert_content_block(block)) | |
| inputs.append({"content": converted}) | |
| else: | |
| inputs.append({"content": [_convert_content_block(item)]}) | |
| return inputs | |
| return [{"content": [{"type": "text", "text": str(input)}]}] | |
| if isinstance(input, list): | |
| if len(input) == 0: | |
| return [] | |
| if isinstance(input[0], str): | |
| return [{"content": [{"type": "text", "text": text}]} for text in input] | |
| if isinstance(input[0], dict): | |
| inputs = [] | |
| for item in input: | |
| if "content" in item: | |
| content = item["content"] | |
| converted = [] | |
| for block in content: | |
| converted.append(_convert_content_block(block)) | |
| inputs.append({"content": converted}) | |
| else: | |
| inputs.append({"content": [_convert_content_block(item)]}) | |
| return inputs | |
| return [{"content": [{"type": "text", "text": str(input)}]}] |
| if block_type == "image_base64": | ||
| return { | ||
| "type": "image_base64", | ||
| "image_base64": block.get("image_base64", ""), |
There was a problem hiding this comment.
Hardcoded model-detection flag should live in model JSON
is_multimodal_embeddings hard-codes routing logic by doing "multimodal" in model.lower(). Per the team's rule on model-specific flags, this logic should instead be expressed as a field in model_prices_and_context_window_backup.json (e.g. "litellm_multimodal_embedding": true) and resolved at runtime via get_model_info. That way future multimodal Voyage models are handled automatically without a code change.
Note that the existing VoyageContextualEmbeddingConfig.is_contextualized_embeddings uses the same substring-match pattern, so this is following established codebase precedent — but the custom rule flags both as the preferred pattern to migrate away from.
Rule Used: What: Do not hardcode model-specific flags in the ... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| if isinstance(input, list) and len(input) > 0: | ||
| if isinstance(input[0], str): | ||
| return [{"content": [{"type": "text", "text": text}]} for text in input] | ||
|
|
||
| if isinstance(input[0], dict): | ||
| inputs = [] | ||
| for item in input: | ||
| if "content" in item: | ||
| content = item["content"] | ||
| converted = [] | ||
| for block in content: | ||
| converted.append(_convert_content_block(block)) | ||
| inputs.append({"content": converted}) | ||
| else: | ||
| inputs.append({"content": [_convert_content_block(item)]}) | ||
| return inputs |
There was a problem hiding this comment.
Mixed-type list only inspects first element
The type-dispatch checks isinstance(input[0], str) / isinstance(input[0], dict), meaning the type of the first element governs how all elements are processed. A mixed list like ["plain text", {"content": [...]}] will silently stringify the dict by passing it through the str-branch list comprehension. Consider validating that all elements are the same type, or raising an explicit error for heterogeneous lists.
| logging_obj: LiteLLMLoggingObj, | ||
| api_key: Optional[str] = None, | ||
| request_data: dict = {}, | ||
| optional_params: dict = {}, | ||
| litellm_params: dict = {}, | ||
| ) -> EmbeddingResponse: | ||
| try: | ||
| raw_response_json = raw_response.json() | ||
| except Exception: |
There was a problem hiding this comment.
prompt_tokens conflated with total_tokens
The Voyage multimodal usage response includes text_tokens and image_pixels fields. Both prompt_tokens and total_tokens are currently set to total_tokens, which already includes pixel-based image cost. Setting prompt_tokens to text_tokens would be more semantically accurate for multimodal usage accounting.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Hi @ishaan-berri, sorry to bother you — just wanted to gently flag something in case it's helpful. I noticed this PR is marked merged, but it looks like it went into the
Totally possible I'm missing context here — would you mind taking a quick look when you get a chance? Happy to re-open this against |
|
Hi @ishaan-berri, sorry to bother you — just wanted to gently flag something in case it's helpful. I noticed this PR is marked merged, but it looks like it went into the
Totally possible I'm missing context here — would you mind taking a quick look when you get a chance? In the meantime, I rebuilt the video-support delta on top of the current |
Voyage's multimodal embeddings API supports MP4 video via `video_url` and `video_base64` content blocks in addition to text and image. The existing `VoyageMultimodalEmbeddingConfig` added in BerriAI#30193 does not handle these — video blocks fall through to the identity branch, so OpenAI-style nested `{"url": ...}` dicts are not unwrapped and `data:video/mp4;base64,...` data URIs are not converted to the `video_base64` shape Voyage expects. Extend `_normalize_content_item` with a `video_url` branch that mirrors the existing `image_url` logic: - unwrap `{"url": ...}` dicts (OpenAI-style) - convert `data:video/mp4;base64,...` URIs to `video_base64` blocks - raise `ValueError` on missing/empty video URLs - pass explicit `video_base64` blocks through unchanged 6 new unit tests cover each path plus an end-to-end request transform with mixed text + video content. Refs BerriAI#24957 — this complements BerriAI#30193 by closing the video gap that was in the original BerriAI#24972 draft but never landed on main.
Summary
Voyage multimodal embedding models (
voyage-multimodal-3,voyage-multimodal-3.5) currently route to the standard/v1/embeddingsendpoint, which does not support multimodal inputs (images, videos). This PR adds proper support by:VoyageMultimodalEmbeddingConfigthat routes to the correct/v1/multimodalembeddingsendpointtext,image_url,image_base64,video_url,video_base64content types)image_urlcontent blocks (with nested{"url": "..."}) to Voyage's flat formatimage_urlblocks and converting them toimage_base64typevoyage-multimodal-3.5to the model pricing registryFixes #24957
Changes
litellm/llms/voyage/embedding/transformation_multimodal.pyVoyageMultimodalEmbeddingConfigclasslitellm/utils.pylitellm/__init__.pylitellm/_lazy_imports_registry.pylitellm/model_prices_and_context_window_backup.jsonvoyage-multimodal-3.5, addsupports_visionflagtests/test_litellm/llms/voyage/embedding/test_voyage_multimodal_embedding.pyUsage
PR Checklist
tests/test_litellm/llms/voyage/embedding/test_voyage_multimodal_embedding.py- 32 tests)What type of PR is this?
🆕 New Feature
Reference