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

Added Retrying Mechanism in case of Request Rate Limit Error for MistralAIEmbeddings #27818

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

keenborder786
Copy link
Contributor

  • Description:: In the event of a Rate Limit Error from the MistralAI server, the response JSON raises a KeyError. To address this, a simple retry mechanism has been implemented to handle cases where the request limit is exceeded.
  • Issue: Cannot create MistralAI embeddings from pdf or urls #27790

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Nov 1, 2024
Copy link

vercel bot commented Nov 1, 2024

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 Nov 13, 2024 7:33pm

@dosubot dosubot bot added Ɑ: embeddings Related to text embedding models module 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Nov 1, 2024
@keenborder786
Copy link
Contributor Author

@eyurtsev

batch_responses = []

@retry(
retry=retry_if_exception_type(Exception),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally, retries should never be implemented on 4xx errors (except for 408 and 429). e.g., 403 should not be retried by default

  • What do we do in other parts of the code? Perhaps there's a better example that can be adopted?
  • What do other models do in the code base in terms of exposing the retry parameters so users can adjust? (e.g.,what if someone wants to have the first retry after 1 second rather than 30 seconds?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • @eyurtsev it is a 429 error therefore retrying makes sense.
  • I was not able to find any related example.
  • Yes I can make the wait and stop seconds as parameters.

for batch in self._get_batches(texts)
)
if response.status_code == 429:
raise Exception("Requests rate limit exceeded")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code takes an exception that was good and informative and turns it into one that's a broad Exception of type Exception -- this is usually not a good pattern for exception handling. Stack trace will be partially lost, the exception type is less specific etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Their were no specific exception being raised to being with. But I can change it from a general Exception.

Copy link
Collaborator

@eyurtsev eyurtsev left a comment

Choose a reason for hiding this comment

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

Makes sense to add retry mechanism. Added a few questions to see if we can improve how it's configured

@keenborder786
Copy link
Contributor Author

@eyurtsev please check now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: embeddings Related to text embedding models module size:S This PR changes 10-29 lines, ignoring generated files.
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants