[Bugfix]: Use float32 for base64 embedding (#7855)

Signed-off-by: Hollow Man <hollowman@opensuse.org>
This commit is contained in:
ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟
2024-08-26 03:16:38 +00:00
committed by GitHub
parent 1856aff4d6
commit 0b769992ec
3 changed files with 13 additions and 3 deletions
+3 -1
View File
@@ -31,7 +31,9 @@ def _get_embedding(
if encoding_format == "float":
return output.embedding
elif encoding_format == "base64":
embedding_bytes = np.array(output.embedding).tobytes()
# Force to use float32 for base64 encoding
# to match the OpenAI python client behavior
embedding_bytes = np.array(output.embedding, dtype="float32").tobytes()
return base64.b64encode(embedding_bytes).decode("utf-8")
assert_never(encoding_format)