Add a rate limiter for litellm#125
Merged
georgeh0 merged 1 commit intococoindex-io:mainfrom Apr 6, 2026
Merged
Conversation
georgeh0
reviewed
Apr 5, 2026
Member
georgeh0
left a comment
There was a problem hiding this comment.
Thanks for the PR!
There's a bunch of CI errors because of mypy. Please fix and also run a uv run mypy . to check.
Comment on lines
+38
to
+51
| class _PacedEmbedderInstance: | ||
| """Inner batched embedder for a specific input_type.""" | ||
|
|
||
| def __init__(self, embedder: PacedLiteLLMEmbedder, input_type: str | None) -> None: | ||
| self._embedder = embedder | ||
| self._input_type = input_type | ||
|
|
||
| @coco.fn.as_async(batching=True, max_batch_size=64) | ||
| async def embed(self, texts: list[str]) -> list[NDArray[np.float32]]: | ||
| kwargs = dict(self._embedder._kwargs) | ||
| if self._input_type is not None: | ||
| kwargs["input_type"] = self._input_type | ||
| response = await self._embedder.run_embedding_request(input=texts, **kwargs) | ||
| return [np.array(item["embedding"], dtype=np.float32) for item in response.data] |
Member
There was a problem hiding this comment.
We won't need a separate instance. We can just add additional argument like input_type directly to the PacedLiteLLMEmbedder.embed() method like this:
Contributor
Author
There was a problem hiding this comment.
thank you, this should now be fixed, including for the pre-commit
1cca4c3 to
724afe2
Compare
724afe2 to
4959ed0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PacedLiteLLMEmbedderto serialize LiteLLM embedding requests, apply configurable minimum request spacing, and retry rate-limited calls with bounded backoff.min_interval_msand persists that field through settings serialization and deserialization.5mspacing interval when the setting is omitted, and documents the new configuration in the user-facing markdown references.litellm.aembeddingcalls.Validation
uv run pytest tests/test_litellm_embedder.py -vpassed with2 passed in 1.60s.uv run pytest tests/ -vpassed with108 passed in 159.00s.uv run pre-commit run --all-filespassed.