-
Notifications
You must be signed in to change notification settings - Fork 216
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
base: main
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #423 +/- ##
==========================================
+ Coverage 68.04% 68.37% +0.33%
==========================================
Files 46 46
Lines 3505 3510 +5
==========================================
+ Hits 2385 2400 +15
+ Misses 1120 1110 -10 ☔ View full report in Codecov by Sentry. |
@@ -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 |
There was a problem hiding this comment.
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"}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
User description
Related to PR#414.
From user:
Hi everyone.
I wanted to use the Text Embeddings Inference with the encoder but I noticed two small bugs in the code. I believe that the HFEndpointEncoder was intentionally created to be used with TEI (right?)
The loop for max_retries in attempts, that is inside of the function query, has no break or any system to return the result when we have a success response. I added a break, similar to the OpenAI encoder.
The response from TEI is [[[array]]]. The array is inside of a list of a list. I remove one list when receiving the response. Without this it will throw a dimension error when comparing all the vectors.
These are the main bugs, but I would also take some time to purpose a future update. With TEI we can send a batch of texts
To save time, we could batch the different sentences to the endpoint. This would be great for longer document. If it sounds interesting I can try to help to develop it.
By the way, should I use semantic router for splitting text, or the semantic chunkers?
PR Type
enhancement, bug fix
Description
query
method to exit upon a successful response, improving efficiency.Changes walkthrough 📝
huggingface.py
Implement batch processing and fix response handling in TEI encoder
semantic_router/encoders/huggingface.py
of 50.
output.
response.