[fix] Collapse single-key multimodal dicts to bare modality#3779
Merged
Conversation
6 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes single-key multimodal dicts like {"image": pil} behave equivalently to bare modality inputs (e.g., a raw PIL image). Previously, such dicts were classified as the tuple modality ("image",) and routed through the multimodal path, breaking supports() checks for models that only declare single-modality support (e.g., BGE-VL via MTEB).
Changes:
infer_modalitynow collapses 1-key multimodal dicts to the bare modality string, andparse_inputs/_to_contentunwrap the dict so downstream sees the raw value.- Introduced
MULTIMODAL_DICT_KEYSconstant inmodality_types.pyto centralize valid modality keys. - Updated existing audio/video wrapper tests to expect the bare modality, and added new tests for image/text single-key dicts in
infer_modality,parse_inputs, andpair_to_messages.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sentence_transformers/base/modality_types.py | Adds the MULTIMODAL_DICT_KEYS frozenset constant. |
| sentence_transformers/base/modality.py | Collapses 1-key dicts in infer_modality; unwraps the dict in parse_inputs and _to_content. |
| tests/base/test_modality.py | Updates existing wrapper-modality assertions and adds new tests for image/text single-key handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tomaarsen
added a commit
that referenced
this pull request
May 20, 2026
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.
Hello!
Pull Request overview
{"image": pil}) as equivalent to bare modality inputsDetails
MTEB passes image inputs as
{"image": pil}dicts when running vision-retrieval benchmarks (see embeddings-benchmark/mteb#4310 (comment)). These were previously classified as the tuple modality("image",)and routed through the multimodal path, which fails thesupports()check for models that only declare"image"support (e.g. BGE-VL).With this PR,
infer_modalitycollapses a single-key multimodal dict to the bare modality string.{"image": pil}now returns"image"instead of("image",).parse_inputsandpair_to_messagescorrespondingly unwrap the dict so downstream sees the raw value, matching what they would have seen for a bare PIL input.The existing
{"audio": ...}/{"video": ...}wrapper tests are updated to expect the bare modality (they were already going through the same unwrap path), and new tests coverparse_inputsandpair_to_messagesfor the image/text cases that the previous tuple-based handling silently masked.Notably, this fixes: