-
Notifications
You must be signed in to change notification settings - Fork 2k
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
HuggingFaceTEIDocumentEmbedder do not truncate rather they throw an exception. #7413
Comments
@awinml I remember that you developed this Embedder. |
@anakin87 This is only an issue when using a Text-embeddings-inference deployed endpoint, the HF Inference endpoints automatically truncate and but don't normalize. You can view a simple example showcasing this with both endpoints in this Colab notebook. The default behaviour of TEI endpoints is to automatically normalize and raise an error if the tokens exceed 512. This can be changed using the We use the import json
import numpy as np
from huggingface_hub import InferenceClient
client = InferenceClient(...)
text = "Very long text"
# NOTE: `truncate` and `normalize` parameters only work for TEI-powered APIs
response = client.post(json={"inputs": [text], "truncate": True, "normalize":True}, task="feature-extraction")
response_dict = json.loads(response.decode())
embedding = np.array(response_dict, dtype="float32").tolist() I can open a PR to refactor the embedders if this approach is okay. The other option would be to wait until they standardize their API and document this limitation in the docs. |
Let me try to recap... Please correct me if I am wrong. Currently, HFTEIEmbedders in Haystack support these different backends:
Using the If my analysis is correct, I would do the following:
@awinml WDYT? |
@anakin87 Sounds good! I'll add the |
HuggingFaceTEIDocumentEmbedder do not auto-truncate rather they throw an exception.
I'd like to have the option to pass an argument to truncate my text and go on.
The text was updated successfully, but these errors were encountered: