Abstract
Efficient long-video understanding requires identifying relevant evidence while minimizing the tokens processed by vision-language models (VLMs). Existing video retrieval-augmented generation (RAG) methods rely on frame selection and token compression, but overlook how much each additional token is worth. We introduce Lembas, a plug-and-play framework that formulates video RAG as a token allocation problem over frames and subtitles under a shared budget. Our key insight is that the value of a token diminishes within each item and decreases further as similar evidence receives more tokens. Lembas captures both effects in a single objective and solves it with an efficient iterative water-filling algorithm that has a provable convergence guarantee. For multi-turn conversations, Lembas reuses the tokens processed in earlier turns and refines relevance with the VLM’s attention at no extra cost. Our evaluations show that Lembas improves accuracy by up to 7.2 percentage points over state-of-the-art baselines at comparable compute. On multi-turn video understanding, Lembas achieves up to 1.5 percentage points higher accuracy with 1.7–17.3× fewer TFLOPs.
01 · Motivation
From frame selection to token allocation
A VLM’s vision encoder turns each video frame into a sequence of visual tokens, whose number is the frame’s full token count, and inference cost grows with the number of tokens in the context. Processing every frame of a long video can easily exceed the VLM’s context window and incur prohibitive inference cost. Video RAG addresses this by retrieving the frames and subtitles most relevant to the query. Conventional Top-K retrieval keeps the K highest-scoring frames but processes every selected frame at its full token count, so it cannot trade unnecessary detail in one frame for useful evidence from another.
Lembas lifts the problem from frame selection to token allocation: it decides how many tokens each frame and subtitle receives under a shared token budget, a cap on the total number of evidence tokens passed to the VLM. Two observations motivate the design. First, tokens exhibit diminishing returns: once a frame preserves sufficient detail, additional tokens yield progressively smaller accuracy gains. Second, token value depends on the other allocated evidence: a frame contributes less new information when similar frames already receive tokens.
Lembas is plug-and-play. Given the candidate frames and subtitles of an existing RAG system and their relevance scores, it allocates the token budget across them and prunes each item to its allocated token count before VLM inference. To prune a frame to b_i tokens, Lembas keeps its b_i highest-ranked visual tokens. The tokens of a frame are ranked once, offline and independently of the query, by the attention they receive in the last layer of the vision encoder.






Fig. 2 of the paper. Varying the tokens per frame allows Lembas to retain evidence from more frames within a shared budget. In the Lembas view, percentages give the share of each frame’s tokens retained, read off the figure’s 8×4 grid.
02 · Formulation
The allocation objective
Let r_i(q) \ge 0 denote the retrieval relevance of candidate frame i, out of N, to query q, derived for example from the cosine similarity between the embeddings of the query and the frame. Top-K retrieval is an integer linear program over binary selections x_i:
Its optimum selects the K highest-scoring frames, each at its full token count. Lembas replaces the binary selection with a token count: it allocates b_i \in [0, b_i^{\max}] tokens to every candidate frame i \in \mathcal F and subtitle segment i \in \mathcal S under a shared budget B, where b_i^{\max} is the full token count of item i:
Here v_i(b_i) \in [0,1], which is v_{\text{frame}} for a frame and v_{\text{text}} for a subtitle, models the value retained when item i is represented by b_i tokens, r_i(q,\mathbf b) is its relevance given both the query and the evidence allocated elsewhere, and \beta balances subtitles against frames.
- Token value function. Retrieval relevance estimates an item’s usefulness when it is fully represented, not how much of it survives token pruning. We measure QA accuracy as a function of the per-frame token count on held-out validation sets and find that a saturating rational function, v(b) = b/(b+\tau), fits best among the candidate functions, for both modalities. The parameters are fitted offline by least squares: \tau_{\text{frame}} = 38 and \tau_{\text{text}} = 13.6.
- Diversity-aware relevance. Nearby frames often depict nearly identical content, so we discount each item’s retrieval relevance by the token value already allocated to similar items: r_i(q,\mathbf b) = r_i(q) - \eta\sum_j s_{ij}\,v_j(b_j), where the sum runs over the items j of the same modality as i, s_{ij} is the cosine similarity between their embeddings, and \eta \ge 0 controls the redundancy penalty.
03 · Solver
Iterative water-filling
The solver has two parts. Water-filling allocates the budget when the relevance of every item is fixed. Iterative water-filling repeats it, because the diversity term changes the relevance of an item as similar items receive tokens. Allocating integer token counts is NP-hard, so we optimize a continuous relaxation, in which token counts may be fractional, and round its solution down to whole tokens. In terms of the token values z_i = v_i(b_i), the relaxation maximizes a concave function over a convex set.
Water-filling. With the relevance of each item fixed to \bar r_i, its retrieval relevance (scaled by \beta for subtitles), the objective is a sum of concave terms under a single budget: each additional token of an item yields a smaller gain than the previous one. At the optimum, all partially allocated items therefore share the same marginal gain per token \lambda, the Lagrange multiplier of the budget constraint. Otherwise, moving a token from an item with a lower marginal gain to one with a higher marginal gain would improve the objective. Setting the marginal gain of item i, \bar r_i\tau_i/(b_i+\tau_i)^2, to \lambda gives b_i = \big[\sqrt{\bar r_i\tau_i/\lambda} - \tau_i\big]_0^{b_i^{\max}}. Here \tau_i is the token value parameter of the item’s modality, and the brackets clip the token count to [0, b_i^{\max}]. An item receives tokens only if its relevance exceeds the threshold \lambda\tau_i, and its token count grows with the square root of its relevance rather than in proportion to it. Bisection on \lambda finds the value at which the allocation meets the budget B.
Iterative water-filling. In terms of the token values, the objective reads J(\mathbf z) = \bar{\mathbf r}^{\top}\mathbf z - \eta\,\mathbf z^{\top}\mathbf S\mathbf z, where \mathbf S is the block-diagonal matrix of within-modality similarities s_{ij} (scaled by \beta for subtitles). \mathbf S is positive semidefinite, so J is concave. With the diversity term, the relevance that water-filling requires depends on the allocation it produces. We resolve this circular dependence with the Frank–Wolfe method, which iteratively maximizes linear approximations of the objective. Each iteration computes the gradient at the current token values \bar{\mathbf z}, which is the diversity-discounted relevance \widetilde{\mathbf r} = \nabla J(\bar{\mathbf z}) = \bar{\mathbf r} - 2\eta\,\mathbf S\bar{\mathbf z}. Maximizing the linear approximation is a water-filling subproblem with \widetilde{\mathbf r} in place of \bar{\mathbf r}. The iteration solves it and averages its token values into \bar{\mathbf z} with step size \gamma_\ell = 2/(\ell+1). The solver converges to the global optimum of the relaxation with an O(1/\ell) objective gap after \ell iterations.
The demo below runs Algorithm 1 of the paper on a synthetic video. Drag the relevance bars, or vary B, \eta and \beta.
A synthetic video with 36 candidate frames and 18 subtitle segments (b^{\max} = 256 and 40 tokens). \tau, the L = 20 iterations and the 60 bisection steps follow the paper; relevance, embeddings and the scale of \eta are synthetic. Top-K takes the highest-scoring frames and Uniform takes evenly spaced frames, as many as fit in the budget, each at its full token count with its aligned subtitle. Water-filling is the first iteration of Algorithm 1, without the diversity term. Relevance is drawn on a square-root scale, on which the height of a bar above the threshold is proportional to its token count, up to b^{\max}. The final allocation is rounded down to whole tokens, so it uses slightly fewer than B tokens.
04 · Multi-turn
Incremental allocation and attention refinement
Multi-turn conversations often revisit the same evidence. Serving systems typically retain the KV cache across turns, which stores the attention keys and values of the tokens the VLM has already processed. A later turn then has to prefill, that is, run the forward pass over, only the tokens that are new to its context. Under token allocation, however, the same item may receive different token counts at different turns, which complicates KV-cache reuse.
Incremental allocation. Let b_i^{(t)} be the token count allocated to item i at turn t, and c_i^{(t-1)} the number of its highest-ranked tokens already in the KV cache. Because token rankings are query-independent, the tokens of an item in the KV cache are always its highest-ranked ones, and a larger allocation extends them. Lembas therefore prefills only the p_i^{(t)} = \max\big(0,\, b_i^{(t)} - c_i^{(t-1)}\big) newly included ranks and updates the cache state to c_i^{(t)} = \max\big(c_i^{(t-1)},\, b_i^{(t)}\big). Evidence prefilled at an earlier turn therefore remains available to later queries, and the budget B applies to the evidence allocated at each turn. Lembas appends the new tokens to the existing context instead of inserting them at earlier positions, which would invalidate subsequent KV-cache entries, because the keys and values of a token depend on all tokens before it. Each token is prefilled at most once, so the cumulative prefill of evidence tokens over a conversation is bounded by \sum_i b_i^{\max}.
Attention refinement. The query must be prefilled in any case, so Lembas prefills q_t over the cached context first and measures the attention a_i^{(t)} from the query tokens to each cached item, normalized per cached token, at no additional inference cost. The relevance of cached items is refined to \hat r_i^{(t)} = \alpha_t\, r_i(q_t)^{1-\omega}\,\big(a_i^{(t)}\big)^{\omega}, where \omega \in [0,1] controls the contribution of attention and \alpha_t preserves the total retrieval relevance of cached items. Uncached items keep r_i(q_t).
A synthetic four-turn conversation over 24 candidate frames, with B = 900 tokens allocated at each turn by the same solver. Each bar is the number of tokens of a frame in the context at that turn, c_i^{(t)}. Tokens prefilled at earlier turns remain in the KV cache, and a turn prefills only the tokens that its allocation b_i^{(t)} adds beyond them. Relevance is synthetic and attention refinement is not simulated. Ablations on MT-Video-Bench are in Table 3 below.
05 · Evaluation
Results at comparable compute
We evaluate on three single-turn, multiple-choice video understanding benchmarks, MLVU, LongVideoBench (LVB) and Video-MME, with two VLM backbones, Qwen3-VL-8B and InternVL3.5-4B. Lembas is applied to embedding-based RAG, which scores frames with SigLIP 2 and subtitles with BGE, and to graph-based RAG built on VideoRAG, which retrieves related evidence through a graph structure. Baselines are uniform sampling, the frame selection methods Top-K and FOCUS, and three methods that adapt token counts: Q-Frame (resolution tiers), QuoTA (relevance-proportional allocation) and AdaAlloc (agentic budget planning), all under the same token budget. Compute is reported in TFLOPs (1012 floating-point operations) and counts prefill across all model calls, including auxiliary frame-scoring and planning calls.
Lembas achieves the highest overall accuracy on all three benchmarks with both backbones. With Qwen3-VL-8B, it improves over Top-K by 2.2, 2.6 and 4.2 points on MLVU, LVB and Video-MME, at 0.9–5.5% higher TFLOPs. QuoTA achieves competitive accuracy and matches Lembas on LVB, but with Qwen3-VL-8B it incurs 2.8–3.4× higher compute due to its VLM-based frame scoring. When integrated with VideoRAG, Lembas improves accuracy by 0.4 and 2.2 points on MLVU and Video-MME, while accuracy decreases by 0.7 points on LVB.
Short <2 min, medium 4–15 min, long 30–60 min. The gains over Top-K are most pronounced on long videos.
Removing subtitle allocation decreases overall accuracy by 3.6 points (7.3 on long videos); in that setting the VLM still receives the subtitles aligned with the selected frames, as the baselines do, and Lembas still outperforms the similarly budgeted, non-agentic frame selection baselines by 0.6–3.6 points. Removing the diversity term reduces accuracy by 0.7 points, and replacing water-filling with proportional allocation by 1.2.
MT-Video-Bench is a multi-turn, open-ended benchmark; responses are scored by an LLM judge against an answer checklist. Against the baselines, Lembas reaches 0.3–1.5 points higher accuracy with 1.7–17.3× fewer TFLOPs (Fig. 8b of the paper): Top-K and FOCUS reuse the KV cache only for frames selected before, Q-Frame and AdaAlloc only for frames at a matching resolution, and QuoTA cannot reuse it. Disabling incremental allocation increases compute from 275 to 687 TFLOPs (2.5×) for a 0.6-point accuracy increase. Removing attention refinement decreases accuracy by 1.1 points and increases prefill compute to 315 TFLOPs.
On synthetic videos with 30 to 3,600 candidate frames, iterative water-filling is 4–23× faster than the integer solver Gurobi and matches its integer optimum to three decimals. The open-source solver SCIP does not finish within 600 s beyond 420 frames. In the full pipeline, similarity search, allocation and token pruning together take tens of milliseconds per query.
Full results table (Table 1)
Cite
@article{barik2026efficient,
title={Efficient Video Retrieval Augmented Generation via Token Allocation},
author={Ayush Barik and Fan Lai and Francis Yan},
journal={arXiv preprint arXiv:2611.32938},
year={2026}
}