Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle backoff and bundle requests for API timing (#81)
Nomic's embedding API is rate limited to 2 requests per second, but these can include multiple embeddings. This PR does two things. 1. Batches together all requests in the `Embedder` class into 510 ms groups to ensure that users are automatically kept within the rate limit. 2. Respects the 429s newly sent from the API server with exponential backoff of up to 8 seconds. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Batch requests in `Embedder` class every 510 ms and handle 429 errors with exponential backoff to comply with API rate limits. > > - **Behavior**: > - Batches requests in `Embedder` class every 510 ms to comply with API rate limit of 2 requests per second. > - Implements exponential backoff up to 8 seconds for 429 errors in `flushDeferredEmbeddings()`. > - **Constants**: > - Increases `BATCH_SIZE` from 32 to 400 in `embedding.ts`. > - **Error Handling**: > - Re-queues failed requests due to 429 errors in `flushDeferredEmbeddings()`. > - Throws error if `embedQueue` exceeds 100,000 items in `embed()`. > - **Misc**: > - Adjusts `setTimeout` in `periodicallyFlushCache()` to 510 ms. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=nomic-ai%2Fts-nomic&utm_source=github&utm_medium=referral)<sup> for 2dcf449. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information