Aidan Riordan
Aidan Riordan

Reputation: 1

Embedding openai api, ratelimit error short text

Does anyone have any experience creating embeddings with Openai's API? I am stuck on an odd error (rate limit) on the first step from my few lines of code when I try to run openai.Embedding.create(input=short_string, model="text-embedding-ada-002 ). If anyone has any ideas it would be much appreciated!

(I am sure my api key is valid and has credits, I tried multiple across 2 accounts one of them is paid)

Upvotes: 0

Views: 1389

Answers (3)

tbo812
tbo812

Reputation: 45

I use something like this (I'll only post a snippet). If error 429 occurs (refers to Rate Limit by OpenAI), wait 60 seconds. If it occurs again, I split Batch in two and try again after 60 seconds. And so on...

...
    except HTTPException as http_error:
        if http_error.status_code == 429: # back off if rate limit reached
            logger.info("HTTP RATE LIMIT REACHED: {0}", str(http_error.detail))
            time.sleep(60)
            if len(documents_chunk) == 1:
                # retry the single document
                process_documents_chunk(documents_chunk, retries + 1)
            else:
                # Recursively divide and process the documents
                half = len(documents_chunk) // 2
                process_documents_chunk(documents_chunk[:half], retries + 1)
                time.sleep(60)
                process_documents_chunk(documents_chunk[half:], retries + 1)
        else:
            logger.exception("HTTP ERROR: {0}", str(http_error.detail))
            raise
...

Upvotes: 0

Matt
Matt

Reputation: 1

What worked for me was to include a more appropiate delimiter for the TextSplitter. In my case:

text_splitter = CharacterTextSplitter(chunk_size=800, chunk_overlap=50, separator="\n")

Upvotes: 0

zaffer
zaffer

Reputation: 446

As per the rate limits documentation, you might have to wait for 48 hours for the initial limits to be lifted. The subsequent limits are much more accommodating.

Upvotes: 0

Related Questions