Skip to content

Commit 8b29542

Browse files
fix(JinaV5OmniWrapper): use Query/Document prefix for all text tasks
The text-matching, classification and clustering adapters were trained WITH the "Query: "/"Document: " prefix, not without it. Running them without any prefix causes dramatic score drops (e.g. STS12: 0.85→0.38, Banking77: 0.90→0.30, SprintDuplicateQuestions: 0.96→0.18). New logic: audio/video non-retrieval tasks skip the prefix (unchanged); text and image tasks always use the prefix regardless of adapter type. Update unit tests to reflect the corrected expected behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0c5a402 commit 8b29542

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

mteb/models/model_implementations/jina_models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -842,15 +842,16 @@ def encode(
842842
task_metadata.simplified_task_type
843843
)
844844
task = jina_task_name or "retrieval"
845-
# Non-retrieval adapters were trained without the Query/Document prefix.
846-
if task == "retrieval":
845+
# All text and image adapters use Query/Document prefix.
846+
# Audio/video non-retrieval adapters do not use the prefix.
847+
if (has_video or has_audio) and task != "retrieval":
848+
prompt = ""
849+
else:
847850
prompt = (
848851
"Query: "
849852
if prompt_type and prompt_type == PromptType.query
850853
else "Document: "
851854
)
852-
else:
853-
prompt = ""
854855

855856
logger.info(
856857
f"Using prompt=`{prompt}` and task={task} for task={task_metadata.name} prompt_type={prompt_type}"

tests/test_models/test_jina_v5_omni_wrapper.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ def _omni_prompts() -> dict:
7272
[
7373
(PromptType.query, "Retrieval", "retrieval", "Query: "),
7474
(PromptType.document, "Retrieval", "retrieval", "Document: "),
75-
(PromptType.document, "Clustering", "clustering", ""),
76-
(PromptType.query, "STS", "text-matching", ""),
77-
(PromptType.document, "Classification", "classification", ""),
78-
(PromptType.query, "PairClassification", "text-matching", ""),
75+
# Text tasks: all adapters now use prefix (trained with prefix)
76+
(PromptType.document, "Clustering", "clustering", "Document: "),
77+
(PromptType.query, "STS", "text-matching", "Query: "),
78+
(PromptType.document, "Classification", "classification", "Document: "),
79+
(PromptType.query, "PairClassification", "text-matching", "Query: "),
7980
],
8081
)
8182
def test_prefix_by_task_type(prompt_type, task_type, expected_task, expected_prompt):
@@ -89,9 +90,10 @@ def test_prefix_by_task_type(prompt_type, task_type, expected_task, expected_pro
8990
"prompt_type,task_type,expected_task,expected_prompt",
9091
[
9192
(PromptType.query, "Any2AnyRetrieval", "retrieval", "Query: "),
92-
(PromptType.document, "ImageClustering", "clustering", ""),
93-
(PromptType.query, "VisualSTS(eng)", "text-matching", ""),
94-
(PromptType.query, "AudioPairClassification", "text-matching", ""),
93+
# Text-input paths always get prefix regardless of task type label
94+
(PromptType.document, "ImageClustering", "clustering", "Document: "),
95+
(PromptType.query, "VisualSTS(eng)", "text-matching", "Query: "),
96+
(PromptType.query, "AudioPairClassification", "text-matching", "Query: "),
9597
],
9698
)
9799
def test_simplified_fallback(prompt_type, task_type, expected_task, expected_prompt):
@@ -108,9 +110,10 @@ def test_simplified_fallback(prompt_type, task_type, expected_task, expected_pro
108110
(PromptType.query, "ImageClassification", "retrieval", "Query: "),
109111
(PromptType.query, "AudioClassification", "retrieval", "Query: "),
110112
(PromptType.query, "ZeroShotClassification", "retrieval", "Query: "),
111-
(PromptType.document, "Compositionality", "clustering", ""),
113+
# Text-input paths always get prefix
114+
(PromptType.document, "Compositionality", "clustering", "Document: "),
112115
(PromptType.query, "AudioPairClassification", "retrieval", "Query: "),
113-
(PromptType.document, "ImageClustering", "text-matching", ""),
116+
(PromptType.document, "ImageClustering", "text-matching", "Document: "),
114117
],
115118
)
116119
def test_omni_overrides(prompt_type, task_type, expected_task, expected_prompt):

0 commit comments

Comments
 (0)