Skip to content

Commit

Permalink
fix: Normalize the output of OnnxEmbeddingFunction. (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: wxywb <[email protected]>
  • Loading branch information
wxywb authored May 17, 2024
1 parent c8a11db commit 3ee078f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion milvus_model/dense/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def _to_embedding(self, data: str, **_):
ort_outputs = self.ort_session.run(None, ort_inputs)
ort_feat = ort_outputs[0]
emb = self._post_proc(ort_feat, ort_inputs["attention_mask"])
return emb.flatten()
emb = emb.flatten()
return emb / np.linalg.norm(emb)

def _post_proc(self, token_embeddings, attention_mask):
input_mask_expanded = (
Expand Down

0 comments on commit 3ee078f

Please sign in to comment.