prompt-name-and-pixels (#7)
Browse files- refactor: change text type, set max pixels (8ad9fcd4614eb0e4ead82b632f4074635d2ef7fa)
- README.md +1 -1
- modeling_jina_embeddings_v4.py +9 -9
- preprocessor_config.json +2 -2
README.md
CHANGED
@@ -33,7 +33,7 @@ model.set_task(task='retrieval')
|
|
33 |
|
34 |
# Generate multi-vector embeddings
|
35 |
img_embeddings = model.encode_images(images=images, vector_type='multi_vector')
|
36 |
-
text_embeddings = model.encode_texts(texts=texts, vector_type='multi_vector',
|
37 |
|
38 |
# Example 3: Code task with single vector embeddings
|
39 |
model.set_task(task='code')
|
|
|
33 |
|
34 |
# Generate multi-vector embeddings
|
35 |
img_embeddings = model.encode_images(images=images, vector_type='multi_vector')
|
36 |
+
text_embeddings = model.encode_texts(texts=texts, vector_type='multi_vector', prompt_name='passage')
|
37 |
|
38 |
# Example 3: Code task with single vector embeddings
|
39 |
model.set_task(task='code')
|
modeling_jina_embeddings_v4.py
CHANGED
@@ -331,17 +331,17 @@ class JinaEmbeddingsV4Model(Qwen2_5_VLForConditionalGeneration):
|
|
331 |
self,
|
332 |
vector_type: Optional[str] = None,
|
333 |
truncate_dim: Optional[int] = None,
|
334 |
-
|
335 |
) -> Dict[str, Any]:
|
336 |
encode_kwargs = {}
|
337 |
-
if
|
338 |
-
if
|
339 |
raise ValueError(
|
340 |
-
f"Invalid
|
341 |
)
|
342 |
else:
|
343 |
encode_kwargs["prefix"] = (
|
344 |
-
PREFIX_DICT[
|
345 |
if self.task != TaskType.text_matching
|
346 |
else PREFIX_DICT["query"]
|
347 |
)
|
@@ -372,7 +372,7 @@ class JinaEmbeddingsV4Model(Qwen2_5_VLForConditionalGeneration):
|
|
372 |
vector_type: Optional[str] = None,
|
373 |
return_numpy: bool = False,
|
374 |
truncate_dim: Optional[int] = None,
|
375 |
-
|
376 |
) -> List[torch.Tensor]:
|
377 |
"""
|
378 |
Encodes a list of texts into embeddings.
|
@@ -384,14 +384,14 @@ class JinaEmbeddingsV4Model(Qwen2_5_VLForConditionalGeneration):
|
|
384 |
vector_type: Type of embedding vector to generate ('single_vector' or 'multi_vector')
|
385 |
return_numpy: Whether to return numpy arrays instead of torch tensors
|
386 |
truncate_dim: Dimension to truncate embeddings to (128, 256, 512, or 1024)
|
387 |
-
|
388 |
|
389 |
Returns:
|
390 |
List of text embeddings as tensors or numpy arrays
|
391 |
"""
|
392 |
-
|
393 |
encode_kwargs = self._validate_encoding_params(
|
394 |
-
vector_type, truncate_dim,
|
395 |
)
|
396 |
|
397 |
processor_fn = partial(
|
|
|
331 |
self,
|
332 |
vector_type: Optional[str] = None,
|
333 |
truncate_dim: Optional[int] = None,
|
334 |
+
prompt_name: Optional[str] = None,
|
335 |
) -> Dict[str, Any]:
|
336 |
encode_kwargs = {}
|
337 |
+
if prompt_name is not None:
|
338 |
+
if prompt_name not in PREFIX_DICT:
|
339 |
raise ValueError(
|
340 |
+
f"Invalid prompt_name: {prompt_name}. Must be one of {list(PREFIX_DICT.keys())}."
|
341 |
)
|
342 |
else:
|
343 |
encode_kwargs["prefix"] = (
|
344 |
+
PREFIX_DICT[prompt_name]
|
345 |
if self.task != TaskType.text_matching
|
346 |
else PREFIX_DICT["query"]
|
347 |
)
|
|
|
372 |
vector_type: Optional[str] = None,
|
373 |
return_numpy: bool = False,
|
374 |
truncate_dim: Optional[int] = None,
|
375 |
+
prompt_name: Optional[str] = None,
|
376 |
) -> List[torch.Tensor]:
|
377 |
"""
|
378 |
Encodes a list of texts into embeddings.
|
|
|
384 |
vector_type: Type of embedding vector to generate ('single_vector' or 'multi_vector')
|
385 |
return_numpy: Whether to return numpy arrays instead of torch tensors
|
386 |
truncate_dim: Dimension to truncate embeddings to (128, 256, 512, or 1024)
|
387 |
+
prompt_name: Type of text being encoded ('query' or 'passage')
|
388 |
|
389 |
Returns:
|
390 |
List of text embeddings as tensors or numpy arrays
|
391 |
"""
|
392 |
+
prompt_name = prompt_name or "query"
|
393 |
encode_kwargs = self._validate_encoding_params(
|
394 |
+
vector_type, truncate_dim, prompt_name
|
395 |
)
|
396 |
|
397 |
processor_fn = partial(
|
preprocessor_config.json
CHANGED
@@ -14,7 +14,7 @@
|
|
14 |
0.26130258,
|
15 |
0.27577711
|
16 |
],
|
17 |
-
"max_pixels":
|
18 |
"merge_size": 2,
|
19 |
"min_pixels": 3136,
|
20 |
"patch_size": 14,
|
@@ -22,7 +22,7 @@
|
|
22 |
"resample": 3,
|
23 |
"rescale_factor": 0.00392156862745098,
|
24 |
"size": {
|
25 |
-
"longest_edge":
|
26 |
"shortest_edge": 3136
|
27 |
},
|
28 |
"temporal_patch_size": 2,
|
|
|
14 |
0.26130258,
|
15 |
0.27577711
|
16 |
],
|
17 |
+
"max_pixels": 602112,
|
18 |
"merge_size": 2,
|
19 |
"min_pixels": 3136,
|
20 |
"patch_size": 14,
|
|
|
22 |
"resample": 3,
|
23 |
"rescale_factor": 0.00392156862745098,
|
24 |
"size": {
|
25 |
+
"longest_edge": 602112,
|
26 |
"shortest_edge": 3136
|
27 |
},
|
28 |
"temporal_patch_size": 2,
|