Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Detect shape error of embedding (#3710)

Zhichang Yu43e367f2eabe
diff --git a/rag/nlp/search.py b/rag/nlp/search.py
index 154d5850d4..a24f7a71d8 100644
--- a/rag/nlp/search.py
+++ b/rag/nlp/search.py
@@ -46,6 +46,9 @@ class Dealer:
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})