@@ -31,7 +31,7 @@ def _normalize(embeddings: np.ndarray) -> np.ndarray:
3131 def embed_images (self , image_paths : list [Path ]) -> np .ndarray :
3232 """Embed a batch of images. Returns L2-normalized projected vectors (768-dim)."""
3333 images = [Image .open (p ).convert ("RGB" ) for p in image_paths ]
34- inputs = self .processor (images = images , return_tensors = "pt" )
34+ inputs = self .processor (images = images , return_tensors = "pt" ) # type: ignore[operator]
3535 inputs = {k : v .to (self .device ) for k , v in inputs .items ()}
3636 with torch .no_grad ():
3737 # Explicitly run vision_model + visual_projection to get 768-dim
@@ -45,12 +45,15 @@ def embed_images(self, image_paths: list[Path]) -> np.ndarray:
4545
4646 def embed_text (self , text : str ) -> np .ndarray :
4747 """Embed a single text query. Returns L2-normalized projected vector (1, 768)."""
48- inputs = self .processor (text = [text ], return_tensors = "pt" , padding = True , truncation = True )
48+ proc_kwargs = dict (text = [text ], return_tensors = "pt" , padding = True , truncation = True )
49+ inputs = self .processor (** proc_kwargs ) # type: ignore[operator]
4950 inputs = {k : v .to (self .device ) for k , v in inputs .items ()}
5051 with torch .no_grad ():
5152 # Explicitly run text_model + text_projection to guarantee
5253 # 768-dim projected features matching JS CLIPTextModelWithProjection.
53- text_out = self .model .text_model (input_ids = inputs ["input_ids" ], attention_mask = inputs ["attention_mask" ])
54+ text_out = self .model .text_model (
55+ input_ids = inputs ["input_ids" ], attention_mask = inputs ["attention_mask" ]
56+ )
5457 projected = self .model .text_projection (text_out .pooler_output )
5558 embedding = projected .cpu ().numpy ()
5659 return self ._normalize (embedding ).astype (np .float32 )
0 commit comments