From d4f719c34bfec96d1249eec80842c35a0eea3a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=81ukawski?= Date: Tue, 24 Jan 2023 16:01:40 +0100 Subject: [PATCH] Convert numpy arrays to lists in HuggingFaceEmbeddings (#714) `SentenceTransformer` returns a NumPy array, not a `List[List[float]]` or `List[float]` as specified in the interface of `Embeddings`. That PR makes it consistent with the interface. --- langchain/embeddings/huggingface.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/langchain/embeddings/huggingface.py b/langchain/embeddings/huggingface.py index 8d5d817b8a..98f9986ad2 100644 --- a/langchain/embeddings/huggingface.py +++ b/langchain/embeddings/huggingface.py @@ -54,7 +54,7 @@ class HuggingFaceEmbeddings(BaseModel, Embeddings): """ texts = list(map(lambda x: x.replace("\n", " "), texts)) embeddings = self.client.encode(texts) - return embeddings + return embeddings.tolist() def embed_query(self, text: str) -> List[float]: """Compute query embeddings using a HuggingFace transformer model. @@ -67,4 +67,4 @@ class HuggingFaceEmbeddings(BaseModel, Embeddings): """ text = text.replace("\n", " ") embedding = self.client.encode(text) - return embedding + return embedding.tolist()