Robust Implementation of Retrieval-Augmented Generation on Edge-based Computing-in-Memory Architectures

Ruiyang Qin, Zheyu Yan, Dewen Zeng, Zhenge Jia, Dancheng Liu, Jianbo Liu, Zhi Zheng, Ningyuan Cao, Kai Ni, Jinjun Xiong, Yiyu Shi

Introduction

Deploying Large Language Models (LLMs) on edge devices—such as smartphones and IoT gateways—presents a significant challenge in balancing personalization with computational efficiency. While users demand context-aware, personalized responses, traditional fine-tuning methods are prohibitively expensive for edge hardware, often requiring dozens of hours for even modest datasets. Retrieval-Augmented Generation (RAG) offers a more efficient alternative by allowing models to query local document repositories. However, RAG faces its own bottlenecks at the edge: high latency during Maximum Inner Product Search (MIPS) on standard mobile CPUs and the inherent hardware noise of emerging high-speed architectures.

This paper introduces RoCR (Robust CiM-backed RAG), a framework developed by researchers from the University of Notre Dame and the University at Buffalo. RoCR leverages Computing-in-Memory (CiM) architectures to accelerate RAG while overcoming the reliability issues associated with analog memory devices.

The RoCR Framework: Software-Hardware Co-design

Computing-in-Memory (CiM) architectures, utilizing Non-Volatile Memory (NVM) devices like RRAM or FeFET, can perform MIPS searches in under 50ms by executing calculations directly within the memory chips. However, these devices are susceptible to "noise"—device-to-device variations and temporal fluctuations that corrupt data and degrade retrieval accuracy. RoCR addresses this through a three-stage optimization framework designed to make RAG inherently "CiM-friendly."

1. Noise-Aware Contrastive Learning

Instead of utilizing standard embeddings, RoCR employs contrastive learning with a triplet loss function. This approach trains the embedding model to maximize the distance between a query and irrelevant documents while minimizing the distance to relevant ones. By creating a semantic "buffer zone," the framework ensures that hardware noise is less likely to flip search results, maintaining high retrieval precision despite physical imperfections.

2. Novel Data Construction (CDE & CDI)

To facilitate effective training, RoCR introduces two data construction methods:

  • Contrastive Data with Explicit Labels (CDE): For labeled datasets, the framework concatenates labels to text to create distinct anchor/positive pairs.
  • Contrastive Data with Implicit Labels (CDI): For unlabeled data, RoCR uses a high dropout rate (0.9) to create "corrupted" versions of documents. These serve as negative examples, effectively simulating the semantic fragmentation caused by CiM noise during the training phase.

3. Flexible Noise Injection

During the training of the embedding model, RoCR injects simulated Gaussian noise that mirrors the specific physical variations of RRAM and FeFET devices. This ensures that the resulting embeddings are robust to the specific hardware non-idealities they will encounter during deployment.

Experimental Evaluation

The framework was evaluated across five diverse datasets covering classification and text generation tasks: Citation Identification, Movie Tagging (15-class), Product Rating (5-class), News Headline Generation, and the large-scale DBLP-Citation-network. To demonstrate versatility, RoCR was tested with several edge-friendly LLMs, including Gemma-2B, Phi-2, Mistral-7B, and Llama-2-3B.

Key Results and Insights

RoCR demonstrates that high-performance RAG is achievable on noisy edge hardware without the need for expensive, noise-free components. Key findings include:

  • Significant Accuracy Gains: RoCR improved RAG performance on various CiM devices by up to 35% compared to vanilla implementations.
  • MIPS Robustness: The framework achieved over 90% MIPS accuracy in many scenarios—matching the performance of noise-free digital computers—whereas standard baselines often dropped below 50% accuracy under identical noise conditions.
  • Zero Inference Overhead: Because RoCR is a training-time optimization, it provides these robustness benefits without adding any energy or latency overhead during actual inference.
  • Scalability: By offloading the MIPS search to CiM, the primary bottleneck shifts from search latency to memory capacity, allowing edge devices to support much larger local knowledge bases.

Conclusion and Future Work

RoCR represents a significant step toward private, high-speed, and personalized AI on edge devices. By utilizing a software-hardware co-design approach, the framework mitigates the physical limitations of analog memory through noise-aware training. While current results are based on high-fidelity simulations of RRAM and FeFET devices, future work will focus on testing the system on custom-fabricated RoCR chips and addressing spatial variations and long-term device aging. Additionally, exploring how RoCR scales with higher embedding dimensions and varying bit-precisions will further refine its application in complex edge computing environments.

Summary updated

BibTeX
@inproceedings{qin2024robust,
  author = {Ruiyang Qin and Zheyu Yan and Dewen Zeng and Zhenge Jia and Dancheng Liu and Jianbo Liu and Zhi Zheng and Ningyuan Cao and Kai Ni and Jinjun Xiong and Yiyu Shi},
  title = {{Robust Implementation of Retrieval-Augmented Generation on Edge-based Computing-in-Memory Architectures}},
  booktitle = {ICCAD},
  year = {2024},
}
Figure