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 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions semantic_router/encoders/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

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

Expand Down