소스 검색

Truncate text for zhipu embedding. (#4490)

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.16.0
Kevin Hu 9 달 전
부모
커밋
be5f830878
No account linked to committer's email address
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8
    0
      rag/llm/embedding_model.py

+ 8
- 0
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)

Loading…
취소
저장