Add retryable extraction, chunking and ingest worker (I02, #18) #60
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/rag-rust!60
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/18-extraction-chunking"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs #18
What
Retryable extraction and source-preserving chunking for the first approved formats (UTF-8 plain text and Markdown, OD-07 still
proposed), run by a newingest-workerprocess.rag-domain):IngestionJobs,ClaimedJob,ChunkRecord,ExtractionFailure(closed set of 8 safe error codes; onlystorage_unavailableretries).rag-ingestion::extract): verifies profile, SHA-256 digest, UTF-8, control characters and emptiness, in that order, before anything is chunked.text-chunk-v1: at most 1000 source characters, 150 overlap, fixed break order. Each chunk stores half-open UTF-8 byte offsets into the original,text = NFC(original[start..end]), atext_sha256, a language hint (en/ms/mixed/und, a hint only, never used for policy) and a deterministic UUIDv8 id from (version, profile, ordinal). Golden fixtures cover English, Malay, mixed, combining marks, astral characters and CRLF; an 8 MiB input runs in the tests.0012_chunks.sql: job lease columns, thedocument_chunkstable, and a NOLOGINrag_ingest_workerrole with column-level grants (it cannot read title, marking or provenance, cannot update versions, cannot touch audit/outbox). Chunks inherit the version's marking by foreign key.rag_apphas no access to chunks (default-deny, enforced by the startup guard). The existing 0008 policies are now scopedTO rag_app(they previously applied to PUBLIC).PostgresIngestionJobs: lease plusFOR UPDATE SKIP LOCKEDclaim, reaping, attempt cap 5 with backoff (30 s x 2^(n-1), capped at 15 min), lease-fencedcomplete(all chunks andsucceededin one transaction), fencedfail, and backlog counts. Undecodable jobs are retired instead of stalling the queue.ingest-workerbinary (crates/api): separate/health/liveand/health/ready(reusing F07),/metricswith fixed labels only, payload-free panic hook, SIGTERM drain, loopback bind unlessINGEST_WORKER_ALLOW_REMOTE=true. Operator guide:docs/operations/ingestion-worker.md.Deviations and things to know
quarantinedand the jobdeadwith a safe code; the version is not markedunavailable. It is still invisible torag_app(active versions only), and the success path also leaves the versionquarantined. #19-#21 must requirejob.state = 'succeeded'before a version becomes active.NFC(original[byte_start..byte_end]) == textbefore publishing.SELECT (version, success, checksum)on_sqlx_migrationssomigrations::verifyworks; migration 0012 was edited in place during review, so any dev database migrated from earlier #18 commits must be recreated (nothing from this branch is onmain).ingest-workerdoes not readCRYPTO_PROFILE_SETyet (K02 follow-up; see PR #59).failedjobs, chunk retention is undecided (OD-07).Verification
cargo test --workspace: 277/277.scripts/test-postgres.sh --local(real PostgreSQL): 276/276.cargo fmt --checkandcargo clippy --workspace --all-targets -- -D warningsclean.scripts/coverage.sh rust: 94.50% workspace line coverage (minimum 80%). New/changed files: chunk.rs 97.7%, ingestion/worker.rs 98.6%, storage-postgres ingestion.rs 98.5%, ingest_worker.rs 94.8%, bin/ingest-worker.rs 96.0%, domain ingestion.rs 96.9%.api/src/main.rsis 34.5% (identity wiring never covered; this PR only removes lines from it).run_onceabout 2.6 s in a debug build, of which about 2.4 s is chunking outside any transaction and about 250 ms is the single completion transaction (default statement timeout 5 s).Not in this PR
🤖 Generated with Claude Code
CorruptData from complete is failed as invalid_content at once instead of being retried to the cap. Extraction and chunking run on spawn_blocking so an 8 MiB document does not stall the runtime, and a panic there is failed as invalid_content with its payload dropped unread instead of unwinding out of run. rag_ingest_store_errors_total{operation} counts claim, complete, fail and backlog errors from a fixed label set. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>amiryahaya referenced this pull request2026-10-26 13:56:26 +01:00