Finding and extracting repeating patterns from noisy sequences using Jev — TypeSafe's System One model that answers typed questions (probabilities, choices, scores) instead of generating text.
This repo is a small experiment with one real finding: how you split the work between code and the model matters more than the model's capability. The same model that face-planted on a noisy sequence solved it in 2 calls once the representation changed.
Goal: given a number sequence like 1,2,1,2,1,2, detect whether it contains a
repeating pattern and extract the repeating unit — then survive noise, and
eventually multiple patterns at once.
Ask Jev one question at a time, like a detective:
- "Does
sequencecontain a repeating pattern?" (yes/no) - "What number is in position 1 of the shortest repeating unit?" (choice menu = the digits actually present)
- "Is
unit_so_farthe complete unit, or does it continue?" (head-to-head choice) — repeat 2–3 until "complete"
This works great on easy input, and each refinement taught us something:
- Rules must be in the prompt. Given
1,2,1,2,5,1,2,1,2, Jev absorbed the noise5into a[1,2,1,2,5]unit — a defensible reading we never ruled out. Adding "the unit must fully repeat; one-off values are noise" fixed it. - Questions need memory. Each API call is independent. Passing
unit_so_faras state (and asking "complete or continues?") turned a coin-flip termination signal (~0.51) into a confident one (0.70–0.96).
Then the stress test: 42 numbers, 64% noise, the unit [7,3,8,2,4] hidden 3
times, noise deliberately reusing the unit's own digits.
Total collapse. Jev picked a noise value for position 1 (confidence 0.25 —
it knew it was guessing), which poisoned unit_so_far, and every subsequent
answer compounded the error: 85 API calls, 13.7 seconds, and a 42-entry garbage
unit ending in thirty-six consecutive 4s. Greedy sequential extraction has no
way to back up.
Flip the labor. Counting repeats is mechanical — code is perfect at it and cannot be sweet-talked by noise:
- Mine candidates in code (zero API calls): slide every window across the
sequence, count non-overlapping full occurrences, keep anything appearing
twice, prune shadows (
[7,3]inside[7,3,8,2,4]) and doubled units ([1,2,1,2]), rank by coverage. - One semantic judgment per candidate: "Is
candidatea genuine repeating pattern withinsequence, rather than a coincidental arrangement of unrelated values?" Independent questions — no shared state, no error compounding. Hard budget of 100 calls.
Same 42-number gauntlet:
mined 2 candidate(s): [7,3,8,2,4]×3 [7,3,8,2,4,1]×2
candidate [7,3,8,2,4]×3 -> true (p 0.91)
candidate [7,3,8,2,4,1]×2 -> true (p 0.88)
result (563ms, 2 tries): correct
85 calls of garbage → 2 calls of right answer. And multiple patterns fall out for free:
sequence: [1,2,1,2,1,2,5,7,8,9,7,8,9,0,1,2]
candidate [1,2]×4 -> true (p 0.85)
candidate [7,8,9]×2 -> true (p 0.74)
candidate [2,1]×2 -> true (p 0.82)
Both real patterns found (plus [2,1], the phase-shifted echo of [1,2] —
Jev isn't wrong, it does repeat; deduping rotations is mechanical work that
belongs in code, next on the list).
A ~100-line wrapper that makes Jev feel like a language primitive:
import { jev, QueryType } from "./src/jev";
const r = await jev.send(
jev.create(QueryType.choice, {
prompt: "Which team should handle this ticket?",
choices: { billing: "payments, refunds", technical: "bugs, outages" },
state: { ticket: "I was charged twice for the same month." },
})
);
if (r instanceof Error) retry();
else if (r === null) punt();
else r.value; // "billing" — the winner, whatever the question typejev.create(type, spec)→ a complete wire-ready query. Three types:question(yes/no),choice(pick from a menu),score(graded levels).jev.send(body)→JevResult | null | Error, never throws.- Every result has the same shape:
value/max(winner),min(loser),probabilities,confidence, pluspositionfor scores. Yes/no answers are exposed as a{ true, false }distribution so all three types rank alike. src/jev-client.tsholds the transport (timeout, retry, backoff).
Field notes baked into the code: the API rejects state: null (send ""),
choice criteria are name → description maps (null when the name speaks for
itself), score criteria are ordered low→high arrays of 2–10 levels.
# needs bun (https://bun.sh); no dependencies
cp .env.example .env # add your TYPESAFE_API_KEY
bun test # 35 tests, all mocked — no API calls
bun run showcase # one query of each type, live: query/raw/parsed dumps
bun run pattern # greedy interrogation (bun src/pattern.ts 1,2,5,1,2,5)
bun run patterns # miner + judge on both demo sequences, or your own CSV- Representation beats capability. Both attempts used the same model.
- Put definitions in the prompt — Jev will find every loophole your rule leaves open, and it's usually right to.
- Give sequential questions memory via state, or don't ask sequentially.
- Let code do what code is good at. Counting is code's job; meaning is the model's. One narrow semantic judgment per API call, independent of the others, is the shape that scales.
- Watch the confidence. Every failure announced itself (0.25, 0.09…) before it compounded. Thresholds and guardrails are free wins.