RAID: Retrieval-Augmented Anomaly Detection

Mingxiu Cai, Zhe Zhang, Gaochang Wu, Tianyou Chai, Xiatian Zhu

TL;DR

RAID reinterprets Unsupervised Anomaly Detection (UAD) through the lens of Retrieval-Augmented Generation (RAG). By combining a coarse-to-fine hierarchical vector database with a guided Mixture-of-Experts (MoE) denoising filter, RAID drastically reduces retrieval noise and achieves state-of-the-art anomaly localization across full-shot, few-shot, and multi-dataset settings.

What Problem Does This Paper Address?

In industrial quality inspection, finding anomalies without labeled defective training data is a classic Unsupervised Anomaly Detection (UAD) problem. Standard approaches typically compare a test image against a "memory bank" of normal templates or try to reconstruct the image using generative models, flagging discrepancies as anomalies.

However, these methods face a fundamental bottleneck: matching noise. Because of subtle intra-class variations, lighting changes, or imperfect alignments, directly matching a query image to normal templates introduces false positives (hallucinated noise) and misses subtle defects. The authors argue that existing methods focus too heavily on the retrieval aspect while neglecting the generative reasoning needed to clean up the comparison.

Methods

RAID solves this by fully embracing the RAG paradigm, splitting the task into an efficient Retrieval Stage and a noise-resilient Generation Stage.

Figure 2. Overview of our RAID, which reinterprets UAD within a RAG paradigm. (a) In the retrieval stage, a hierarchical vector database is constructed, indexing tokenized templates into three sequential entity levels: class prototype, semantic prototype, and instance token. This structure allows efficient retrieval flow queried by input tokens. (b) In the generation stage, an anomaly cost volume is built by matching each input token with its retrieved template tokens. A guided MoE filter then dynamically refines this cost volume under the dual guidance of the retrieved semantic prototypes and the input tokens.
  1. Hierarchical Vector Database (Retrieval): Instead of searching through a massive, flat memory bank of patch embeddings—which is computationally expensive and noisy—RAID organizes normal templates into a three-level hierarchy:
  2. Class Prototypes: Global category-level clusters to quickly identify the object type.
  3. Semantic Prototypes: Clustered patch tokens that capture recurring intra-class patterns (like textures or backgrounds).
  4. Instance Tokens: The raw patch embeddings preserving fine-grained visual details. This coarse-to-fine flow allows query tokens to quickly pinpoint contextually relevant normal patches.

  5. Filtering-based Generation Reasoning (Generation): Once the top-$K$ normal instance tokens are retrieved, RAID computes a compact 3D anomaly cost volume. To strip away matching noise, this volume is passed through a Guided Mixture-of-Experts (MoE) filter. The filter utilizes dual guidance—combining the raw input query tokens with the retrieved semantic prototypes—to dynamically route data through specialized denoising experts, producing a clean, sharp anomaly map.

Datasets

The authors evaluated RAID on four widely recognized industrial anomaly detection benchmarks:

  • MVTec-AD: 15 categories (10 objects, 5 textures) with high-resolution images.
  • VisA: 12 object subsets featuring complex surface and structural anomalies.
  • MPDD: Metallic parts under challenging backgrounds and illumination.
  • BTAD: 3 industrial categories featuring real-world industrial variability.

Key Insights and Ideas

  • UAD as a RAG Problem: The core conceptual leap is treating anomaly map generation as a reasoning process over retrieved context. Instead of treating retrieval and comparison as separate, static steps, the generation network explicitly learns how to "denoise" the comparison based on the retrieved context.
  • The Power of Hierarchy: Moving away from flat memory banks doesn't just save compute; it actively filters out out-of-context matches. RAID achieves a 5× reduction in per-image latency compared to flat retrieval schemes while maintaining near-identical accuracy.
  • Dual-Guidance Denoising: By feeding both the query image and the abstract semantic prototypes into the MoE router, the model gains a global understanding of what the object should look like, allowing individual experts to focus on refining fine-grained local boundaries.

Key Results

RAID demonstrates exceptional performance and versatility across multiple evaluation setups:

  • Full-Shot Multi-Class UAD: When trained on all normal data within a dataset using a single unified model, RAID achieves state-of-the-art results. On MVTec-AD, it reaches 99.4% Image-AUROC and 98.6% Pixel-AUROC, outperforming competitive baselines like GLAD and AnomalyDINO.
Figure 3. Qualitative comparison of multi-class anomaly localiza- tion results on MVTec-AD and VisA datasets.
  • Few-Shot Generalization: When evaluated on unseen categories with only 1, 2, or 4 normal reference images, RAID consistently outperforms other few-shot methods (such as DFM and Win-CLIP) without requiring any target-domain fine-tuning. For instance, in a 1-shot setup on MVTec-AD, RAID achieves 95.1% Image-AUROC.
  • Multi-Dataset Scalability: When all four benchmarks are merged into a single massive training corpus, RAID shows virtually no performance degradation, proving its robustness against highly complex and diverse data distributions.

Limitations and Future Work

While the paper demonstrates excellent empirical results and a massive speedup over flat retrieval methods, a dedicated limitations section is not explicitly detailed. However, the authors note in their conclusion that the current framework is purely visual. They envision extending this RAG-based anomaly detection paradigm into agentic and cross-modal settings (e.g., incorporating text or multi-modal foundation models) to create more explainable and data-efficient industrial intelligence systems.

Summary updated

BibTeX
@inproceedings{cai2026raid,
  author = {Mingxiu Cai and Zhe Zhang and Gaochang Wu and Tianyou Chai and Xiatian Zhu},
  title = {{RAID: Retrieval-Augmented Anomaly Detection}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=zMx96q8icU},
}
Figure