Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions libs/partners/mistralai/langchain_mistralai/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
SecretStr,
model_validator,
)
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed
from tokenizers import Tokenizer # type: ignore[import]
from typing_extensions import Self

Expand Down Expand Up @@ -57,13 +56,8 @@ class MistralAIEmbeddings(BaseModel, Embeddings):
api_key: SecretStr | None
The API key for the MistralAI API. If not provided, it will be read from the
environment variable `MISTRAL_API_KEY`.
max_retries: int
The number of times to retry a request if it fails.
timeout: int
The number of seconds to wait for a response before timing out.
wait_time: int
The number of seconds to wait before retrying a request in case of 429
error.
max_concurrent_requests: int
The maximum number of concurrent requests to make to the Mistral API.

Expand Down Expand Up @@ -133,9 +127,7 @@ class MistralAIEmbeddings(BaseModel, Embeddings):
default_factory=secret_from_env("MISTRAL_API_KEY", default=""),
)
endpoint: str = "https://api.mistral.ai/v1/"
max_retries: int = 5
timeout: int = 120
wait_time: int = 30
max_concurrent_requests: int = 64
tokenizer: Tokenizer = Field(default=None)

Expand Down Expand Up @@ -225,13 +217,6 @@ def embed_documents(self, texts: list[str]) -> list[list[float]]:
try:
batch_responses = []

@retry(
retry=retry_if_exception_type(
(httpx.TimeoutException, httpx.HTTPStatusError)
),
wait=wait_fixed(self.wait_time),
stop=stop_after_attempt(self.max_retries),
)
def _embed_batch(batch: list[str]) -> Response:
response = self.client.post(
url="/embeddings",
Expand Down Expand Up @@ -266,13 +251,6 @@ async def aembed_documents(self, texts: list[str]) -> list[list[float]]:
"""
try:

@retry(
retry=retry_if_exception_type(
(httpx.TimeoutException, httpx.HTTPStatusError)
),
wait=wait_fixed(self.wait_time),
stop=stop_after_attempt(self.max_retries),
)
async def _aembed_batch(batch: list[str]) -> Response:
response = await self.async_client.post(
url="/embeddings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import httpx
import pytest
import tenacity

from langchain_mistralai import MistralAIEmbeddings

Expand Down Expand Up @@ -38,14 +37,14 @@ async def test_mistralai_embedding_documents_async() -> None:
async def test_mistralai_embedding_documents_http_error_async() -> None:
"""Test MistralAI embeddings for documents."""
documents = ["foo bar", "test document"]
embedding = MistralAIEmbeddings(max_retries=0)
embedding = MistralAIEmbeddings()
mock_response = httpx.Response(
status_code=400,
request=httpx.Request("POST", url=embedding.async_client.base_url),
)
with (
patch.object(embedding.async_client, "post", return_value=mock_response),
pytest.raises(tenacity.RetryError),
pytest.raises(httpx.HTTPStatusError),
):
await embedding.aembed_documents(documents)

Expand Down