Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Batch encoding for TEI encoder #423

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
10 changes: 4 additions & 6 deletions semantic_router/encoders/huggingface.py
Original file line number Diff line number Diff line change
@@ -212,19 +212,17 @@ def __call__(self, docs: List[str]) -> List[List[float]]:
ValueError: If no embeddings are returned for a document.
"""

batch_size=50
batch_size = 50

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueError: No embeddings returned for batch. Error: Query failed with status 413: {"error":"batch size 50 > maximum allowed batch size 32","error_type":"Validation"}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @joaomsimoes what HuggingFace TEI model were you using when you encountered this error?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late answer @Siraj-Aizlewood

I was using Alibaba-NLP/gte-large-en-v1.5

embeddings = []
for i in range(0, len(docs), batch_size):
batch = docs[i:i + batch_size]
batch = docs[i : i + batch_size]
try:
outputs = self.query({"inputs": batch, "parameters": {}})
if not outputs or len(outputs) == 0:
raise ValueError("No embeddings returned from the query.")
embeddings.extend(outputs)
embeddings = embeddings + outputs
except Exception as e:
raise ValueError(
f"No embeddings returned for batch. Error: {e}"
) from e
raise ValueError(f"No embeddings returned for batch. Error: {e}") from e

return embeddings