Memory & RAG
~9 min readUpdated: December 2026

CARVE: Cache-Fused RAG with Chunk-Pair KV Repair & 62x Faster TTFT

CARVE Entity-Linked Planner and Position-Aware KV Scaling Architecture in vLLM

CARVE (arXiv:2612.01288, Fudan University) solves the accuracy vs. time-to-first-token (TTFT) trade-off in cache-fused RAG serving on vLLM. By replacing scattered token-level recomputation with query-conditioned chunk-pair repair (Entity-Linked Planner) and scaling reused VALUE vectors by chunk-to-prefix length ratio (Position-Aware KV Scaling), CARVE eliminates semantic fragmentation and distractor leakage—improving F1 by +4.1 points over CacheBlend while delivering 8.71–62.31x faster TTFT than full-prompt prefill.

Technical Review: Smoke Monkey Core Architecture Team
Tested on Node.js 18+ & BunTypeScript 5.x
Quick Answer & Executive Definition

CARVE: Cache-Fused RAG with Chunk-Pair KV Repair & 62x Faster TTFT: CARVE (arXiv:2612.01288, Fudan University) solves the accuracy vs. time-to-first-token (TTFT) trade-off in cache-fused RAG serving on vLLM. By replacing scattered token-level recomputation with query-conditioned chunk-pair repair (Entity-Linked Planner) and scaling reused VALUE vectors by chunk-to-prefix length ratio (Position-Aware KV Scaling), CARVE eliminates semantic fragmentation and distractor leakage—improving F1 by +4.1 points over CacheBlend while delivering 8.71–62.31x faster TTFT than full-prompt prefill. Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.

Key Architectural Takeaways
Quick Implementation Examplecarve-rag-agent.ts
carve-rag-agent.tstypescript
import { createAgent } from '@smoke-monkey/harness';
// Query a low-TTFT CARVE-enabled vLLM RAG serving cluster from Smoke Monkey Harness
const ragAgent = createAgent({
agentId: 'carve-low-ttft-rag-agent',
provider: 'openai-compatible',
model: 'Qwen/Qwen2.5-32B-Instruct',
baseUrl: 'http://127.0.0.1:8000/v1',
workspacePath: process.cwd(),
permissions: {
read_file: 'allow',
write_file: 'allow',
run_command: 'ask',
},
mcpServers: {
filesystem: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', process.cwd()],
},
},
});
async function runMultiHopRetrieval() {
const result = await ragAgent.run(
'Index ./docs/knowledge-base into the entity-chunk graph with spaCy en_core_web_sm, pre-warm isolated chunk KV caches, and run multi-hop QA benchmarks.'
);
console.log('CARVE RAG pipeline complete:', result.summary);
}
runMultiHopRetrieval().catch(console.error);
Video Guides

Watch: Related Video Guides

How KV Cache Speeds Up LLMs for Faster AI Models on GPUs

What is Prompt Caching? Optimize LLM Latency with AI Transformers

Why Stitched KV Caches & Token-Level Repair Fail on Multi-Hop RAG

Stitched-cache systems (like PromptCache and TurboRAG) prefill knowledge-base chunks independently offline and concatenate their KV caches at query time—omitting cross-chunk attention needed for multi-hop reasoning. Token-level selective recomputation (such as CacheBlend) tries to fix this by recomputing scattered token positions, creating two failure modes quantified in CARVE (arXiv:2612.01288):

  • Semantic Fragmentation: Recomputing isolated tokens leaves coherent supporting spans half-repaired. On HotpotQA, repairing the complete supporting context raised F1 from 19.7 to 34.7—10.4 points higher than token-level recomputation at the same budget.
  • Distractor Leakage: On 28.7% of HotpotQA questions (86/300), incorrect answers matched phrases inside un-recomputed chunks because isolated prefill over-weights within-chunk VALUE vectors relative to full-prompt prefill.
CARVE Ablation Step (HotpotQA, Mistral-7B)Measured F1 / TTFTMechanism Contribution
Stitched-Cache Baseline (Isolated Prefill)38.11 F1Omits cross-chunk attention edges
+ Chunk-Pair Cross-Chunk Repair40.35 F1Entity-Linked Planner preserves coherent spans
+ Position-Aware KV Scaling (V-only)45.24 F1Attenuates isolated-prefill distractor bias
+ Confidence-Aware Relaxation (Full CARVE)`48.47 F1 (+10.36)`Relaxes scaling when chunk activation confidence is low
+ Chunk Reordering + Dual Pipelines1.085 s -> 0.760 s (`-30.0%`)Cuts downstream FFN cost & hides CPU->GPU KV transfer

Entity-Linked Planner, Position-Aware V-Scaling & Chunk Reordering

CARVE operates on chunk pairs (where tokens inside a chunk share >0.95 cosine attention-profile similarity) using three lightweight primitives built into vLLM 0.8.5 (~5.5K LOC, ~1.4K vLLM prefill modifications):

  1. Entity-Linked Planner: Builds an offline bipartite entity–chunk graph using spaCy en_core_web_sm. At request time, IDF-weighted entity overlap achieves 79.5% Hit@1 / 92.5% Hit@3 on query-to-chunk relevance and 43.3% Recall@1 / 76.8% Recall@3 on cross-chunk repair partner discovery.
  2. Position-Aware KV Scaling: Scales only reused VALUE vectors by the chunk-to-prefix length ratio ρ_i = |C_i| / sum_{b<=i} |C_b| (leaving KEY vectors untouched so attention logits stay intact), modulated by activation confidence.
  3. Chunk Reordering: Swaps activated chunks behind their repair partners so multiple edges share one downstream FFN target. On Qwen2.5-32B (HotpotQA), varying repair budget b from 1 to 8 blew up un-reordered TTFT from ~2 s to 44 s, while CARVE’s reordering held TTFT flat at 2.28–2.44 s.

Scale VALUE Vectors Only—Never Scale KEY Vectors

CARVE scales reused V vectors (v′ = ρ_i * v) while leaving K vectors unscaled. Scaling K alters pre-softmax QK^T attention logits and distorts routing across chunks, whereas scaling V cleanly dampens residual distractor contribution.

Reproducible Entity-Chunk Graph & Position-Aware KV Scaling Prototype

You can prototype CARVE’s offline entity–chunk graph builder and position-aware V scaling factor calculation before deploying the vLLM 0.8.5 + xFormers prefill patch.

bash
# Install spaCy entity extraction & vLLM runtime dependencies
pip install spacy vllm==0.8.5 torch==2.6.0
python -m spacy download en_core_web_sm
python
import spacy

nlp = spacy.load("en_core_web_sm")

def compute_position_aware_v_scale(chunk_lengths: list[int], repaired_indices: set[int]) -> dict[int, float]:
    """Compute CARVE chunk-to-prefix length ratios rho_i for reused (non-repaired) chunks."""
    scales = {}
    prefix_tokens = 0
    for idx, length in enumerate(chunk_lengths):
        prefix_tokens += length
        if idx not in repaired_indices:
            scales[idx] = length / prefix_tokens  # Scale only VALUE vectors of reused chunks
    return scales

print("Example V-scales across 5 chunks:", compute_position_aware_v_scale([256, 256, 256, 256, 256], {1, 3}))
Google Search Questions & Answers

Frequently Asked Questions

Q:How fast is CARVE compared to full-prompt prefill and CacheBlend?

Across 3 datasets and 5 models (15 combinations), CARVE achieved an 8.71–62.31x TTFT speedup over full-prompt prefill and improved average F1 by +4.1 points over CacheBlend at a comparable recomputation ratio.

Q:What is distractor leakage in cache-fused RAG systems?

Because isolated chunk prefill normalizes softmax attention over a single chunk instead of the full prefix, reused VALUE vectors retain inflated attention weights and distract generation—causing 28.7% of HotpotQA failures in token-level repair baselines.

Q:How does chunk reordering keep TTFT constant as repair budget grows?

Placing activated query-side chunks after their repair source chunks makes multiple repair edges share one downstream target chunk, cutting redundant FFN recomputations and keeping Qwen2.5-32B TTFT at 2.28–2.44s instead of 44s.

Q:Does CARVE require storing the entire knowledge-base KV cache in GPU VRAM?

No. CARVE stores offline isolated KV caches in CPU memory and overlaps layer-i GPU compute with layer-(i+1) CUDA async CPU-to-GPU transfers to hide PCIe latency and minimize VRAM staging.

Q:How does CARVE integrate with Smoke Monkey Harness RAG agents?

Smoke Monkey Harness connects to a CARVE-patched vLLM OpenAI-compatible endpoint over baseUrl while keeping MCP filesystem and code-verification tools local, cutting multi-hop repository/docs RAG latency without sacrificing accuracy.

Related Alternatives & Comparisons

Related Architecture Guides

View all guides

Build with Smoke Monkey Harness

Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.

npm install smoke-monkey-harness