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.
harrison/document-split
Kacper Łukawski 1 year ago committed by GitHub
parent 97c3544a1e
commit d4f719c34b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()

Loading…
Cancel
Save