MCPcopy Create free account
hub / github.com/Agent-RL/ReCall / encode_text

Method encode_text

src/flashrag/retriever/encoder.py:227–248  ·  view source on GitHub ↗
(self, text_list: List[str])

Source from the content-addressed store, hash-verified

225
226 @torch.inference_mode()
227 def encode_text(self, text_list: List[str]) -> np.ndarray:
228 # Each item in image_list: PIL Image, local path, or URL
229 if self.model_type == "CLIPModel" or self.model_type == 'ChineseCLIPModel':
230 inputs = self.processor(
231 text=text_list,
232 padding=True,
233 truncation=True,
234 return_tensors="pt",
235 )
236 inputs = {k: v.cuda() for k, v in inputs.items()}
237 text_emb = self.model.get_text_features(**inputs)
238 text_emb = text_emb / text_emb.norm(p=2, dim=-1, keepdim=True)
239 text_emb = text_emb.detach().cpu().numpy().astype(np.float32)
240 elif self.model_type.endswith("CLIPModel"):
241 text_emb = self.model.encode_text(
242 text_list,
243 padding=True,
244 truncation=True,
245 )
246 else:
247 raise NotImplementedError(f"Unsupported model type: {self.model_type}")
248 return text_emb

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected