Back to Feed
Efficiency & Inference / Multimodal

Optimizing RAG Serving with Visual Caching

Original: QV-PIC: Query-Aware Visual Position-Independent Caching for Efficient RAG Serving

Listen to the summary

Uses a voice available on your device

Audio options
On this page 5 sections
Related concepts 3 concepts

Key Takeaways

  • QV-PIC reduces time to first token (TTFT) by 83.8 percent compared to full prefill operations.
  • The method uses template-conditioned compilation to achieve F1 scores of 48.8, 52.1, and 51.7 for different content types and resolutions.
  • System efficiency relies on managing trade-offs between resolution-based token counts and the quality of textual information capture.
  • Performance is validated across a range of multi-hop and long-context question-answering tasks including LongBench and 2WikiMQA.

Summary & Methodology Analysis

QV-PIC improves retrieval-augmented generation (RAG) by optimizing how the system processes retrieved text chunks rendered as images. By applying template-conditioned compilation, the method reduces cache mismatches that occur when the model's native chat-template prefix is baked into pre-computed keys and values. During serving, the system uses a frozen BGE-M3 encoder to compute cosine similarity between the query and cached document chunks, allowing for the selective activation of high-resolution caches based on relevance thresholds rather than processing all data at the highest fidelity. This selective approach mitigates the token inflation associated with high-resolution visual processing while maintaining semantic alignment. The architecture was evaluated using several models, including Glyph 9B, GLM-4.1V-9B-Thinking, and LLaVA-OneVision-2-8B-Instruct. Performance metrics indicate that relative to full prefill, the system cuts TTFT by 83.8 percent. Furthermore, template-conditioned compilation achieves F1 scores of 48.8 and 52.1 for 72-DPI and 120-DPI rendered images, alongside a score of 51.7 for text. The approach shows that increasing DPI does not guarantee quality improvement, as additional visual detail can sometimes preserve or even reduce F1 scores. A significant limitation is that existing PIC repair methods cannot reconstruct characters, digits, punctuation, or layout cues lost during visual encoding. This is particularly problematic for rendered images where answer-bearing information depends on fine-grained textual details rather than coarse visual semantics. While higher resolution preserves more detail, it sharply increases token counts, which erodes the efficiency gains intended by the compression method.

Interactive System Flowchart

Click diagram to expand and zoom

Illustrative Implementation

A short sketch of the paper's core idea, not the authors' own code.

# Illustrative sketch (not from the paper)
import torch
from transformers import AutoModel, AutoTokenizer

def compile_cache(text, model, tokenizer, tmpl):
    low, high = render_images(text)
    prompt = tmpl + text
    ids = tokenizer(prompt, return_tensors="pt")["input_ids"]
    with torch.no_grad():
        kv = model(input_ids=ids, use_cache=True).past_key_values
    kv = strip_prefix(kv, len(tokenizer(tmpl)["input_ids"]))
    return {"low_kv": kv, "high_kv": kv, "embed": embed(text), "tokens": ids.shape[1]}

def serve(query, caches, model, tokenizer, alpha, B):
    q_emb = embed(query)
    sims = [torch.nn.functional.cosine_similarity(q_emb, c["embed"], dim=0) for c in caches]
    ranked = sorted(zip(caches, sims), key=lambda x: x[1], reverse=True)
    sel, cum = [], 0.0
    for c, s in ranked:
        if cum >= alpha or len(sel) >= B:
            break
        sel.append(c)
        cum += max(s.item(), 0.0)
    active = [c["high_kv"] if c in sel else c["low_kv"] for c in caches]
    assembled = assemble(active)
    q_ids = tokenizer(query, return_tensors="pt")["input_ids"]
    out = model(input_ids=q_ids, past_key_values=assembled)
    return tokenizer.decode(out.logits.argmax(-1)[0])

def render_images(t): pass

def strip_prefix(kv, n): return kv

def embed(t): return torch.randn(768)

def assemble(kv_list): return kv_list

Cross-Examination & FAQs

A deeper dive clarifying mechanics, constraints, and baseline evaluations.

Q1. What is the primary benefit of using QV-PIC?

The primary benefit is an 83.8 percent reduction in time to first token (TTFT) compared to performing a full prefill.

Q2. Does higher resolution always improve retrieval quality?

No. The paper notes that increasing DPI does not guarantee quality improvement and can sometimes result in preserving or reducing F1 scores.

Q3. What types of tasks was this system tested on?

The system was evaluated on tasks from LongBench, including 2WikiMQA, HotpotQA, MuSiQue, MultiFieldQA-en, NarrativeQA, and TriviaQA.

Q4. What models were used for this research?

The authors used Glyph 9B as the primary model, alongside GLM-4.1V-9B-Thinking and LLaVA-OneVision-2-8B-Instruct.

Q5. What is the limitation of PIC regarding text reconstruction?

Existing PIC repair methods cannot reconstruct characters, digits, punctuation, or layout cues that were lost during the initial visual encoding process.

Q6. Why is the loss of fine-grained detail specifically harmful?

This is problematic for rendered images because the information needed to answer questions often resides in fine-grained textual details rather than coarse visual semantics.

Q7. How does resolution impact system efficiency?

While high resolution preserves richer textual details, it significantly increases the number of tokens, which reduces the efficiency gains provided by visual-text compression.

Q8. What specific encoder is utilized by QV-PIC?

QV-PIC uses a frozen BGE-M3 encoder for embedding tasks.

Q9. How do 2WikiMQA, HotpotQA, and MuSiQue contribute to the evaluation?

These datasets are used to evaluate multi-document and multi-hop evidence aggregation capabilities.

Flag an issue

What is wrong with this summary?

What is wrong?