Pion — a Redis-compatible key-value store in Mojo¶
Pion is a key-value store that speaks the Redis protocol: one small Mojo
binary that Redis clients such as redis-cli and redis-py talk to unmodified.
Every write goes to a write-ahead log before it is acknowledged, --maxmemory
with Redis's eviction policies makes it a cache, and the same server does vector
search over the RediSearch FT.* commands and keeps a prompt cache for mlx-lm.
The prompt cache, on Apple Silicon, is four lines around mlx_lm:
from pion_vllm_mlx import PionPromptCache
pc = PionPromptCache(model, host="127.0.0.1", port=1974) # once per loaded model
cache = pc.get_or_prefill(prefix_ids, namespace="app|v1|llama-1b|system_v1") # MISS: prefill once + store · HIT: fetch
text = generate(model, tok, prompt=suffix_ids, prompt_cache=cache) # decode as usual, at native speed
| Time to first token, Apple Silicon: Llama-3.2-1B-4bit, 2,049-token prefix, 16-token question | first token | vs cold |
|---|---|---|
| Cold prefill, vanilla mlx-lm | 1,193 ms | |
| mlx-lm's own prompt-cache file, read by a fresh process (67 MB) | 37.0 ms | 32× |
| Pion, same process | 46.2 ms | 26× |
| Pion, from a separate process, over the wire | 69.0 ms | 17× |
Pion, from a separate process on the same machine (V.EXPORT) |
37.0 ms | 32× |
The Pion rows differ only by where the cache comes from: the first is the
process that computed it, the others read what a separate process wrote, and
that reproduces the vanilla output at BLEU 1.000. Both come from
cross_process_ttft.py
(--same adds the first); the file row from
file_cache_ttft.py, timed the
same way. On the same machine Pion matches the file: a separate process
maps the prefix as a file Pion wrote (V.EXPORT), 37.0 ms; over TCP it is
69.0 ms. If one program reuses one fixed prefix, mlx-lm's save_prompt_cache /
load_prompt_cache is the simpler tool. Pion is for what a file
does not do: a cache every process reads over one wire, crash-consistent, and
through pion-vllm-mlx serve a longest-prefix match that a
restarted agent or a second session finds by itself.
Read the limits before installing: it caches prefill, not decode, and it
only pays off when a long prefix is really reused.
What works¶
Three things, each covered by Pion's gate tier, the tests run before every merge:
- A Redis-compatible KV store with a write-ahead log. Command matrix for every Redis-compatible command and its known divergences, Persistence, Data types.
- A prompt cache for mlx-lm, and one endpoint for coding agents.
Shared KV cache (namespaces, Stage 1 vs Stage 2, the
wire protocol, what is measured) and Coding agents
(
pion-vllm-mlx servebehind Claude Code, Codex and OpenAI clients). - Vector search and the semantic cache. Vector engine,
Embeddings, and
AI.SEMANTIC_CACHEin the AI gateway page.
Two properties are Pion's own: an acked write is still there after SIGKILL,
and the cache is read directly by a different program over a protocol every
language already has a client for. It is not an inference engine: it feeds
forward passes, it does not run them.
Experimental¶
Everything else is experimental: in the tree, tested as far as each page
says, with no published measurement of what it buys and no user outside this
project, so it may change or be removed. Each such page opens with an
Experimental banner: the rest of the AI gateway
(AI.COMPLETE, AI.CHAT, AI.FLARE.*), Distributed
systems and Multi-tenant. The README's
Experimental table lists
each part and what tests it.
Where to start¶
- Reference: Configuration for profiles;
Networking for the event-loop tiers and the binary lane on
port+1; Client APIs. - Operations: Running in production for crash breadcrumbs, the status file, supervised serving and the durability of every type.
- Internals: Architecture, Memory management, Vector engine.
- Licensing:
licensing.md. Pion is Apache-2.0, with one free closed binary library (libpion_vector) for the tuned vector kernels.