Skip to content

Commit

Permalink
Truncate text for zhipu embedding. (#4490)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
KevinHuSh authored Jan 15, 2025
1 parent 7944aac commit be5f830
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rag/llm/embedding_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def __init__(self, key, model_name="embedding-2", **kwargs):
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)
Expand Down

0 comments on commit be5f830

Please sign in to comment.