Term Cleanup: Handle embedding generation errors like rate limits

Open
#906 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
php, wordpress
Domain
ai, backend

Research direction

The issue does not name files or tests; first locate the cleanup flow that generates embeddings and inspect how API responses and rate-limit failures are currently handled. Done means general API errors stop with a visible message, while rate-limit responses retry with bounded backoff or eventually stop with an error, backed by tests for both paths.

Written by the indexing model from the issue text.

Description

Is your enhancement related to a problem? Please describe.

Originally documented by @dkotter:

I didn't run into any errors when testing but in looking at the code, it doesn't seem we ever look at the response from generating an embedding.

So in a scenario where this API request fails, we just continue on to the next term. Think of a situation where the API goes down or we hit rate limits on the API. In that case, the process will continue to try forever even though we aren't getting any results from the API.

I'd suggest, if easy enough, two different approaches:

  1. If we get just a general error response from the API (i.e. the API is down), I think we should show that error message and stop the process from continuing
  2. If we get a rate limit error, ideally we would pause for a minute or two before proceeding and then try again. If it fails again with a rate limit error, maybe increase our pause by a couple minutes. Once we've tried this a few times, we can then output an error and stop the process. So basically an automatic retry mechanism with a built-in backoff mechanic to try and handle rate limit issues.

Note this last piece may be overkill for this so we can discuss whether it's worth the effort or not.

Designs

Originally documented by @dkotter:

Note that OpenAI exposes some headers around rate limits that would be interesting to use: https://platform.openai.com/docs/guides/rate-limits/rate-limits-in-headers

They also provide some examples (in python) on how to build an exponential backoff system: https://platform.openai.com/docs/guides/rate-limits/retrying-with-exponential-backoff

Describe alternatives you've considered

Originally reported via https://github.com/10up/classifai-cleanup/issues/3

Code of Conduct
  • I agree to follow this project's Code of Conduct
Dominant language
PHP
Stars
714
Forks
68
Avg merge
4h 32m
Merged PRs (30d)
23

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 10up/classifai

All issues in 10up/classifai

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.