Skip to content

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

Truncate text for zhipu embedding. (#4490)

Kevin Hube5f830878ee
diff --git a/rag/llm/embedding_model.py b/rag/llm/embedding_model.py
index df57f5d9f5..1babf11528 100644
--- a/rag/llm/embedding_model.py
+++ b/rag/llm/embedding_model.py
@@ -217,6 +217,14 @@ class ZhipuEmbed(Base):
def encode(self, texts: list):
arr = []
tks_num = 0
+ MAX_LEN = -1
+ if self.model_name.lower() == "embedding-2":
+ MAX_LEN = 512
+ if self.model_name.lower() == "embedding-3":
+ MAX_LEN = 3072
+ if MAX_LEN > 0:
+ texts = [truncate(t, MAX_LEN) for t in texts]
+
for txt in texts:
res = self.client.embeddings.create(input=txt,
model=self.model_name)