Technical Architecture & Methodology

How BatchTrace Agent Works

A step-by-step walkthrough of how disconnected food manufacturing records become a navigable, deterministic traceability graph powered by controlled open-weight AI.

01

Document Ingestion & Coordinate Provenance

CSV, XLSX, Text PDF, and Dock Logs

When documents are uploaded, BatchTrace validates file headers, validates MIME types, and uses deterministic regex parsers alongside AI extraction to parse supplier invoices, dock receipts, production sheets, and bills of lading.

Zero Hallucinated Citations Principle:

For every extracted lot code, quantity, and timestamp, BatchTrace records exact source coordinates: Document ID, page number, row index, original extracted text, and normalized value. If a citation cannot be pointed to an actual byte or row in storage, it is marked invalid.

02

Deterministic Graph Traversal & Quantity Reconciliation

PostgreSQL Foreign Keys, Join Tables, and Certainty Levels

Traceability is not entrusted to an LLM prompt. Traversal logic executes in typed TypeScript and PostgreSQL relational queries across Suppliers → Ingredient Lots → Production Batches → Finished Lots → Customer Orders.

Certainty Classification:

  • • Confirmed: Backed by approved documents and validated joins.
  • • Possible: Pending review (e.g. unreviewed batch sheet) or matching rule.
  • • Unknown: Missing data explicitly highlighted.

Quantity Reconciliation:

Compares received ingredient mass against cumulative batch usage. Automatically flags variances (such as the 50 kg overage on Lot L-204) without silently coercing numbers.

03

Controlled AI Agent & Open-Weight Inference

Qwen3-4B / Local Ollama Adapter with Tool Calling

The AI model is sandboxed behind server-side typed tools (`trace_ingredient_lot`, `check_quantity_discrepancies`, `get_source_evidence`). It has zero direct SQL execution, no arbitrary file system permissions, and cannot fabricate business entities.

Controlled Tool Sequence:

> Understand Query: "Which batches used lot L-204?"

> Call Tool: get_ingredient_lot(lotId="L-204")

> Call Tool: trace_ingredient_lot(lotId="L-204", direction="FORWARD")

> Ground Explanation in Verified DB Records

> Output Evidence Chips & Request Human Sign-off

04

Human Decision-Support & Audit Trail

Formal Incident Generation with Sign-off Controls

BatchTrace is decision-support software. It prepares formal incident reports with affected batches, retail destination addresses, and discrepancy breakdowns, but requires an authorized QA manager to approve next actions.