Lembas: Solving the Long-Video RAG Efficiency Problem with Token Allocation

Lembas reframes video RAG as a token allocation problem, using water-filling to balance accuracy and compute.
The Lembas framework addresses the overlooked token budget allocation problem in long-video retrieval-augmented generation by modeling video RAG as a shared-budget token allocation problem between frames and captions. Its core insight is that token marginal value diminishes within a single video item and further diminishes when similar evidence receives more tokens; both effects are unified into one objective function and solved with a provably convergent iterative water-filling algorithm. The framework is plug-and-play and not tied to any specific VLM or retriever. Experiments show up to 7.2 percentage point accuracy gains at comparable compute, and in multi-turn video understanding, up to 1.5 percentage point accuracy improvement with 1.7–17.3× TFLOPs reduction. Multi-turn dialogue reuses previous-round tokens and leverages VLM attention to refine relevance at zero additional cost.
Long-video understanding has always been a tough nut to crack in the multimodal field. Vision-language models (VLMs) have limited context windows, while a video lasting tens of minutes can easily produce hundreds of thousands of frames and dense captions—stuffing all of that into a model is neither realistic nor economical. Existing video retrieval-augmented generation (video RAG) approaches typically take one of two paths: frame selection or token compression. But both paths overlook a key question—how much is each additional token actually worth?
The Blind Spot of Existing Methods: Subtraction Without Valuing
The traditional video RAG approach is to first retrieve relevant segments, then compress visual tokens, and finally feed them into the VLM. Frame selection determines which frames to look at, and token compression determines how much information to retain—the two are often optimized independently. The problem is that when similar evidence is repeatedly retained, the marginal value of additional tokens drops sharply; and since information density varies enormously across different frames and captions, a one-size-fits-all budget allocation inevitably leads to waste.

The Lembas framework proposed in the paper breaks out of this mold, reframing video RAG as a token allocation problem between frames and captions, solved under a shared budget. This shift in perspective is the core insight of the entire work.
Video RAG (Retrieval-Augmented Generation for Video) is a framework that extends the retrieval-augmented generation (RAG) paradigm to the video modality. Its typical pipeline is: first retrieve relevant segments or frames from a long video based on the user query, then encode or compress this visual content, and finally feed the compressed visual tokens along with the text query into a vision-language model (VLM) to generate an answer. Unlike text RAG, the core challenge facing video RAG is the explosion in the number of visual tokens—the frame sequence of a video can produce hundreds of thousands of tokens after passing through a visual encoder, far exceeding the model's context window, making the post-retrieval compression step particularly critical. Existing approaches mostly optimize the two subproblems—frame selection (deciding which frames to retrieve) and token compression (deciding how much visual information to retain)—separately, but the budget coupling between the two is often overlooked.
Core Insight: The Dual Effect of Diminishing Token Value
Lembas starts from two empirical principles. First, within a single video item, the marginal value of tokens diminishes as their number increases—the benefit of viewing one more frame is far smaller than that of the first frame. Second, when similar evidence has already received a large number of tokens, directing more resources toward the same type of content yields even lower returns. These two effects compound, meaning the optimal strategy is neither equal allocation nor greedily selecting the most relevant frames, but rather directing each unit of budget to wherever the current marginal value is highest.
The research team unifies these two diminishing effects into a single objective function and solves it with an iterative water-filling algorithm. The intuition behind water-filling is simple: budget behaves like water, preferentially filling the high-value "depressions" until the marginal returns across all locations tend toward equilibrium. The paper emphasizes that the algorithm has provable convergence guarantees, which in practical deployment means stability and predictability.
Iterative water-filling originates from the classical power allocation method in information theory. Its basic idea is to allocate a limited resource (here, the token budget) across multiple channels (here, evidence items such as frames or captions) so that total return is maximized when the marginal returns on each channel are equal. Because different channels have differently shaped "value curves" that interact with one another, an iterative approach is typically used to gradually adjust the allocation: each round moves resources from the location with the lowest marginal value to the location with the highest marginal value, until convergence. In underwater communications, this is akin to pouring water into a pond with an uneven bottom—the water surface eventually levels out; in token allocation, it means the budget naturally flows toward evidence items with higher information density that are not yet saturated. The algorithm has provable convergence under convex optimization conditions, making it suitable for practical systems that require stable inference overhead.
The Free Lunch of Multi-Turn Dialogue
Multi-turn video dialogue is another easily overlooked scenario. When the user asks follow-up questions, re-retrieving and re-compressing each round causes computational overhead to accumulate rapidly. Lembas's approach is to reuse tokens already processed in previous rounds, leveraging the VLM's own attention mechanism to refine relevance at no additional cost. This is equivalent to crystallizing the visual computation from historical rounds and performing only lightweight attention reordering when needed.
From an engineering perspective, this design is very appealing for real products: multi-turn interaction is the norm in video question answering, and token reuse directly lowers the average inference cost per round.
TFLOPs (trillions of floating-point operations) is a common unit for measuring the computational cost of model inference or training. 1 TFLOPs means executing one trillion floating-point operations per second (or per task). In video understanding scenarios, because large numbers of frames and visual tokens must be processed, computational overhead often becomes a deployment bottleneck. The paper reports that Lembas achieves a 1.7× to 17.3× reduction in TFLOPs for multi-turn video understanding, meaning that the required compute drops substantially while achieving equal or even better task performance. This metric reflects algorithmic-level efficiency improvements better than latency or memory footprint alone, because it directly corresponds to the computational workload executed by the hardware, is independent of specific hardware models, and facilitates cross-platform comparison.
Measured Performance: Accuracy and Compute Improve Together
At comparable compute, Lembas achieves up to a 7.2 percentage point accuracy improvement over current state-of-the-art baselines. In multi-turn video understanding scenarios, it achieves up to a 1.5 percentage point accuracy improvement while reducing TFLOPs by 1.7× to 17.3×. The significance of these numbers is that they break the ingrained expectation that "higher accuracy necessarily costs more"—through smarter budget allocation, both dimensions can improve simultaneously.
You may not have noticed that Lembas is designed as a plug-and-play framework that is not tied to any specific VLM or retriever architecture. This means it can be layered onto existing video RAG pipelines without requiring a complete rebuild.
Implications for Video RAG Engineering
The value of Lembas goes beyond a single algorithm. It suggests a more general optimization approach: in retrieval-augmented systems, what to retrieve and how much budget to allocate are two coupled problems, and optimizing them separately leaves a lot of gains on the table. When the context budget becomes a hard constraint, modeling RAG as a resource allocation problem may be more effective than simply improving retrieval accuracy.
For teams building long-video question-answering products, the token allocation perspective offers a practical tuning lever: rather than agonizing over more complex frame sampling strategies, it's better to first examine whether the budget is being uniformly wasted on low-value content.
(This article is based on the paper abstract; please refer to the original paper for implementation details and experimental setup.)
Related articles

Running Local AI Agents on Mac: A Full Breakdown of the MLX Four-Layer Stack
A breakdown of Apple engineer Joanna's local Mac AI agent solution: the MLX four-layer stack, a three-step setup, and how the neural network accelerator, continuous batching, and distributed inference solve local agent performance bottlenecks.
52KB Engine Runs 2B LLM in a Browser Tab
52KB Engine Runs 2B LLM in a Browser Tab
A 52KB WebAssembly engine on Hacker News claims to run Qwen3.5-2B in a browser tab. We analyze the engine-model separation, browser inference pros and cons, and the on-device AI runtime race.

MIT PhD Takes You from Scratch to Build DeepSeek: A 25-Hour Hardcore Course
MIT PhD Raj Dandekar launches a 25+ hour Bilibili course building DeepSeek from scratch—MoE, MLA, GRPO, hand-written code plus math derivations, aiming to reproduce mini R1.