feat(core): Pipeline + Batcher primitives (Step 1.1d)#50
Merged
officialCodeWork merged 1 commit intoMay 24, 2026
Merged
Conversation
Adds the two cross-cutting concurrency primitives the rest of Phase 1 will build on: - ``Pipeline`` (``rag_core.pipeline``) — composable async DAG with bounded queues, per-stage worker counts, and natural backpressure. Stage functions return one item, a ``list[...]`` for fan-out, or ``None`` to drop. ``on_error="fail"`` / ``"skip"`` policies; optional ``error_handler`` callback. Joiner tasks per stage transition handle the different upstream/downstream worker counts cleanly (one ``_DONE`` sentinel per next-stage worker, never more, never fewer). - ``Batcher[Req, Resp]`` (``rag_core.batcher``) — DataLoader-pattern middleware that coalesces concurrent ``load(req)`` calls into one ``batch_fn(reqs)`` invocation. Size trigger (``max_batch_size``) and time trigger (``max_wait_ms``, default 5 ms). Per-request ``asyncio.Future`` keeps error propagation isolated; ``flush()`` forces deterministic shutdown. Both primitives use PEP-695 generic syntax. CancelledError is intentionally allowed to propagate in every layer so structured cancellation tears the pipeline down cleanly. Tests: 22 new (8 Batcher + 14 Pipeline) covering coalescing, size / time triggers, error propagation, length-mismatch handling, fan-out, filter, backpressure, per-stage worker concurrency, fail / skip error policies, source-exception surfacing, and early-break cleanup. Full suite: 549 passed, 1 skipped. Documentation ------------- - New: docs/architecture/pipeline-batcher.md — design, usage, internals, extension points. - Updated: docs/reference/rag-core.md (Concurrency primitives section), docs/README.md (index entries), docs/architecture/performance.md (cross-link). Step 1.1d of the Phase 1 refactor window (1.1a–1.1f). Unblocks Step 1.10 (write-path), Step 1.2 (connectors framework), and the future Embedder / Reranker / LLM adapters that will sit under the Batcher per the performance.md reviewer checklist. ``rag-core`` 0.5.0 → 0.6.0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7 tasks
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
Pipeline(rag_core.pipeline) — composable async DAG with bounded queues, per-stage worker counts, and natural backpressure. Joiner tasks per stage transition cleanly handle different upstream/downstream worker counts;on_error="fail"/"skip"policies; optionalerror_handlercallback.Batcher[Req, Resp](rag_core.batcher) — DataLoader-pattern middleware that coalesces concurrentload(req)calls into one batchedbatch_fn(reqs)invocation. Size trigger (max_batch_size) + time trigger (max_wait_ms, default 5 ms). Per-requestasyncio.Futurefor isolated error propagation;flush()for deterministic shutdown.CancelledErroris intentionally allowed to propagate everywhere so structured cancellation tears the pipeline down cleanly.rag-core0.5.0 → 0.6.0.Step 1.1d of the Phase 1 refactor window (1.1a–1.1f). Unblocks Step 1.10 (write path), Step 1.2 (connectors framework), and the future Embedder / Reranker / LLM adapters that will sit under the Batcher per the performance.md reviewer checklist.
Tests
task lintclean;mypy --strictclean for new files (two pre-existingrag_observabilityimport-resolution warnings inrag_core.logging/rag_core.eventsshims are unchanged frommain).Documentation
Per the per-PR docs requirement (CLAUDE.md):
docs/architecture/pipeline-batcher.md— design, usage, internals, error semantics, extension points (public + technical sections).docs/reference/rag-core.md(Concurrency primitives section),docs/README.md(architecture + reference index entries),docs/architecture/performance.md(Related cross-link).Tracker
Test plan
uv run pytest packages/core/tests/test_batcher.py packages/core/tests/test_pipeline.py -xuv run pytest tests/ packages/ -k "not integration"(549 passed)uv run ruff check .cleanuv run mypy packages/core/ apps/gateway/clean for new filesPYTHONPATH=packages/core/src:packages/observability/src uv run python -m rag_core.gen_schemas dist/schemas/) — no drift🤖 Generated with Claude Code