MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / encode

Method encode

methods/remem_agent.py:214–241  ·  view source on GitHub ↗

Encode texts into embedding vectors. Returns: np.ndarray of shape (len(texts), dim)

(self, texts: List[str], **kwargs)

Source from the content-addressed store, hash-verified

212 timeout=60,
213 )
214 logger.info(f"Embedding API client initialized, model={self.model_name}")
215
216 def encode(self, texts: List[str], **kwargs) -> np.ndarray:
217 """Encode texts into embedding vectors.
218
219 Returns:
220 np.ndarray of shape (len(texts), dim)
221 """
222 if isinstance(texts, str):
223 texts = [texts]
224
225 texts = [t if t.strip() else "empty" for t in texts]
226
227 # ReMem uses instruction prefix to distinguish queries from documents
228 instruction = kwargs.get("instruction", "")
229 if instruction:
230 texts = [f"{instruction}{t}" for t in texts]
231
232 if self.provider == "local":
233 embeddings = self._encode_local(texts)
234 else:
235 embeddings = self._encode_api(texts)
236
237 # Normalize
238 if self.normalize and kwargs.get("norm", True):
239 norms = np.linalg.norm(embeddings, axis=1, keepdims=True)
240 norms = np.where(norms == 0, 1, norms)
241 embeddings = embeddings / norms
242
243 return embeddings
244

Callers 3

batch_encodeMethod · 0.95
_encode_localMethod · 0.45
_fallback_retrievalMethod · 0.45

Calls 3

_encode_localMethod · 0.95
_encode_apiMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected