Files
rag-technical-docs-assistant/app/modules/documents/operational_limits.py
T
amirhosein mazaheri 39ed0422c5 feat(ingestion): implement Phase 4 chunking and vector embedding generation
- Add heading and paragraph-preserving chunking algorithms with bounded overlap
- Implement OpenAI embeddings client adapter with explicit token limits and batching
- Implement stage_document pipeline with strict operational limits and memory protections
- Add unit and integration tests covering chunking boundaries, timeouts, and vector generation
2026-10-07 16:21:17 +03:30

29 lines
1.1 KiB
Python

"""Conservative operational bounds shared by configuration and runtime consumers."""
import math
from threading import TIMEOUT_MAX
MAX_OPERATIONAL_SECONDS = min(TIMEOUT_MAX, (2**31 - 1) / 1000.0)
MIN_OPERATIONAL_SECONDS = 1e-6 # PostgreSQL interval/timestamp microsecond precision.
def validate_duration(value):
valid = False
if type(value) in (int, float):
try:
valid = math.isfinite(value) and MIN_OPERATIONAL_SECONDS <= value <= MAX_OPERATIONAL_SECONDS
except OverflowError:
pass
if not valid:
raise ValueError("Operational duration is not representable by runtime or PostgreSQL")
return float(value)
def validate_worker_durations(settings):
for name in ("poll_seconds", "heartbeat_seconds", "lease_seconds",
"retry_base_seconds", "retry_cap_seconds"):
validate_duration(getattr(settings, name))
if settings.heartbeat_seconds >= settings.lease_seconds:
raise ValueError("Heartbeat must be shorter than lease")
if settings.retry_base_seconds > settings.retry_cap_seconds:
raise ValueError("Retry base must not exceed retry cap")