Skip to content

Commit

Permalink
Detect shape error of embedding (#3710)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
yuzhichang authored Nov 28, 2024
1 parent e678819 commit 43e367f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rag/nlp/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class SearchResult:

def get_vector(self, txt, emb_mdl, topk=10, similarity=0.1):
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]
vector_column_name = f"q_{len(embedding_data)}_vec"
return MatchDenseExpr(vector_column_name, embedding_data, 'float', 'cosine', topk, {"similarity": similarity})
Expand Down

0 comments on commit 43e367f

Please sign in to comment.