RailShot-Stream / RUN.md
chadstthomas's picture
Stage verified RailShot Stream industry preview
efc59a3 verified
|
Raw History Blame Contribute Delete
3.42 kB
# RailShot Stream
RailShot adds durable, ordered JSONL sessions to MagicEightBall’s incremental CPU and NCS1 runners. Text fragments in a session share a document and a decision history. Each successful append returns the resulting Boolean answer, category, and proposed action as data.
## Run locally
Use Python 3.11+ with NumPy, ONNX Runtime, and SentencePiece. Run from the repository root.
```powershell
python -m pip install numpy onnxruntime sentencepiece
@"
{"stream_id":"case-42","seq":1,"append":"Duplicate charge. "}
{"stream_id":"case-42","seq":2,"append":"Review authorized."}
{"stream_id":"case-42","seq":3,"append":" Do not route."}
"@ | python -m apps.railshot --db results/railshot.sqlite3
```
The second result proposes `review_billing`. The third clears the proposal. Run the same command again with the same journal to retrieve the committed results. To continue the document, send sequence 4.
The default CPU artifact is the repository’s radix ONNX. Use `--artifact path/to/model.onnx` for another MagicEightBall CPU export and keep its adjacent `model.json`. A journal is bound to the artifact, policy manifest, and tokenizer.
## Run on the original Intel NCS
Use the Windows OpenVINO 2020.3.2 toolchain with Python 3.7, NumPy and SentencePiece 0.1.99. The adapter checks for a cold USB device with product ID 2150 before loading the compact native archive. Use a separate journal for the two backends.
```powershell
$toolchain = 'C:/path/to/ncs1'
$python = Join-Path $toolchain '.venv/Scripts/python.exe'
& $python -m pip install sentencepiece==0.1.99
@"
{"stream_id":"case-42","seq":1,"append":"Duplicate charge. "}
{"stream_id":"case-42","seq":2,"append":"Review authorized."}
"@ | & $python -m apps.railshot --backend ncs1 --toolchain $toolchain --db results/railshot-ncs1.sqlite3
```
The learned decision head runs on the stick. Tokenization, evidence extraction, and transaction commits run on the host. The physical replay passed two process launches, two independent documents, exact retries, a late veto, a gap rejection, and recovery after an append exceeded 131,072 tokens. Stable JSON replies go to stdout. Native runtime diagnostics go to stderr.
## Protocol
- A `stream_id` has 1–64 ASCII letters, digits, underscores, periods, or hyphens, beginning with a letter or digit. Each stream starts at `seq: 1` and advances by one on each commit. Different streams can be interleaved.
- Send `append` as a text fragment. `reset: true` starts a fresh document at the next sequence number, with optional initial text. Each active document has MagicEightBall’s 131,072-token limit.
- Success is a `railshot.result/1` object with `ok: true`, the stream ID, sequence, and `decision`. Resubmitting the same fragment and reset flag at an accepted sequence returns the recorded response. A different payload at that sequence produces `conflicting_retry`.
- Errors return `ok: false` with an `error` object. A gap reports `out_of_order` and `expected_seq`. A rejected append leaves the next sequence available. Successful results carry stable decision fields for replay.
- SQLite stores the request text, reset flag, and response in one transaction before stdout acknowledges success. Restart with the same journal to recover the active document from its committed fragments. Earlier results remain available for retries after a reset.