THUNDER-AI(7)

Reference index

NAME

thunder-ai — store the inputs, progress, and results of a model run

SYNOPSIS

db.set(key, payload)
stored = db.get(key)
results = db.mget(keys)

DESCRIPTION

A chat application needs the user’s messages when a session reopens. An agent needs its last saved step when a worker restarts. Thunder stores either record as a sequence of bytes. The application chooses a key and uses it to read the record later.

For example, a worker can save its progress as JSON. Once Thunder confirms the write, the journal record is on disk. A second worker with the key can read the JSON and resume work. The application chooses the file format and controls who may read the record.

INPUTS

Retrieval-augmented generation (RAG)
A search index ranks passages. Store the original document in Thunder and put its key and the passage offset in the index. When a search returns a passage, those two fields tell the application which revision to fetch and where to read. The sample source bundle uses the key sources/thunder-docs/v1. Give each later revision its own key.
Chat history
Save the messages in order, together with the conversation summary. The sample conversation fits under sessions/setup-review/v1. When the user reopens the chat, the application reads that key and chooses which messages to send to the model.
Audio, images, and video
A transcription worker can read the original recording from media/run-007/cue. Save its transcript under a second key that identifies the model version. A later model can transcribe the same audio, and the two transcripts can be compared.

STATE AND OUTPUTS

Agent checkpoints
A checkpoint records how far a worker got and what it should do next. The sample checkpoint lists two finished steps, the keys for the source and tool result, and a next step named validate_batch. After Thunder confirms the write, the scheduler can give a replacement worker the key agents/run-007/rev-003. The Python example reads the next step.
Model outputs
One job saves the finished report under results/run-007/report. A publishing job reads that key to get the file. The same handoff works for a tensor if the writer also records its shape and data type.
Saved responses
Reuse a model response only when the caller has access and the saved answer still applies. Build the key from the user or tenant, model revision, prompt, input, retrieved context, and generation settings. A change to any of them gives a different key. If the lookup misses, call the model and save its answer.

EVALUATION

Prompt revisions
Suppose an instruction change causes a classifier to mislabel a ticket. If each result records its input and prompt key, you can read the exact instructions used in that run. Give each prompt revision its own key, such as prompts/support/v3.
Test cases
Save a test input and its expected answer together, for example under evals/support-v2/case-018. Run both model revisions on that case. Keep each answer and its score under its own run ID so the original test stays the same.

BATCH RETRIES

Suppose a classifier stops after labeling two of three support tickets. Its manifest lists the ticket IDs, model revision, and prompt revision for the run. Each label has its own key. On restart, the worker reads the manifest and looks up all three labels. Only ticket 020 still needs a result.

batches/triage-042/manifest
batches/triage-042/results/018    billing
batches/triage-042/results/019    access
batches/triage-042/results/020    (missing)

Save the Python listing below as retry_batch.py in the release-kit directory on the Docker host. It writes two fixed labels, reconnects, then prints the ID of the ticket whose label is missing. The example uses a fresh run ID each time.

python -m pip install thunderstrike
python retry_batch.py
retry_batch.py
import json
from pathlib import Path
from uuid import uuid4

from thunderstrike import Thunderstrike

run = "batches/" + uuid4().hex
ca = Path("docker/tls/ca.crt").read_text()

def connect():
    return Thunderstrike("127.0.0.1:7380",
                         tls_server_name="localhost", tls_ca_pem=ca)

def key(name):
    return f"{run}/{name}".encode()

with connect() as db:
    manifest = {"model": "triage-v2", "prompt": "support-v3",
                "tickets": ["018", "019", "020"]}
    db.set(key("manifest"), json.dumps(manifest).encode())
    db.set(key("results/018"), b"billing")
    db.set(key("results/019"), b"access")

with connect() as db:
    tickets = json.loads(db.get(key("manifest")))["tickets"]
    keys = [key("results/" + ticket) for ticket in tickets]
    values = db.mget(keys)
    missing = [ticket for ticket, value in zip(tickets, values)
               if value is None]
    print("Retry:", ", ".join(missing))

Expected output Retry: 020

Save the run ID with the job so a replacement worker can find it. Start a new run when the inputs or model settings change. Have the scheduler assign one writer per ticket and leave completed results in place. A worker that stops after calling the model but before saving the result may have to make the call again.

For a large batch, divide the manifest into smaller lists and check one list at a time. The example tests for None because Python returns None for a missing key and b"" for a stored empty value.

SEE ALSO