
A RAG Co-Pilot for PCBA Test Logs That Refuses to Guess
A synthetic PCBA test-log pipeline, automated SPC and a citation-forced RAG co-pilot that refuses to answer when it isn't sure, built over eight weeks of evenings and weekends.
- Published
- July 3, 2026
- Author
- Hrushiekesh Reddy Kanjula
- Read time
- ~7 min
- Category
- engineering
Flying-probe and in-circuit testers emit structured logs, millions of measurement records per shift. The data is there. The analytics layer usually isn't. Factories pay for a commercial suite or use Excel. Root-cause work still comes down to "we saw something like this on lot 2024-W18, ask Kevin." That stops working when Kevin takes a week off.
Four gaps cost real time on the floor:
- Flat-file logs. Correlating a shift's yield drop with one component family takes hours, not minutes.
- SPC not automated. Wheeler XmR charts, run-of-8 and zone rules are well understood on paper. They are almost never automated against real test data.
- Unwatched outliers. One part number can start failing at four times the line average, and nobody is watching that slice.
- Root cause by chat. A question like "why are these 0402s tombstoning?" becomes a Slack message to whoever remembers, not a query that returns a cited answer in seconds.
I spent the last two months closing those four gaps for the open-source, local-first, single-engineer case. There is no cloud service and no vendor contract. It is one DuckDB file on a laptop. Below is what shipped and the three bugs that changed how I think about a class of problems.
What's running
A synthetic HP3070/i3070 log generator produces Keysight Log Record Format output across three board profiles. It has configurable fault correlation and shift-physics-aware timestamps, and runs at about a second per thousand panels. A parser turns that output into a nine-table DuckDB schema: five dimension tables, one run table and three fact tables.
The analytics library on top is deliberately thin. It has four pure Python functions:
yield_over_timefailure_paretoindividuals_chart, a Wheeler XmR chart with run-of-8z_score_anomalies, leave-one-out and severity-first
A six-page Streamlit dashboard renders all of it.

The Pareto and SPC pages are where the automation pays off. Failure-mode ranking used to mean a pivot table. Now it updates as new runs land. The individuals chart flags zone violations when a shift drifts, not two days later when someone opens Minitab.


The co-pilot
The second half is a hybrid RAG co-pilot. It is grounded in an eight-document failure-mode knowledge base: opens, shorts, cold joints, missing components, misorientation, tombstoning, out-of-tolerance analog and insufficient solder. Each document cites the relevant IPC or J-STD section without quoting the copyrighted text.
Retrieval runs ChromaDB (cosine HNSW) and rank-bm25 in parallel. The two are fused with Reciprocal Rank Fusion at k=60. Vector search alone misses exact-match queries like "Q15" or "0402", and BM25 catches those. ChromaDB catches semantic phrasing, like "lifted leads" matching "open joints." Fusing both beat tuning a weighted blend of either one alone.
The contract
The answer() function refuses to respond unless four conditions all hold:
- Retrieval returned at least one hit.
- The model emitted valid JSON.
- The response's
sufficientfield istrue. - At least one cited chunk ID exists in the retrieved set.
Hallucinated citations are dropped before they reach the user. The model is never called on an empty retrieval, so a failed lookup costs zero tokens. The refusal text is a fixed constant, not LLM output. A confident-sounding refusal can't sneak past the contract.

The eval
The eval discipline mattered as much as the retrieval design. There are ten frozen questions, one per failure-mode document, checked two ways:
- An offline citation-pattern test with a stubbed retriever and a stubbed LLM. It runs in CI for free.
- An env-gated live test that calls the real API and asserts at least 8 of 10 correct citations.
That bar later tightened to 12 of 15, after a terse-query retrieval miss exposed a real gap. Both bars are green as of the last run.
Three bugs, three lessons
Each phase produced one bug that changed how I think about a whole class of problem.
The shift-snap that lied about time
The synthetic generator schedules panels across three shifts. Shift C runs 22:00 to 05:59. A raw timestamp of 02:00 therefore belongs to the window that started the previous evening.
My first cut drew a shift letter uniformly per panel, then snapped the timestamp into that shift's window. The overnight wrap correction was a literal pass statement. A 02:00 draw assigned to shift C silently jumped to 22:00 the same day. SPC trend analysis on that data would show fictitious shift-to-shift yield deltas, presented as fact.
Patching the wrap was not the fix. The fix was to derive the shift from time-of-day instead of drawing it independently and reconciling afterward. _shift_for_hour(hour) returns the correct shift. _shift_window_start(ts, shift) snaps to the right window start. The broken pass became unreachable because the two values can no longer disagree.
The lesson goes beyond this project. If two correlated parameters are drawn independently and then reconciled, the reconciliation step is where the bug lives. Derive one from the other and that class of error goes away.
The model that got retired mid-evaluation
The Phase 3 exit criterion was a live evaluation of at least 8/10 against Gemini on a frozen ten-question dataset. The first attempt ran two minutes thirty-one seconds and failed with a 404. Google had retired gemini-2.0-flash. All of that wall-clock time was gRPC's retry deadline timing out against a dead endpoint, not real API work.
The fix took three lines. I bumped the model constant, updated the test mirror and refreshed the env example. The re-run passed 10/10 in 37 seconds. It was four times faster only because it no longer retried something that didn't exist.
A vendor model ID is versioned external state, not a constant in your codebase. DEFAULT_MODEL = "gemini-2.0-flash" reads like a config value. It is really a contract with a remote API that can be revoked without notice. I migrated off the deprecated google-generativeai SDK to its successor the same day, and the live eval re-ran green without touching the model ID again.
The test that only broke under concurrency
A parser test passed every time in isolation. Inside the full suite it failed about 60% of the time, sometimes on a partial-read assertion and sometimes on a Windows file-lock error.
The cause was a test helper writing to a fixed path at the repo root. Alone, there is no contention. In the full suite, Windows file-watchers, antivirus and parallel pytest workers all hit the same path mid-write. The fix was to thread pytest's tmp_path fixture through every call, so each test gets its own OS-temp file. A two-thread stress harness confirmed it. The shared-path version failed 484 times out of 800. The isolated version passed 800 out of 800.
Shared mutable state in tests is the same anti-pattern as in production, and flakiness is its most visible symptom. This one stuck with me because the test was correct in isolation. The bug existed only under concurrency, which is easy to dismiss as "flaky" and re-run past. I now grep for repo-root file writes in every test-helper review.
What I'd do differently
- Migrate the vendor SDK when it is flagged end-of-support. Waiting for a 404 doesn't make the migration cheaper, especially on your critical path.
- Capture screenshots from CI, not by hand. This is already fixed. A headless Playwright pipeline regenerates all six images and the demo gif from one command.
- Validate on real data earlier. The guardrail that real customer logs only touch the work network is correct. It also means realistic edge cases surface late. A synthetic-but-realistic stress test would have caught a hardcoded
shift="A"in the parser at the start of Phase 2, not midway through it.
Try it
The repo is public and MIT-licensed at flying-probe-copilot. It has a scripted five-minute walkthrough in docs/DEMO.md, and every plan, decision and bug is logged under docs/logs/.
It is the sibling project to Assembly-Hub. The same approach runs there against a live SMT line: synthetic-first development, eval-as-code, and guardrails logged before they're needed.
If you work on test-log data or PCBA quality and want to compare notes, reach out through the contact page.