Detect shape error of embedding (#3710)

### What problem does this PR solve?

Detect shape error of embedding. Close #2997

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Zhichang Yu 2024-11-28 14:10:22 +08:00 committed by GitHub
parent e678819f70
commit 43e367f2ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,6 +46,9 @@ class Dealer:
def get_vector(self, txt, emb_mdl, topk=10, similarity=0.1): def get_vector(self, txt, emb_mdl, topk=10, similarity=0.1):
qv, _ = emb_mdl.encode_queries(txt) qv, _ = emb_mdl.encode_queries(txt)
shape = np.array(qv).shape
if len(shape) > 1:
raise Exception(f"Dealer.get_vector returned array's shape {shape} doesn't match expectation(exact one dimension).")
embedding_data = [float(v) for v in qv] embedding_data = [float(v) for v in qv]
vector_column_name = f"q_{len(embedding_data)}_vec" vector_column_name = f"q_{len(embedding_data)}_vec"
return MatchDenseExpr(vector_column_name, embedding_data, 'float', 'cosine', topk, {"similarity": similarity}) return MatchDenseExpr(vector_column_name, embedding_data, 'float', 'cosine', topk, {"similarity": similarity})