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
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"""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")
|
||||
Reference in New Issue
Block a user