PROJECT / 002

Java LLM Practice

Reproducible Java conversation, retry and persistence boundaries, alongside attention, cache-cost and quantization-error experiments.

Building · UPDATED 2026-10-11

Java 8 · Gson · HTTP · TypeScript · Node.js · Python · NumPy

GitHub ↗

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.

  1. User

    你好

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

  1. 01Console input
  2. 02Messages history
  3. 03JSON / HTTP
  4. 04Agnes API
  5. 05Parse + display
ARCHITECTURE

ARCHITECTURE

KEEP EXPLORING

Related content

  1. 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.

    15 MINPublished
  2. 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.

    16 MINPublished
  3. 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.

    12 MINPublished
  4. LAB / 005

    L1 / Context position: an interrupted trial

    Can the model retrieve the same fact at different positions?

    INCONCLUSIVE
  5. 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.

    16 MINPublished
  6. 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.

    10 MINPublished
  7. 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.

    11 MINPublished
  8. LAB / 011

    A1 / The chat-history commit boundary

    How should committed history survive failures, truncation and candidate trimming?

    Completed
  9. LAB / 010

    TypeScript / Output boundary comparison

    Which invalid inputs escape assertions and object validation?

    Completed
  10. 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.

    10 MINPublished
  11. 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.

    8 MINPublished
  12. 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.

    8 MINPublished
  13. 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.

    8 MINPublished
  14. 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.

    8 MINPublished
  15. 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.

    8 MINPublished
  16. 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.

    8 MINPublished
  17. 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.

    Completed
  18. LAB / 014

    A2 / Concurrent history commits

    Reproduce reversed response order with real Java threads, then enforce versioned commits, complete turns and bounded receipts.

    Completed
  19. LAB / 001

    Retrieval quality comparison

    Use fixed questions and documents; compare retrieval hits, citations and answer correctness with and without retrieval.

    Running
  20. LAB / 002

    Tool failure recovery experiment

    Use controlled read-only tools; inject timeouts and empty results, then record completion and call counts.

    Running
  21. 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.

    9 MINPublished
  22. 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.

    9 MINPublished
  23. 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.

    Completed
  24. 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.

    11 MINPublished
  25. 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.

    Completed
  26. 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.

    10 MINPublished
  27. 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.

    Completed
  28. 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.

    10 MINPublished
  29. 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.

    Completed
  30. 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.

    11 MINPublished
  31. 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.

    Completed
  32. 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.

    11 MINPublished
  33. 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.

    Completed
  34. 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.

    12 MINPublished
  35. 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.

    Completed
  36. 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.

    9 MINPublished
  37. Engineering cases

    Java retries: three timeouts are not one deadline

    Seven local HTTP conditions separate retryability, Retry-After, attempt limits and elapsed-time budgets.

    9 MINPublished
  38. 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.

    9 MINPublished
  39. Mechanisms

    Profiling KV reuse: saved work versus added overhead

    Profile 909 queries across signatures, lookup, copying and continuation, including the remaining slowdown.

    9 MINPublished
  40. 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.

    9 MINPublished
  41. 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.

    9 MINPublished
  42. 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.

    11 MINPublished
  43. 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.

    10 MINPublished
  44. Tutorials

    Durable idempotency: commit identity and result together

    Use a framed journal, process crashes and 99 truncated prefixes to explain durable idempotency.

    10 MINPublished
  45. 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.

    10 MINPublished
  46. Tutorials

    Conversation recovery: reconcile intent, receipt and whole turn

    Halt the JVM at three commit boundaries and rebuild whole-turn history from durable facts.

    10 MINPublished
  47. 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.

    Completed
  48. Mechanisms

    Packed KV groups: what does 4-bit actually save?

    Store real nibbles and audit group-scale overhead, padding bytes and attention output error.

    10 MINPublished
  49. 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.

    10 MINPublished
  50. Mechanisms

    Block KV decoding: less workspace, more time

    Separate cache payload, work arrays and observed runtime, retaining 810 timings including slower block decoding.

    10 MINPublished
  51. 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.

    Completed

← Back to index