KV cache

The KV cache keeps the conversations a worker has already read, so the next message only reads what's new and the reply starts sooner. The reply itself is the same. It's on by default.

How it works

Every request sends the whole conversation. The worker reuses the part it's seen before and reads only the new part, so a long chat stays quick however long it gets.

Reused from the cache Read fresh
Turn 1 6,200 read 0% reused
Turn 2 6,700 reused 98% reused
Turn 3 7,300 reused 98% reused
  • With several workers, Pendra sends a conversation's follow-ups back to the worker that has it cached. You don't change anything in your code.
  • Images earlier in a conversation are reused like the text around them.

Choose a setting

Open a worker in the console, then Settings, and set KV cache. It applies to the next request. Owners and operators can change it.

SettingKeeps conversations inBest for
Memory + NVMe (default)The GPU, system memory and disk. Survives restarts.Prompts that share a long opening, such as a big system prompt or a document, and workers that switch between models.
MemoryThe GPU and system memory only.Chat, on a worker where nothing may be written to disk.
OffNothing.One-off requests, embeddings and batch jobs.

Workers that Pendra runs start on Memory, so nothing from your prompts is written to a disk Pendra runs. GPUs you rent start on Memory + NVMe, like your own workers.

System memory

When a conversation leaves the GPU, the worker saves a copy in system memory, so bringing it back takes a fraction of a second. The RAM cache setting decides how much memory it may use. Automatic uses up to half, or 80% on workers Pendra runs, and gives memory back when other programs need it.

On disk

  • The worker caps the cache at a fifth of the drive, up to 250 GB, and drops the least recently used copies first. You can set your own cap in the console.
  • Put it on a fast SSD with PENDRA_KV_CACHE_DIR. See Configuration.
  • In Docker, mount a volume so the cache survives a new container. See Docker.
  • Copies unused for 24 hours are removed. Switching away from Memory + NVMe deletes them all.

Put what changes at the end

The cache matches your prompt from the start and stops at the first difference. A timestamp or request id at the top of your system prompt means the whole conversation is read again, every turn:

Turn 3 12:04 7,420 read 0% reused

Keep the system prompt, tools and earlier messages the same, and put anything that changes in the latest user message. When this happens, the worker's log says reuse lost to an early divergence.

See what it saves

Open a worker in the console and choose the Cache breakdown tab, next to Memory & storage. Reused counts the tokens served from the cache instead of being read again, since the worker last started.

LocationHoldingReusedSurvives
Warm context (reserved context) 2.1 GB 1.2M tok Lost on restart
System RAM (saved conversations) 6.4 GB of 24 GB 3.8M tok 412 of 530 lookups found something · 78% A model swap and idle unload
NVMe (on disk) 18 GB of 190 GB 2.6M tok 96 of 140 lookups found something · 69% A restart

The Memory & storage tab shows how much memory the cache is holding, so you can see whether it's worth the room.

Conversation memory density

This setting, under the worker's Settings, decides how much memory each conversation takes on the GPU. It applies even with the cache off.

  • Automatic (default) uses Compact when it gives a model at least a quarter more context on an NVIDIA GPU, and Standard otherwise.
  • Compact fits about twice as much conversation. Answers are just as good, but replies late in a long conversation are slower, by up to a third after about 50,000 tokens.
  • Standard gives the fastest replies.

Switching makes copies already saved on disk unusable, so each prompt is read once more before the cache helps again.

End-to-end encryption

Requests sent with end-to-end encryption are never written to disk, whatever the setting. They still get the speed-up from memory.