---
id: 18645
lang: en
title: "RWKV-7 Stitches Document Caches in 0.65–1.55 ms per Document, but Loses Early Documents"
published_at: "2026-11-29 18:25:29"
source_name: "Хабр: Машинное обучение"
source_url: "https://habr.com/ru/articles/1113782/?utm_campaign=1113782&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/18645"
categories: ["llm", "research"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# RWKV-7 Stitches Document Caches in 0.65–1.55 ms per Document, but Loses Early Documents

> **Краткая суть (BLUF):** In RAG, a model re-reads the relevant documents from scratch on every query. RWKV-7 compresses what it has read into a fixed-size state, so these states can be computed in advance and stitched together in 0.65–1.55 ms per document (on a MacBook M4 Air). In a multi-layer network, though, the stitching is approximate: early documents get lost, and building the cache adds 6–19% to reading time. So cache frequently used documents and check the answers against a regular full pass.  - On 7.2B, full composition is closer to the reference than the diagonal variant in 10 out of 10 cells - Two tokens of text prefix cut the state error by 3–4x - The size of the state error is almost unrelated to harm to the answer

Imagine a RAG system: thousands of documents, and for each query the user wants context assembled from several of them. A transformer re-reads the selected texts every time, and that costs tokens and time. The recurrent model RWKV-7 works differently: it "reads" a document and compresses it into a fixed-size state, a kind of summary. The idea follows: compute such a summary for each document in advance, then stitch them together in the needed order without running the texts through the model again. Stitching takes 0.65–1.55 milliseconds per document (measured on a MacBook M4 Air), while building the cache itself costs roughly 6–19% more than an ordinary reading of the document. An independent researcher checked how closely the stitched summary matches the result of ordinary sequential reading, on RWKV-7 checkpoints from 0.4B to 7.2B. The results are mixed.

## What exactly gets stitched

For each document, two things are cached: the state it produced, and the linear transformation it applies to any incoming state. Two documents are combined as a "state plus transformation" pair without re-running the text. For a single layer, this is exact algebra: the divergence from a continuous pass is no more than 2.4e-15 in fp64 and about 8e-7 in fp32 on the 7.2B model. The idea itself is not new; it has relatives such as PICASO/CASO and Priming. What is new here is that the rule was verified across all layers of real models.

In a multi-layer network, the algebra stops being exact. The inputs of the upper layers depend on all the preceding context, while the document cache was built separately. Imagine summarizing a book chapter in advance without knowing what came before: the summary will come out slightly different from one written while reading straight through. The author measured how large this gap is, using synthetic fact retrieval and tasks of picking the correct answer among candidates on SQuAD, HotpotQA, and the Russian-language SberQuAD.

## What the measurements showed

Full composition is noticeably better than the simplified variants. On 7.2B it is closer to the continuous pass than the variant with diagonal transitions, across all ten cells of the independent check. Simply adding states together ("soup") loses to it in all five multi-document checks, by 1.22–4.80 units of log-probability, and the gap grows with the number of documents: addition does not account for how later documents change the meaning of earlier ones. If the answer lies in the first document, stitching beats the state from the last document alone, where the answer simply is not present, by 3.4–4.8 units (checkpoints 1.5B and 2.9B).

There are weak spots too. Early documents get lost, and this repeats on every checkpoint tested. With later documents, the outcome depends on the model: on 2.9B and 7.2B the sign of the effect differs, and the author explicitly writes that this is a difference between checkpoints, not a scaling law. One of the pre-registered predictions, a shift between 2.9B and 7.2B, was not confirmed. Such candor raises confidence in the remaining results.

Two practical observations. First: it is better to build a document cache after a text prefix rather than from scratch. Even two prefix tokens reduce the state error roughly 3–4x in the synthetic task. Plain line breaks do not help: for distant targets they can increase the error 2–6x relative to a text prefix. Second: the magnitude of the state error barely predicts whether the answer will suffer. The correlation between the error norm and harm to the answer is close to zero, so the metric "state is close to the reference" cannot replace testing on real questions.

## What it costs and what to do about it

The stitching itself is cheap, but the cache is not free: building it costs 1.06–1.19 times an ordinary reading of the document. This pays off only if documents are reused in different combinations. For one-off queries there is no benefit.

Keep the limitations in mind. Timing was measured on a Mac, not on CUDA for 7.2B. The independent replication is built on three seeds. Results for a short warm-up before each cached document come from a single seed and remain exploratory: the author calls the method promising, but not confirmed. Finally, the checkpoints are different models, not one training run with different parameter counts.

Takeaway for developers: if you are building RAG or agents on recurrent models, precomputing document caches is practical, and full composition is clearly better than summing states. But do not expect an exact reproduction of ordinary reading. Cache the documents that are used often, build the cache with a meaningful text prefix, and compare the answers against a continuous pass on your own data. The author's code is on GitHub in the state-composition repository.

---
- **Первоисточник:** [Хабр: Машинное обучение](https://habr.com/ru/articles/1113782/?utm_campaign=1113782&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18645
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
