Skip to content

Commit d4f719c

Browse files
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.
1 parent 97c3544 commit d4f719c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

langchain/embeddings/huggingface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
5454
"""
5555
texts = list(map(lambda x: x.replace("\n", " "), texts))
5656
embeddings = self.client.encode(texts)
57-
return embeddings
57+
return embeddings.tolist()
5858

5959
def embed_query(self, text: str) -> List[float]:
6060
"""Compute query embeddings using a HuggingFace transformer model.
@@ -67,4 +67,4 @@ def embed_query(self, text: str) -> List[float]:
6767
"""
6868
text = text.replace("\n", " ")
6969
embedding = self.client.encode(text)
70-
return embedding
70+
return embedding.tolist()

0 commit comments

Comments
 (0)