Retrieving Stream Functions, Not Velocities: Mass-Conserving Retrieval for Flow Reconstruction

Reconstructing a fluid's velocity field from camera images of tracer particles is badly underdetermined. Many different flows explain the same pair of frames. The standard way to narrow the choice is to require incompressibility (the velocity $\mathbf{u}$ must satisfy $\nabla\cdot\mathbf{u}=0$, so fluid is never created or destroyed), and the strongest learned methods build this constraint into a single trained network. Retrieval-augmented generation offers a different kind of help. In this approach a model looks up relevant examples in an external database at prediction time and conditions on them, so its knowledge can be extended or swapped without retraining. We propose bringing retrieval to flow reconstruction: given particle images, fetch similar simulated flows from a library and let a network blend them into the answer. The new regime-specific knowledge then sits in a database that can be edited, not in the network's weights.

The obvious way to do this breaks the physics. Retrieval systems mix neighbors with weights that change across space, through attention or learned blending. A spatially varying mix of mass-conserving velocity fields is generally not mass-conserving. Our core proposal is to retrieve and blend stream functions, scalar potentials whose spatial derivatives give a velocity that conserves mass automatically. Any spatially varying blend of stream functions, plus any learned correction, still yields an exactly divergence-free flow. No projection step or penalty is needed. The question we test is whether this lets a reconstruction model adapt to a flow regime it was never trained on, by adding simulations of that regime to the database, as well as or better than fine-tuning the model on those same simulations.

Core Claim

Divergence is linear, so a fixed-weight average of incompressible fields stays incompressible. The trouble comes from the spatially varying weights $w_k(\mathbf{x})$ that retrieval conditioning produces. For retrieved velocities $\mathbf{u}_k$ with $\nabla\cdot\mathbf{u}_k=0$,

$$\nabla\cdot\Big(\sum_k w_k\,\mathbf{u}_k\Big)=\sum_k \nabla w_k\cdot\mathbf{u}_k \neq 0,$$

so mass is created wherever the blending weights change along the flow direction. In 2D, write the stream function as $\psi$, with velocity $\mathbf{u}=\nabla^\perp\psi=(\partial_y\psi,-\partial_x\psi)$. We instead predict

$$\mathbf{u}(\mathbf{x})=\nabla^\perp\Big(\sum_{k=1}^{K} w_k(\mathbf{x})\,\psi_k(\mathbf{x}) + r(\mathbf{x})\Big),$$

where $\psi_k$ are the stream functions of the $K$ retrieved exemplars and $w_k$ and $r$ are outputs of a network that sees the particle images and the exemplars. The result is divergence-free for any $w_k$ and $r$, because the divergence of $\nabla^\perp$ of any smooth scalar is identically zero.

Solid walls fit in the same way. If every library exemplar is stored with $\psi$ normalized to zero on the wall, then every blend is also zero on the wall, and the no-penetration condition holds by construction. This addresses the missing boundary awareness noted for projection-based correctors.

The research file frames the open problem (Gap 2) as "linear combinations do not preserve the constraint." That framing is imprecise. Constant-weight combinations are safe; spatially varying conditioning is what breaks the constraint, and moving the blend into potential space removes the problem rather than patching it afterwards.

Relation to Prior Work

Two lines of work supply the ingredients.

On the fluid side, PIVNO treats velocimetry as a mapping from images to velocity functions. It uses global attention and adds divergence-free fine-tuning as a soft, self-supervised penalty. Learning to Estimate and Refine Fluid Motion with Physical Dynamics pairs an unsupervised predictor with a corrector modeled on Chorin's projection, which forces predictions back to zero divergence in one step. Both are purely parametric: everything the model knows about flow regimes lives in its weights. Neither can be given a new regime without gradient updates. Our method borrows the hard-constraint idea from inherently divergence-free representations (vector splines, divergence-free wavelets, divergence-free kernels). Those methods use fixed analytic bases. We use the stream functions of retrieved simulations as a basis chosen per query.

On the retrieval side, Retrieval-Augmented Diffusion Models condition an image generator on nearest neighbors through cross-attention. They show the database can be swapped at test time, for example ImageNet for WikiArt, to change domain without retraining. That swap property is exactly what we want for flow regimes. RANF brings retrieval to coordinate-based neural fields under extreme measurement sparsity: it averages neighbors and predicts a residual. It reduced interaural time difference error from 28.6 to 20.5 μs with three measurements and kept high-frequency spectral detail that plain neural fields smooth away. This is the closest template for our design. RANF's outputs, however, are unconstrained scalars, and its permutation-invariant averaging applied to velocities would create spurious mass sources.

These retrieval works motivate the idea. U-NIAH constrains it: hallucinations rose by over 355% when retrieved context was more than 97% noise. Irrelevant neighbors can actively hurt, so our design has to make poor exemplars cheap to ignore.

The file also suggests using divergence residuals as a trigger for when to retrieve (Gap 4). Under our hard constraint the divergence residual is always zero, so it cannot signal anything. We would instead gate exemplars on photometric misfit, meaning how badly an exemplar's flow fails to warp the first frame onto the second. This is the physically grounded analogue of the hallucination detector in RaDIO.

Research Program

The system has four parts.

First, a library of simulated 2D snapshots, each stored as a stream function with walls normalized to $\psi=0`. We would build it from the canonical regimes of the synthetic PIV benchmarks: backward-facing step, flow past a cylinder, turbulence from direct numerical simulation, and surface quasi-geostrophic sea-surface flow.

Second, a retrieval key. A cheap first-pass flow estimate from cross-correlation is encoded into a small embedding, and the top $K$ snapshots are returned. Each match is allowed a translation, rotation, or rescaling; all three keep it a valid stream function.

Third, the blending network. We reuse a PIVNO-style backbone with global attention over the images and the retrieved stream functions. It outputs blending weights, with a "null" slot so that all exemplars can be ignored, plus a residual stream function $r$.

Fourth, training. The network is trained with supervised loss on synthetic pairs, followed by the same self-supervised photometric fine-tuning PIVNO uses on real data.

The central protocol is leave-one-regime-out. The network is trained with one regime absent from both its training pairs and its library. At test time, simulations of that regime, distinct from the test pairs, are added to the library with no gradient steps. A second experiment tests spectral fidelity on turbulence. The question is whether retrieved high-frequency structure counters the over-smoothing that physics losses cause in PI-NeRF. That work needed a separate pretrained density-to-velocity network to restore vorticity, and retrieval could take over that role.

A 3D extension using vector potentials ($\mathbf{u}=\nabla\times\mathbf{A}$) on ScalarFlow is a stretch goal and not part of the core claim. In 3D, enforcing walls through the potential is subtler because the potential has gauge freedom.

Baselines

The naive reference point is classical window-based cross-correlation followed by a Chorin projection. It shows how much any learned component adds, and it fixes the error scale on each regime.

The strongest existing learned method is PIVNO, which reports an average endpoint error (AEE, the mean distance between predicted and true velocity vectors) of 0.8 on Cylinder flow and 1.9 on Backstep. PIV-RAFT, as reported in the same paper, scored 1.4 and 1.6. Our in-distribution target is to match these numbers within noise. Our model should not lose accuracy on regimes it was trained on simply because it relies on retrieval. We would retrain PIVNO under our leave-one-regime-out splits with the same backbone size, data, and tuning budget, since no held-out-regime numbers are reported. On the DNS turbulence and SQG regimes we found no reported AEE on Lacuna for PIVNO, so those numbers will be produced by our own runs.

The fairest competitor, and the one most likely to win, is PIVNO fine-tuned on exactly the simulations we add to the library, given the same simulation budget and a matched number of fine-tuning steps. Retrieval beats it if it matches fine-tuned AEE on the held-out regime with zero gradient steps. It also beats it if it keeps accuracy on the original regimes while the fine-tuned model degrades on them.

Two ablations isolate the key ingredients. The first blends retrieved velocities with the same network and then applies a Chorin projection afterward; this tests whether potential-space blending matters, or whether projecting after the fact is good enough. The second is the same stream-function network with the library removed, so only the residual $r$ is predicted; this separates the benefit of the hard constraint from the benefit of retrieval. We also include a nonparametric-only baseline: average the retrieved stream functions with weights based on photometric misfit, and use no network. This tells us whether the learned blender earns its place. The Consensus ADMM refinement in Particle Image Velocimetry Refinement via Consensus ADMM reports a 20% error reduction at 60 Hz. No reported AEE on these benchmarks was found on Lacuna, so we would run it as an optional post-processor on every method.

Why not just…?

Why not just fine-tune the parametric operator on the new regime's simulations? This is the real threat. If fine-tuning on 50 snapshots recovers held-out-regime accuracy and does not hurt the old regimes, the swap-the-database argument loses most of its practical value. The matched fine-tuning baseline settles it directly. If fine-tuning matches retrieval on the held-out regime and also keeps the original regimes intact, we would narrow the claim to editing knowledge without gradient steps and the auditability of predictions. We would not claim an accuracy advantage.

Why not just blend velocities and project afterward, as the Chorin-style corrector does? Projection removes the divergence that spatially varying blending creates. It does so by solving a global pressure problem that can redistribute exactly the fine vortex structure retrieval was meant to supply. It also has no explicit wall handling, a limitation noted for Learning to Estimate and Refine Fluid Motion with Physical Dynamics. The velocity-blend-plus-projection ablation measures this. If its AEE and high-wavenumber energy match the potential-space version, the potential-space design is just a tidier implementation, and we would report it that way.

Why not just optimize a physics-informed field per scene, which needs no library? PI-NeRF reports up to 64 hours of training per complex scene. Without an auxiliary learned prior, its physics losses push flows toward overly smooth, laminar solutions. Both problems are what retrieval targets. We include it only on a small subset of turbulence frames for the spectral comparison, because its cost rules out full benchmark runs.

Why not just retrieve and average, with no network? If the library holds a near-duplicate of the test flow, nearest-neighbor averaging may be enough. The nonparametric-only baseline tests this. We expect it to fail when the test flow is a new combination of familiar structures, for example a cylinder wake at an unseen Reynolds number.

Decisive Experiments

The first check is leave-one-regime-out AEE. Each regime is held out in turn, and we compare four conditions: our model with the regime's simulations added to the library, PIVNO with no adaptation, PIVNO fine-tuned on the same simulations, and the velocity-blend-plus-projection ablation. We report mean divergence magnitude alongside AEE. Our model should sit at numerical zero; PIVNO's soft penalty will not.

The second check is the kinetic-energy spectrum on DNS turbulence, comparing energy at high wavenumbers against ground truth. This tests whether retrieval preserves small-scale vortices that the physics-constrained baselines smooth away.

The third check is a stress test of physical noise. We corrupt the library with flows at mismatched Reynolds numbers or wrong geometry at increasing ratios, echoing U-NIAH's noise sweep, and plot AEE against the corruption ratio. With the null slot and misfit gating, performance should degrade gracefully toward the no-library ablation and never fall below it. Falling below it would mean retrieval is harmful under realistic database quality.

Finally, on the real-world sequences (foam and confetti tracers in shallow-water flow past a cylinder, and the jet flows), where no ground truth exists, we report photometric warping error and whether the expected wake structure appears. We treat these results as supporting evidence only.