Skip to content

GoogleGenerativeAIEmbeddings fails with ResourceExhausted error for large document lists #916

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

Open
Mersho opened this issue May 10, 2025 · 1 comment

Comments

@Mersho
Copy link

Mersho commented May 10, 2025

1. Steps To Reproduce

  1. Run the following Python code:
    from langchain_google_genai import GoogleGenerativeAIEmbeddings
    
    embeddings = GoogleGenerativeAIEmbeddings(
        model="models/gemini-embedding-exp-03-07",
        task_type="RETRIEVAL_DOCUMENT",
        google_api_key="<YOUR_GOOGLE_API_KEY>",
    )
    
    docs = [
        "Today is Monday",
        "Today is Tuesday",
        "Today is April Fools day",
    ]
    
    vector = embeddings.embed_documents(docs * 50)
    
    print(f"Successfully embedded {len(vector)} documents.")

2. Current Results

The script fails with a traceback, indicating a resource exhaustion error:

Traceback (most recent call last):
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\langchain_google_genai\embeddings.py", line 228, in embed_documents
    result = self.client.batch_embed_contents(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 1437, in batch_embed_contents
    response = rpc(
               ^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\retry\retry_unary.py", line 293, in retry_wrapped_func
    return retry_target(
           ^^^^^^^^^^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\retry\retry_unary.py", line 153, in retry_target
    _retry_error_helper(
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\retry\retry_unary.py", line 144, in retry_target
    result = target()
             ^^^^^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\timeout.py", line 130, in func_with_timeout
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\google\api_core\grpc_helpers.py", line 78, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.ResourceExhausted: 429 Resource has been exhausted (e.g. check quota).

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\PC\PycharmProjects\embedding\test.py", line 15, in <module>
    vector = embeddings.embed_documents(docs * 50)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\PC\PycharmProjects\embedding\.venv\Lib\site-packages\langchain_google_genai\embeddings.py", line 232, in embed_documents
    raise GoogleGenerativeAIError(f"Error embedding content: {e}") from e
langchain_google_genai._common.GoogleGenerativeAIError: Error embedding content: 429 Resource has been exhausted (e.g. check quota).

3. Expected Results

The embeddings.embed_documents() call should successfully process all documents


Environment Details:

  • OS: Windows 11
  • Python Version: 3.12.7
  • Platform: AMD64
  • langchain-google-genai Version: 2.1.4

@BjornvanBraak
Copy link

BjornvanBraak commented May 12, 2025

Experiencing similar issues. Temporarily solved it by limiting the batch request to one per minute (and leaving the default batch size to 100). It has to do with quota's being hit, but it is unclear to me what quotas as at least the standard quota system has enough room ('Batch embed contents request limit per minute for a region' has 150 per minute per region). However, I did not find which quota system was limiting my requests.

I am currently on the tier 1 plan with api key through Google AI Studio.

Anyone who knowns which quota system is used here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants