PROJECT / 002
Java LLM Practice
Reproducible Java conversation, retry and persistence boundaries, alongside attention, cache-cost and quantization-error experiments.
Practice / 01
What remains when history is removed?
Replay a real conversation, then take the request apart. Compare the visible conversation with the messages actually included in the next input.
Local interaction · No model calls · Original Chinese transcript · No input uploads
What was sent
Message list reconstructed from the author’s transcript; not a raw network capture.
Observation / Author transcript
你好!我是 Agnes,由 Sapiens AI 开发。有什么我可以帮你的吗?- Input
- 285
- Output
- 60
- Total
- 345
Token counts belong to this historical run, not a current estimate, price or benchmark.
Move to the next turn to see how the answer becomes part of the next request.
Inspect message JSON · 1 messages
{
"model": "agnes-2.5-flash",
"messages": [
{
"role": "user",
"content": "你好"
}
]
}OVERVIEW
Java conversation, structured output, tools, claim validation and streaming cancellation, alongside attention, cache admission and measured-query experiments.
PROBLEM
Receiving text is only the start: Java must manage valid history and check the output contract.
DECISIONS
Keep Java 8 and native HTTP. Gson serializes requests; strict JsonReader checks validate business fields. Format adaptation is explicit and does not repair categories.
VALIDATION
Each study retains its protocol, pinned revision and raw evidence. Real model calls, synthetic retrieval, thread schedules and the untrained NumPy model are interpreted separately, not pooled into a success rate. See transport cancellation and cache admission for the latest results.
LIMITATIONS
No automatic retries or publishing. A timeout does not prove the server did no work. Structural validity does not establish semantic correctness; JSON-mode support remains unverified.
Code and companion reading
01 / First request →
Native Java 8 HTTP · raw JSON
02 / Parse and input →
Gson · console input · token usage
03 / Multi-turn chat →
Message history · rollback · exit
Companion article (Chinese) →
First request to multi-turn chat
04 / Validate structured output →
Strict parsing · 35 checks · real failures and replay
Second practice article →
After HTTP 200: how should Java validate model JSON?
L1: context position trial →
Protocol, 29 attempts and an independent audit; stopped early, no claim of position independence.
L1v2: paired blocks and pacing →
24 live Agnes 3.0 requests in six complete blocks, with responses, usage and independent auditing.
05 / Transactional chat history →
Candidate snapshot · whole-turn commit · 41 offline checks
TypeScript / Output boundary →
32 cases · raw JSON and unknown · no model calls
L1v3: similar-distractor design →
128 frozen items verified in Java 8 and independently audited; no live run yet
Similar-distractor code and frozen requests →
2, 515 Java offline checks, 60 Node tests, zero live requests
LLM mechanics I: should changing future tokens affect earlier outputs? →
From a two-row hand calculation to a two-layer numeric experiment: causal masks, softmax and future-information leakage.
Java LLM IV: which concurrent response may commit? →
Reproduce reversed response order with real Java threads, then enforce versioned commits, complete turns and bounded receipts.
Java LLM VI: validate retrieval evidence before judging RAG answers →
Implement BM25 and citation boundaries over ten owned synthetic documents and fourteen frozen queries, retaining misses and false hits.
Java LLM V: why can a timed-out tool keep running? →
Build an allowlisted read-only executor and reproduce the distinction between timeout, cancellation and termination.
LLM mechanics II: what does KV caching save, and how do we verify it? →
Compare prefix recomputation, token decoding and chunk caching with output errors, projected-row counts and actual array payloads.
LLM mechanics III: why is a four-slot cache not four-token recomputation? →
Separate absolute positions, cache slots and retained representations with a two-layer sliding-attention experiment.
Java LLM practice (7): a real citation can still support a wrong answer →
22 frozen configuration cases separate citation existence, revision scope, field support and completeness in a Java answer gate.
LLM mechanics (4): when a prefix changes, is the old KV cache still valid? →
Three seeds and six conditions compare unchecked and keyed prefix reuse; numerical equality does not establish permission to share across scopes.
Java LLM practice (8): should an interrupted stream enter conversation history? →
22 loopback HTTP cases separate incremental preview from committing history, testing UTF-8, SSE framing, cancellation and abnormal endings.
LLM mechanics (5): after editing history, can we recompute only the changed suffix? →
27 fixed conditions and 81 raw arrays test longest-prefix cropping, continuation positions, sliding-window fallback and scope isolation.
Java LLM practice (9): why can a cancelled answer overwrite a new conversation? →
18 controlled thread schedules test request ownership for streaming previews, completion and errors, with cancellation and bounded deduplication.
LLM mechanics (6): why can a larger prefix cache still get zero hits? →
324 requests across cold-start traces and 648 arrays test byte-bounded prefix checkpoints, working sets, isolation and LRU eviction.
Java LLM practice (10): why is the reader still running after cancellation? →
30 local HTTP connections separate conversation invalidation, reader exit and server work, comparing Future interruption with socket closure.
LLM mechanics (7): why is caching slower even when it saves computation? →
4,860 measured queries compare three admission policies, connecting byte budgets, working sets, computation and local elapsed time.
Java history and request windows: can a trimmed fact return? →
Follow narrowing, commit, restart and expansion to separate durable conversation history from one request context.
Java retries: three timeouts are not one deadline →
Seven local HTTP conditions separate retryability, Retry-After, attempt limits and elapsed-time budgets.
Durable Java turns: what survives a process crash? →
Checksummed append records, 142 truncated prefixes and three halted JVMs distinguish local recovery from remote exactly-once execution.
Profiling KV reuse: saved work versus added overhead →
Profile 909 queries across signatures, lookup, copying and continuation, including the remaining slowdown.
Tiled attention: preserving results without a full score matrix →
Derive online softmax from a failing block-average baseline and separate smaller temporaries from measured speed.
KV quantization: how many bytes, and at what error? →
Compare tensor and row-wise int8 quantization, including scale bytes and attention error under outliers.
Java idempotent retries: no reply does not mean no effect →
Seven loopback HTTP fault cases explain idempotency keys, concurrent admission, payload conflicts and process-crash gaps.
KV quantization axes: why Key and Value need separate reasoning →
162 archived INT8 comparisons examine tensor, token and K-channel/V-token scales, including cases where the hybrid loses.
Durable delivery and history recovery →
17 scenarios and 193 child-process records. An unkeyed receiver duplicates the effect after a delivery crash; all three history recovery boundaries retain whole turns.
Packed KV, residual windows and block cost →
144 comparisons and 810 timings. Recent float32 windows help recent-focused attention more; block decoding reduces work arrays but is slower on this CPU run.
- Console input
- Messages history
- JSON / HTTP
- Agnes API
- Parse + display
KEEP EXPLORING
Related content
- Tutorials
Calling an LLM with Java 8 — from one request to a conversation
Three runnable Java demos explain HTTP requests, JSON parsing, timeouts and conversation history.
- Tutorials
Java LLM Practice II: How to validate model JSON after HTTP 200
Build a Java 8 output boundary from a real fenced response and three timeouts, with strict validation, a bounded format adapter and reproducible evidence.
- Experiment reviews
Does moving an answer into the middle make a model miss it? An interrupted controlled trial
Six synthetic cases, four context conditions and 29 recorded requests. A Java experiment that separates retrieval results from HTTP 429 failures.
- LAB / 005
L1 / Context position: an interrupted trial
Can the model retrieve the same fact at different positions?
- Engineering cases
LLM experiment II: make the comparison valid before interpreting position
A Java 8 paired-block protocol with 24 live Agnes 3.0 requests, independently audited scores and reported token usage, including the limits of a perfect observed score.
- Engineering cases
Java LLM practice 3: don't let a failed request change conversation history
Candidate snapshots, complete-pair commits and a UTF-8 request budget: 41 offline checks for history that survives failed requests.
- Engineering cases
Does TypeScript validate model output? A 32-case comparison with Java
Assertions, unknown and raw JSON: 22 false accepts, four object-validation blind spots and a bounded Java/TypeScript comparison.
- LAB / 011
A1 / The chat-history commit boundary
How should committed history survive failures, truncation and candidate trimming?
- LAB / 010
TypeScript / Output boundary comparison
Which invalid inputs escape assertions and object validation?
- Engineering cases
After 24 correct answers: designing a more discriminating context experiment
Remove wording and identifier shortcuts, freeze 128 similar-distractor requests, and verify the materials with Java 8 and an independent audit. Offline preparation is not a new model result.
- Mechanisms
LLM mechanics I: should changing future tokens affect earlier outputs?
From a two-row hand calculation to a two-layer numeric experiment: causal masks, softmax and future-information leakage.
- Engineering cases
Java LLM IV: which concurrent response may commit?
Reproduce reversed response order with real Java threads, then enforce versioned commits, complete turns and bounded receipts.
- Engineering cases
Java LLM VI: validate retrieval evidence before judging RAG answers
Implement BM25 and citation boundaries over ten owned synthetic documents and fourteen frozen queries, retaining misses and false hits.
- Engineering cases
Java LLM V: why can a timed-out tool keep running?
Build an allowlisted read-only executor and reproduce the distinction between timeout, cancellation and termination.
- Mechanisms
LLM mechanics II: what does KV caching save, and how do we verify it?
Compare prefix recomputation, token decoding and chunk caching with output errors, projected-row counts and actual array payloads.
- Mechanisms
LLM mechanics III: why is a four-slot cache not four-token recomputation?
Separate absolute positions, cache slots and retained representations with a two-layer sliding-attention experiment.
- LAB / 015
L2–L4 / Attention and cache mechanics
From a two-row hand calculation to a two-layer numeric experiment: causal masks, softmax and future-information leakage.
- LAB / 014
A2 / Concurrent history commits
Reproduce reversed response order with real Java threads, then enforce versioned commits, complete turns and bounded receipts.
- LAB / 001
Retrieval quality comparison
Use fixed questions and documents; compare retrieval hits, citations and answer correctness with and without retrieval.
- LAB / 002
Tool failure recovery experiment
Use controlled read-only tools; inject timeouts and empty results, then record completion and call counts.
- Engineering cases
Java LLM practice (7): a real citation can still support a wrong answer
22 frozen configuration cases separate citation existence, revision scope, field support and completeness in a Java answer gate.
- Mechanisms
LLM mechanics (4): when a prefix changes, is the old KV cache still valid?
Three seeds and six conditions compare unchecked and keyed prefix reuse; numerical equality does not establish permission to share across scopes.
- LAB / 019
L5 / Prefix-cache invalidation
Three seeds and six conditions compare unchecked and keyed prefix reuse; numerical equality does not establish permission to share across scopes.
- Engineering cases
Java LLM practice (8): should an interrupted stream enter conversation history?
22 loopback HTTP cases separate incremental preview from committing history, testing UTF-8, SSE framing, cancellation and abnormal endings.
- LAB / 021
Java LLM practice (8): should an interrupted stream enter conversation history?
22 loopback HTTP cases separate incremental preview from committing history, testing UTF-8, SSE framing, cancellation and abnormal endings.
- Mechanisms
LLM mechanics (5): after editing history, can we recompute only the changed suffix?
27 fixed conditions and 81 raw arrays test longest-prefix cropping, continuation positions, sliding-window fallback and scope isolation.
- LAB / 022
LLM mechanics (5): after editing history, can we recompute only the changed suffix?
27 fixed conditions and 81 raw arrays test longest-prefix cropping, continuation positions, sliding-window fallback and scope isolation.
- Engineering cases
Java LLM practice (9): why can a cancelled answer overwrite a new conversation?
18 controlled thread schedules test request ownership for streaming previews, completion and errors, with cancellation and bounded deduplication.
- LAB / 024
Java LLM practice (9): why can a cancelled answer overwrite a new conversation?
18 controlled thread schedules test request ownership for streaming previews, completion and errors, with cancellation and bounded deduplication.
- Mechanisms
LLM mechanics (6): why can a larger prefix cache still get zero hits?
324 requests across cold-start traces and 648 arrays test byte-bounded prefix checkpoints, working sets, isolation and LRU eviction.
- LAB / 025
LLM mechanics (6): why can a larger prefix cache still get zero hits?
324 requests across cold-start traces and 648 arrays test byte-bounded prefix checkpoints, working sets, isolation and LRU eviction.
- Engineering cases
Java LLM practice (10): why is the reader still running after cancellation?
30 local HTTP connections separate conversation invalidation, reader exit and server work, comparing Future interruption with socket closure.
- LAB / 027
Java LLM practice (10): why is the reader still running after cancellation?
30 local HTTP connections separate conversation invalidation, reader exit and server work, comparing Future interruption with socket closure.
- Mechanisms
LLM mechanics (7): why is caching slower even when it saves computation?
4,860 measured queries compare three admission policies, connecting byte budgets, working sets, computation and local elapsed time.
- LAB / 028
LLM mechanics (7): why is caching slower even when it saves computation?
4,860 measured queries compare three admission policies, connecting byte budgets, working sets, computation and local elapsed time.
- Engineering cases
Java history and request windows: can a trimmed fact return?
Follow narrowing, commit, restart and expansion to separate durable conversation history from one request context.
- Engineering cases
Java retries: three timeouts are not one deadline
Seven local HTTP conditions separate retryability, Retry-After, attempt limits and elapsed-time budgets.
- Engineering cases
Durable Java turns: what survives a process crash?
Checksummed append records, 142 truncated prefixes and three halted JVMs distinguish local recovery from remote exactly-once execution.
- Mechanisms
Profiling KV reuse: saved work versus added overhead
Profile 909 queries across signatures, lookup, copying and continuation, including the remaining slowdown.
- Mechanisms
Tiled attention: preserving results without a full score matrix
Derive online softmax from a failing block-average baseline and separate smaller temporaries from measured speed.
- Mechanisms
KV quantization: how many bytes, and at what error?
Compare tensor and row-wise int8 quantization, including scale bytes and attention error under outliers.
- Tutorials
Java idempotent retries: no reply does not mean no effect
Seven loopback HTTP fault cases explain idempotency keys, concurrent admission, payload conflicts and process-crash gaps.
- Mechanisms
KV quantization axes: why Key and Value need separate reasoning
162 archived INT8 comparisons examine tensor, token and K-channel/V-token scales, including cases where the hybrid loses.
- Tutorials
Durable idempotency: commit identity and result together
Use a framed journal, process crashes and 99 truncated prefixes to explain durable idempotency.
- Tutorials
Outbox delivery: local durability is not remote exactly-once
Compare keyed and unkeyed receivers to separate lost replies, missing receipts and duplicate remote effects.
- Tutorials
Conversation recovery: reconcile intent, receipt and whole turn
Halt the JVM at three commit boundaries and rebuild whole-turn history from durable facts.
- LAB / 042
Durable delivery and history recovery
17 scenarios and 193 child-process records. An unkeyed receiver duplicates the effect after a delivery crash; all three history recovery boundaries retain whole turns.
- Mechanisms
Packed KV groups: what does 4-bit actually save?
Store real nibbles and audit group-scale overhead, padding bytes and attention output error.
- Mechanisms
KV residual windows: do recent tokens deserve higher precision?
Compare early-focused and recent-focused attention to explain unequal gains from the same float32 window.
- Mechanisms
Block KV decoding: less workspace, more time
Separate cache payload, work arrays and observed runtime, retaining 810 timings including slower block decoding.
- LAB / 043
Packed KV, residual windows and block cost
144 comparisons and 810 timings. Recent float32 windows help recent-focused attention more; block decoding reduces work arrays but is slower on this CPU run.