paulbricman commited on
Commit
7b689ca
1 Parent(s): 9a24553

feat: reduce embedding precision for size

Browse files
Files changed (2) hide show
  1. backend/util.py +3 -3
  2. util.py +1 -1
backend/util.py CHANGED
@@ -199,13 +199,13 @@ def encode(modality, content, text_encoder, text_image_encoder):
199
  return {
200
  'text_model': 'sentence-transformers/multi-qa-mpnet-base-cos-v1',
201
  'text_image_model': 'clip-ViT-B-32',
202
- 'text': [round(e, 6) for e in text_encoder.encode(content).tolist()],
203
- 'text_image': [round(e, 6) for e in text_image_encoder.encode(content).tolist()]
204
  }
205
  elif modality == 'image':
206
  return {
207
  'text_image_model': 'clip-ViT-B-32',
208
- 'text_image': [round(e, 6) for e in text_image_encoder.encode(Image.open(io.BytesIO(content))).tolist()]
209
  }
210
  else:
211
  raise Exception('Can\'t encode content of modality "' + modality + '"')
199
  return {
200
  'text_model': 'sentence-transformers/multi-qa-mpnet-base-cos-v1',
201
  'text_image_model': 'clip-ViT-B-32',
202
+ 'text': [round(e, 5) for e in text_encoder.encode(content).tolist()],
203
+ 'text_image': [round(e, 5) for e in text_image_encoder.encode(content).tolist()]
204
  }
205
  elif modality == 'image':
206
  return {
207
  'text_image_model': 'clip-ViT-B-32',
208
+ 'text_image': [round(e, 5) for e in text_image_encoder.encode(Image.open(io.BytesIO(content))).tolist()]
209
  }
210
  else:
211
  raise Exception('Can\'t encode content of modality "' + modality + '"')
util.py CHANGED
@@ -157,7 +157,7 @@ for e_idx, e in enumerate(new_thoughts):
157
  new_thoughts[e_idx]['embedding'] = e['embedding'].tolist()
158
 
159
  for e_idx, e in enumerate(new_thoughts):
160
- new_thoughts[e_idx]['embedding'] = [round(f, 6) for f in e['embedding']]
161
 
162
  for e_idx, e in enumerate(new_thoughts):
163
  new_thoughts[e_idx]['filename'] = e['filename'].split('/')[-1]
157
  new_thoughts[e_idx]['embedding'] = e['embedding'].tolist()
158
 
159
  for e_idx, e in enumerate(new_thoughts):
160
+ new_thoughts[e_idx]['embedding'] = [round(f, 5) for f in e['embedding']]
161
 
162
  for e_idx, e in enumerate(new_thoughts):
163
  new_thoughts[e_idx]['filename'] = e['filename'].split('/')[-1]