jupyterjazz commited on
Commit
91fd99e
·
verified ·
1 Parent(s): 9e83d6f

prompt-name-and-pixels (#7)

Browse files

- refactor: change text type, set max pixels (8ad9fcd4614eb0e4ead82b632f4074635d2ef7fa)

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', text_type='passage')
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
- text_type: Optional[str] = None,
335
  ) -> Dict[str, Any]:
336
  encode_kwargs = {}
337
- if text_type is not None:
338
- if text_type not in PREFIX_DICT:
339
  raise ValueError(
340
- f"Invalid text_type: {text_type}. Must be one of {list(PREFIX_DICT.keys())}."
341
  )
342
  else:
343
  encode_kwargs["prefix"] = (
344
- PREFIX_DICT[text_type]
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
- text_type: Optional[str] = None,
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
- text_type: Type of text being encoded ('query' or 'passage')
388
 
389
  Returns:
390
  List of text embeddings as tensors or numpy arrays
391
  """
392
- text_type = text_type or "query"
393
  encode_kwargs = self._validate_encoding_params(
394
- vector_type, truncate_dim, text_type
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": 12845056,
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": 12845056,
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,