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

MistralAIEmbeddings retry decorator catches wrong exception type for rate limiting #29125

Open
5 tasks done
Gero-Gi opened this issue Jan 10, 2025 · 0 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@Gero-Gi
Copy link

Gero-Gi commented Jan 10, 2025

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_mistralai import MistralAIEmbeddings
    embeddings = MistralAIEmbeddings(
    model="mistral-embed",
    mistral_api_key="your-api-key",
    wait_time=30 # Should be used for rate limit retries
)

Making multiple requests in quick succession triggers rate limits

for i in range(10):
    # When hitting rate limits, raises httpx.HTTPStatusError without retrying
    embeddings.embed_query("Test string")

Error Message and Stack Trace (if applicable)

File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 286, in invoke
self.generate_prompt(
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 786, in generate_prompt
return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 643, in generate
raise e
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 633, in generate
self._generate_with_cache(
File "/usr/local/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 851, in _generate_with_cache
result = self._generate(
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 545, in _generate
response = self.completion_with_retry(
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 464, in completion_with_retry
rtn = _completion_with_retry(**kwargs)
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 461, in _completion_with_retry
_raise_on_error(response)
File "/usr/local/lib/python3.10/site-packages/langchain_mistralai/chat_models.py", line 170, in _raise_on_error
raise httpx.HTTPStatusError(
httpx.HTTPStatusError: Error response 429 while fetching https://api.mistral.ai/v1/chat/completions: {"message":"Requests rate limit exceeded"}

Description

The MistralAIEmbeddings class currently uses a retry decorator that only catches httpx.TimeoutException, but according to the documentation, it should be handling rate limit (429) errors using the wait_time parameter.

Current Behavior

  • The retry decorator only catches httpx.TimeoutException
  • When hitting rate limits (429 errors), the code raises an httpx.HTTPStatusError without retrying
  • The wait_time parameter is documented as "The number of seconds to wait before retrying a request in case of 429 error" but isn't actually used for this purpose

Expected Behavior

  • The retry decorator should catch httpx.HTTPStatusError to handle 429 rate limit responses
  • When receiving a 429 error, it should wait for wait_time seconds before retrying
  • This matches the documented behavior of the wait_time parameter

System Info

System Information

OS: Linux
OS Version: #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2
Python Version: 3.10.16 (main, Dec 24 2024, 22:23:12) [GCC 12.2.0]

Package Information

langchain_core: 0.3.29
langchain: 0.3.14
langchain_community: 0.3.14
langsmith: 0.2.10
langchain_mistralai: 0.2.4
langchain_ollama: 0.2.2
langchain_qdrant: 0.2.0
langchain_text_splitters: 0.3.5
langchainhub: 0.1.21

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: 4.0.3
dataclasses-json: 0.6.7
fastembed: Installed. No version info available.
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
ollama: 0.4.5
orjson: 3.10.13
packaging: 24.2
pydantic: 2.9.2
pydantic-settings: 2.7.1
PyYAML: 6.0.2
qdrant-client: 1.12.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
tenacity: 9.0.0
tokenizers: 0.21.0
types-requests: 2.32.0.20241016
typing-extensions: 4.12.2
zstandard: Installed. No version info available.

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jan 10, 2025
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
Projects
None yet
Development

No branches or pull requests

1 participant