There is a particular kind of project that stops you in your tracks, not because it announces a new capability, but because it reframes an old object you thought you understood. LARQL is one of those projects. It takes a trained transformer — the thing we have collectively agreed to treat as a black box with a chat window stapled to it — and reorganises it into something you can SELECT from, DESCRIBE, INSERT into, and COMPILE back out. The tagline in the repository is blunt: the model is the database. Once you sit with that sentence for a while, a lot of assumptions about how we interact with neural networks start to look like accidents of tooling rather than necessary truths.

This article walks from the theoretical claim underneath LARQL to the practical mechanics of using it. The project is open source, written in Rust, and sits at github.com/chrishayuk/larql.

Part I — The Theory

Where the knowledge actually lives

Start with a small but load-bearing observation about modern transformer architectures. In a gated feed-forward network — the GeGLU variant used by Gemma, the SiLU-gated MLP in Llama, Mistral, Qwen, Phi — each FFN block looks roughly like this:

y = W_down · (SiLU(W_gate · x) ⊙ (W_up · x))

Read the shapes, not the formula. W_gate is a matrix whose rows act as detectors: each row, dotted against the residual stream, scores how strongly a particular pattern is present at this position. W_up lifts the signal into a higher-dimensional feature space. W_down projects it back, and here is the part that matters: each column of W_down is the contribution that one specific feature makes to the residual stream when it fires. If you project that column through the unembedding, you see which tokens it nudges the logits toward.

That framing — rows of W_gate as keys, columns of W_down as values, with the residual stream as the thing being read from and written to — is not new. Anthropic’s interpretability group has been publishing variations on it for years, and transformer-circuits.pub has a deep archive of the mechanistic picture. What LARQL does is take that picture seriously as a data model. If each feature is a (detector, contribution) pair, then the FFN is literally a key-value store indexed by semantic direction. It is not like a database. It is a database — we just usually access it through a matrix multiplication and a softmax.

From interpretability insight to graph database

Once you accept the framing, the graph structure falls out almost for free. Look at what a single high-scoring feature actually encodes when you query it:

  • The gate row points at a region of activation space — effectively, an entity or a context (”France-ish”, “the thing we’ve been talking about is a capital city”).

  • The down column, projected to vocabulary, points at the tokens it promotes — “Paris”, “Berlin”, “capital”.

That is a subject-predicate-object triple, written in vectors instead of IRIs. The entity lives in the embedding space. The relation is whatever semantic direction the gate encodes. The target is whatever the down column emits. If you can identify the relation — by clustering features, by probing them with templated prompts, by matching their outputs against Wikidata — you recover the full triple.

For anyone who has been building knowledge graphs in the SPARQL or property-graph tradition, this is uncanny. The model has been accumulating a graph this whole time. We just did not have a query language for it.

The vindex: a queryable re-layout of the weights

LARQL’s central artefact is the vindex — short for “vector index”. It is not a copy of the model and not a new representation. It is the same weights, stored on disk in a layout that makes four operations cheap: nearest-neighbour lookup over gate rows, token lookup into embeddings, per-feature metadata retrieval, and an mmap’d scan over down projections.

The layout splits a model into a handful of memory-mappable files: gate_vectors.bin (the rows of W_gate per layer, the KNN index), embeddings.bin (the token lookup), down_meta.bin (per-feature decoded output metadata — which tokens each feature promotes and by how much), and some metadata and label files. For Gemma 3 4B, the browse-only vindex is around 3 GB in f16. That is smaller than the original model file, because you only keep what you need for queries — no attention weights, no up-projection, no LM head. Add those back with WITH INFERENCE or WITH ALL and you can run the full forward pass too.

The critical property is that gate_vectors.bin is W_gate. Not a copy, not a derived index — the canonical storage. COMPILE reads it back to produce standard safetensors. Nothing is duplicated. This means round-tripping is lossless by construction, and the on-disk footprint is a deliberate function of which operations you want to support.

Semantic spacetime, incidentally

An aside worth spelling out, because it sharpens the theoretical picture. Mark Burgess’s Semantic Spacetime framework classifies relations into four types — containment, proximity, sequence, and property — and argues that most useful knowledge structures can be reduced to this small typology. When you look at what LARQL actually discovers in the knowledge band of a trained model (roughly the middle third of the layers, layers 14–27 in Gemma 3 4B), the relations cluster into shapes that rhyme with exactly this typology: borders and continent are proximity and containment, capital-of is a property, morphological inflections in the syntax band are sequences. The model, trained on nothing but next-token prediction, has independently organised its knowledge along the same axes that graph theorists have been arguing for on first-principles grounds. You do not need to believe SST is the right ontology to notice that something generic is happening here: when a system has enough capacity and enough data, the structure of the world leaks in, and it leaks in with a shape.

Why this is not SQL, and not SPARQL

LARQL ships a query language called LQL — Lazarus Query Language — that borrows surface syntax from both SQL and SPARQL and serves a different purpose. The verbs are interpretable: EXTRACT decompiles a model into a vindex, DESCRIBE shows what the model believes about an entity, WALK traces which features fire for a prompt, INFER runs the full forward pass, INSERT edits knowledge, COMPILE bakes edits back out into weights. The statement taxonomy in the spec groups them into lifecycle, browse, inference, mutation, patches, introspection, and residual-stream tracing.

What makes LQL different from SQL is that the “rows” are not user data — they are the weights of a trained model, and every operation has a geometric interpretation in a high-dimensional space. What makes it different from SPARQL is that the triples are not symbolic; they are approximate, probabilistic, and layer-dependent. A fact in LARQL is not a flat assertion. It is a feature — a (layer, slot, gate-vector, down-column) tuple — that fires for a family of inputs and promotes a family of outputs. That is a weaker guarantee than RDF gives you and a much stronger one than you get from prompting a chatbot.

Part II — The Practice

Enough theory. Let us put hands on it.

Getting a vindex

There are three ways to obtain a vindex. The fastest is to pull one that has already been extracted from Hugging Face: larql hf download chrishayuk/gemma-3-4b-it-vindex. If you would rather extract one yourself from a Hugging Face model, the command is larql extract-index google/gemma-3-4b-it -o gemma3-4b.vindex --f16. This walks the safetensors files without loading the full model into memory, pulls out the gate, embedding, and down-projection weights, runs the relation-clustering pipeline, and writes the result to disk. If you want inference capability too, add --level inference. If you want to be able to COMPILE back to a full model after editing, use --level all. The third path, larql convert gguf-to-vindex, handles GGUF input by dequantising to f32 during conversion.

For the walkthrough I will assume you have a Gemma 3 4B vindex sitting at gemma3-4b.vindex. Start the REPL:

larql repl

First query: DESCRIBE

The simplest demonstration of the graph model is DESCRIBE:

larql> USE "gemma3-4b.vindex";
Using: gemma3-4b.vindex (34 layers, 348.2K features, relations: 512 types)

larql> DESCRIBE "France";
France
  Edges (L14-27):
    capital     → Paris              1436.9  L27  (probe)
    language    → French               35.2  L24  (probe)
    continent   → Europe               14.4  L25  (probe)
    borders     → Spain                13.3  L18  (probe)

Read what happened. The engine took the embedding of “France”, computed gate scores across every feature in the knowledge band (layers 14–27 for this model), kept the highest-scoring ones, and decoded each one’s down column to find which tokens it promotes. Where the feature’s relation was confirmed by a probe — a templated prompt of the form “The capital of France is ___” that the model completes with “Paris” — the relation label appears next to the edge. Where it was not probed, the edge still exists; it just lacks a human-readable label.

Note the layer numbers. “Paris” fires at layer 27; the continent relation fires at layer 25; borders fire much earlier, at layer 18. This is not noise. Features at different layers encode different kinds of facts, and the layer band is itself meaningful. If you run DESCRIBE "def" SYNTAX, you get Python-shaped features from the early layers — py:function_def near where you would expect a tokeniser-level pattern to live, not where semantic knowledge lives.

WALK versus INFER — the cleanest demonstration of what attention does

One of the most illuminating things you can do in LARQL is compare WALK and INFER on the same prompt. WALK takes the embedding of the final token and asks: which features fire? It is a pure knowledge lookup with no attention, no context routing. INFER runs the full forward pass, including attention, and asks: what token does the model predict?

larql> WALK "The capital of France is" TOP 3;
  1. Is                   — syntactic continuation of "is"
  2. It                   
  3. The                  

larql> INFER "The capital of France is" TOP 3;
  1. Paris                (97.91%)
  2. the                  (0.42%)
  3. a                    (0.31%)

WALK gives you what the model knows about the string “is” — which, unsurprisingly, is mostly syntax. INFER gives you what the model predicts next, because attention has routed the subject “France” to the final position and the FFN at the final position now sees a “France+capital-relation” residual and fires the capital feature. The difference between these two answers is a precise, operational definition of what attention contributes. You can literally watch it happen.

This is not a toy observation. For interpretability work, this distinction — what a token “means” in isolation versus what it becomes in context — has always been tangled up with the mechanics of the forward pass. LARQL makes it a two-line REPL interaction.

Tracing the residual stream

Going a level deeper, TRACE captures the per-layer decomposition of the forward pass, splitting each layer’s contribution into attention delta and FFN delta. The answer-trajectory output for “The capital of France is” tracking “Paris” as the target token is worth staring at:

  Layer   Rank     Prob      Attn       FFN      Who
    L22     50    0.002     +22.2     +34.4   BOTH ↑
    L23     10    0.024     -16.9     +55.9    FFN ↑
    L24      1    0.714    +105.7     +24.4   BOTH ↑  ← phase transition
    L25      1    0.997      +4.3     +94.4    FFN ↑
    L26      1    0.999     +83.1     +18.7   BOTH ↑

Until layer 22, the model has no idea the answer is Paris — it is ranked fiftieth. Between layers 23 and 24 there is a sharp phase transition: attention dumps more than a hundred logits of evidence onto Paris in a single layer, and the FFN confirms. By layer 25 the answer is settled. This is what knowledge retrieval looks like when you instrument it — not a smooth accumulation, but a sudden decisive event at a specific depth.

You can save traces to disk with TRACE ... SAVE "france.trace" and load them from Python via larql.WalkModel. The on-disk format is mmap-friendly, which matters because trace stores compress dramatically compared to KV caches. The repository benchmarks a 370,000-token Apollo 11 transcript stored as boundary residuals in 18.9 MB, versus 56 GB for the equivalent KV cache — a 3,100× ratio. That number deserves its own article, but the punchline is that the residual stream, captured at window boundaries, carries enough state to reconstruct context without keeping the full attention history alive. It is a different approach to infinite context, grounded in the observation that the residual stream is the Markov state.

Editing knowledge without gradient descent

Here is the part that would have seemed like science fiction two years ago. You can insert a new fact into a trained model without fine-tuning, without a GPU, and without touching the original weights:

larql> INSERT INTO EDGES (entity, relation, target)
   ...   VALUES ("John Coyle", "lives-in", "Colchester");
Inserted 1 edge. Feature F8821@L26 allocated.

What is happening underneath is a small piece of geometric surgery. The engine looks up the “lives-in” relation direction from the cluster centres discovered during extraction. It finds the token embedding for “John Coyle” and the token embedding for “Colchester”. It synthesises a new gate vector pointing roughly at the entity embedding, scaled to match the magnitudes of existing gates at layer 26. It synthesises a new down vector pointing at the target embedding. It finds a low-activation feature slot — one that barely fires across any entity — and writes the new vectors into it. In practice, the insert is a multi-layer constellation rather than a single-layer edit: the repo’s validated regime spreads the install across eight layers at alpha=0.25, because single-layer installs do not move the logits enough and larger alphas damage neighbouring facts.

The base vindex files are never modified. Every edit goes into a patch overlay — a lightweight JSON file (.vlp) that sits on top of the immutable base. This is the same pattern as a Git branch, or a Docker image layer, or an OverlayFS mount. You can SAVE PATCH "medical-facts.vlp", ship that file to someone else, and they can APPLY PATCH it to their copy of the same base vindex. A thousand-fact domain patch runs to about 10 MB. Compared to the eight-gigabyte base model, that is roughly 1/800th the size.

When you are ready to bake, COMPILE CURRENT INTO VINDEX "edited.vindex" flattens the patches into a new standalone vindex — and on APFS the untouched weight files are hardlinked rather than copied, which makes the compile nearly instantaneous. COMPILE CURRENT INTO MODEL "edited/" FORMAT safetensors goes further and produces a plain safetensors directory that loads in Hugging Face Transformers with no special loader code. The inserted facts live in the standard down_proj tensors. No runtime bridge, no sidecar, no custom inference path.

This is a practical answer to the knowledge-update problem that has haunted retrieval-augmented generation from the start. RAG keeps facts outside the model because updating the model is expensive. If updating the model costs a few milliseconds and ten kilobytes per fact, the calculus shifts. You can maintain a base model, a set of domain patches that evolve on their own schedules, and compose them at load time the way you compose container images.

Vindexfile — Dockerfile for knowledge

The declarative-build pattern is explicit in LARQL. A Vindexfile reads almost exactly like a Dockerfile:

FROM hf://chrishayuk/gemma-3-4b-it-vindex
PATCH hf://medical-ai/drug-interactions@2.1.0
PATCH ./patches/company-facts.vlp
INSERT ("Acme Corp", "headquarters", "London")
LABELS hf://chrishayuk/gemma-3-4b-it-labels@latest
EXPOSE browse inference

larql build . produces a composed vindex. You can pin patch versions, stack patches from multiple sources, and promote a build through stages. If you have spent any time in the container world, this will feel eerily familiar. The deeper point is that it works — knowledge composition in neural networks turns out to have the same shape as image composition in file systems, because both are fundamentally about diffs over immutable bases.

Serving over the network

larql serve path/to/vindex --port 8080 starts an HTTP server, and a client session can then USE REMOTE "https://models.example.com/larql" to forward read queries over the wire while keeping any local mutations in a client-side patch overlay. This matters for two reasons. First, vindexes are large, and hosting them centrally is operationally cheaper than shipping them to every endpoint. Second, the readonly-base / overlay-patch model composes cleanly across the network boundary — the server serves an immutable base, the client layers its own patches on top, and the two do not need to agree on anything beyond the base vindex identity.

What it actually costs — and where it breaks

The benchmarks in the repository are not hype. Gate KNN per layer runs at around 0.008 ms on the internal benches. A full 34-layer walk completes in about 0.3 ms. Loading a vindex takes around 8 ms thanks to zero-copy mmap. A single mutation — writing new gate-vector and metadata entries — takes 617 nanoseconds. These numbers are on CPU. No GPU in the loop at any point for browse, walk, or edit operations.

Inference on a Gemma 3 4B with attention enabled runs at 517 ms per forward pass on Apple Silicon for the walk-FFN path, versus 535 ms for dense FFN. That the vindex-backed walk path is actually faster than the dense baseline is counterintuitive; the trick is that the walk path only needs about 3.5 GB of model weights in memory (attention plus embeddings) versus 16.6 GB for dense, and the FFN down-projection reads from mmap’d storage with zero-copy BLAS. You trade a small amount of accuracy at some layers for a much smaller resident set.

It would be dishonest to not note the limitations. Dense and full-precision MoE models support every operation, but MXFP4-quantised mixture-of-experts models — GPT-OSS-120B, notably — have noisy DESCRIBE and WALK results because the 4-bit gate-row precision is simply not enough to support stable KNN. The recommended path for those models is to use INFER for knowledge queries. There are also planned but not-yet-landed surfaces around streaming DESCRIBE and tiered trace-save formats. The honest status table in §8.4 of the LQL spec is worth reading if you are planning to build something on top of this.

What This Opens Up

It is tempting to position LARQL as “the SQL moment for neural networks”, and that framing is not wrong, but I think it misses the deeper shift. SQL was not just a query language — it was a compact over what a data system was. It said: data is tables, queries are compositions of a small algebra over tables, and the system will pick the execution strategy. The contract made the ecosystem.

LARQL is proposing an analogous compact for trained transformers: weights are rows, queries are compositions over a small algebra that includes KNN, graph walk, forward pass, and patch overlay, and the system will handle the physical execution — whether that means an mmap’d gate-vector scan, a BLAS-fused attention pass, or a closed-form MEMIT weight update during compile. If that compact sticks, the gap between “the model” and “what the model knows” collapses into something you can actually inspect and edit.

The downstream consequences get interesting fast. Model archaeology — literally diffing what Gemma 2 knows against what Gemma 3 knows, relation by relation — becomes a database query instead of a research project. Knowledge updates become version-controlled patches instead of fine-tuning runs. Agent memory systems — where every assertion an agent accumulates needs to be faithfully queryable, revisable, and sometimes ejectable — get a primitive that is structurally honest: the memory lives where the agent’s knowledge lives, in the weights, not in a vector database bolted on beside.

The code is Apache 2.0. The docs are unusually candid about what is implemented and what is not. Clone it, extract a small model, and run DESCRIBE "France" yourself. The first time you watch a neural network’s knowledge about a place render as a list of labelled graph edges, something clicks that is hard to un-click.


Repository: github.com/chrishayuk/larql · Language: Rust (with Python bindings) · License: Apache-2.0

Originally published on Sovereign Agentic AI on Substack.