Skip to content

Commit 72e2480

Browse files
committed
docs: add documentation for retry decorator with exponential backoff and configuration details
1 parent cdb5445 commit 72e2480

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

libs/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ It consists of the following python packages:
1818
- [3.3 Replaceable parts](#33-replaceable-parts)
1919
- [`4. RAG Core lib`](#4-rag-core-lib)
2020
- [4.1 Requirements](#41-requirements)
21+
- [4.2 Retry decorator (exponential backoff)](#42-retry-decorator-exponential-backoff)
2122

2223
With the exception of the `RAG Core lib` all of these packages contain an API definition and are easy to adjust for your specific use case.
2324
Each of the packages defines the replaceable parts([1.3 Replaceable Parts](#13-replaceable-parts), [2.3 Replaceable Parts](#23-replaceable-parts), [3.3 Replaceable Parts](#33-replaceable-parts)), expected types and offer a brief description.
@@ -262,3 +263,53 @@ In addition to python libraries the following system packages are required:
262263
build-essential
263264
make
264265
```
266+
267+
### 4.2 Retry decorator (exponential backoff)
268+
269+
The `rag-core-lib` provides a reusable retry decorator with exponential backoff and rate‑limit awareness for both sync and async functions.
270+
271+
- Module: `rag_core_lib.impl.utils.retry_decorator.retry_with_backoff`
272+
- Settings: `rag_core_lib.impl.settings.retry_decorator_settings.RetryDecoratorSettings`
273+
- Works with: synchronous and asynchronous callables
274+
- Rate-limit aware: optionally inspects HTTP status 429 and headers like `x-ratelimit-reset-requests` / `x-ratelimit-reset-tokens`
275+
276+
Usage example
277+
278+
```python
279+
from rag_core_lib.impl.utils.retry_decorator import retry_with_backoff
280+
from rag_core_lib.impl.settings.retry_decorator_settings import RetryDecoratorSettings
281+
282+
# Configure via code (env vars also supported, see below)
283+
settings = RetryDecoratorSettings(
284+
max_retries=3,
285+
retry_base_delay=0.2,
286+
)
287+
288+
@retry_with_backoff(settings=settings)
289+
def fetch_something():
290+
return "ok"
291+
292+
@retry_with_backoff(settings=settings)
293+
async def fetch_async_something():
294+
return "ok"
295+
```
296+
297+
Configuration
298+
299+
- Environment variables (prefix `RETRY_DECORATOR_`):
300+
- `RETRY_DECORATOR_MAX_RETRIES` (default: 5)
301+
- `RETRY_DECORATOR_RETRY_BASE_DELAY` (default: 0.5)
302+
- `RETRY_DECORATOR_RETRY_MAX_DELAY` (default: 600)
303+
- `RETRY_DECORATOR_BACKOFF_FACTOR` (default: 2)
304+
- `RETRY_DECORATOR_ATTEMPT_CAP` (default: 6)
305+
- `RETRY_DECORATOR_JITTER_MIN` (default: 0.05)
306+
- `RETRY_DECORATOR_JITTER_MAX` (default: 0.25)
307+
308+
- Helm chart (shared values): set the same keys under `shared.envs.retryDecorator` in [infrastructure/rag/values.yaml](../infrastructure/rag/values.yaml) to apply cluster‑wide defaults for backend/admin services.
309+
310+
Advanced
311+
312+
- Customize which exceptions trigger retries via `exceptions` and `rate_limit_exceptions` parameters of `retry_with_backoff()`.
313+
- Header‑based wait: When rate‑limited, the decorator will honor reset headers if present and add jitter.
314+
315+
For more examples, see tests in [./rag-core-lib/tests/retry_decorator_test.py](./rag-core-lib/tests/retry_decorator_test.py).

0 commit comments

Comments
 (0)