-1

I have to send lists of text embeddings in flask output. The output looks as follows:

{"embeddings":[[0.1,0.2,0.3],[0.4,0.5,0.6],[0.7,0.8,0.9]]}

I tried doing json.dumps and jsonify from flask but still I get following error when sending above output in flask response:

TypeError: Object of type float32 is not JSON serializable

How can I fix it?

davidism
  • 121,510
  • 29
  • 395
  • 339
Yadnesh Salvi
  • 175
  • 1
  • 18

1 Answers1

0

You need to convert that into a native Python data type before serializing it to JSON

import numpy as np

embeddings = np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9]], dtype=np.float32)
N. Arunoprayoch
  • 922
  • 12
  • 20