Skip to content

Commit

Permalink
skip token count when local embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
dayesouza committed Oct 31, 2024
1 parent 6c9296f commit 6e72825
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions toolkit/AI/base_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ def embed_store_one(
if len(existing_embedding) > 0:
return existing_embedding.get("vector")[0]

tokens = get_token_count(text)
if tokens > self.max_tokens:
text = text[: self.max_tokens]
logger.info("Truncated text to max tokens")
# error when local
try:
tokens = get_token_count(text)
if tokens > self.max_tokens:
text = text[: self.max_tokens]
logger.info("Truncated text to max tokens")
except:
pass

try:
embedding = self._generate_embedding(text)
Expand Down

0 comments on commit 6e72825

Please sign in to comment.