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

langchain_community: add error handling in HuggingFaceInferenceAPIEmbeddings #29792

Closed

Conversation

brian-ogrady
Copy link

When using a custom HuggingFace API Endpoint there can be an error in the JSON response. I propose added two checks when calling the embed_documents method of the HuggingFaceInferenceAPIEmbeddings class:

  1. Add a check for a JSONDecodeError
  2. Add a check within the JSON response for an error

While working with the HuggingFaceInferenceAPIEmbeddings class, I sometimes receive a nebulous error ValueError: could not convert string to float: 'e'
Screenshot 2025-02-13 at 5 04 36 PM

This results because the embed_documents method, which is called during the execution of the add_documents method of a vector store, can return a JSON response like the following: {'error': 'Input validation error: inputs cannot be empty', 'error_type': 'Validation'}

The initial ValueError raised from add_documents is misleading because it makes the underlying error returned in the JSON response. I propose surfacing this error by adding a check during embed_documents to return the JSON error in a Pythonic manner.

I have detailed this request in the discussions.

If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 13, 2025
Copy link

vercel bot commented Feb 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Feb 14, 2025 6:03pm

@dosubot dosubot bot added community Related to langchain-community Ɑ: embeddings Related to text embedding models module labels Feb 13, 2025
brian-ogrady and others added 6 commits February 13, 2025 20:36
Removing trailing whitespace from newline

Linting a bit more
:q

Even more linting

Lint + test failure

Trailing commas, linting indentation

Call me lintman

Gonna have to squash these commits eventually

Gonna have to squash these commits eventually again

Gonna have to squash these commits eventually again again

fix

fix

fix

fix
@brian-ogrady brian-ogrady force-pushed the add-hf-api-error-check branch from 5026f3b to aaf105e Compare February 14, 2025 17:59
@brian-ogrady brian-ogrady requested a review from efriis as a code owner February 14, 2025 17:59
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Feb 14, 2025
@brian-ogrady
Copy link
Author

woops! @efriis please ignore this last commit here. Accidentally committed some unstaged changes when squashing my commits.

@brian-ogrady
Copy link
Author

Replaced by this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community Ɑ: embeddings Related to text embedding models module size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants