Manuscript Offprint

arXiv:2611.06498

Signed but Steerable: Measuring and Closing the Text-Vector Integrity Gap in Offline Retrieval-Augmented Generation

Georgios Feretzakis, Alexandros Papaspyridis

Abstract

Offline retrieval-augmented generation (RAG) on edge devices is updated through signed knowledge packs that carry text and precomputed embedding vectors. A signature proves who published a pack, not that its vectors encode its text. We study this text-vector integrity gap. A verifier that recomputes vectors and accepts them within a cosine tolerance concedes a predictable share of queries to an attacker who controls the vectors: the hijack rate equals the distribution of angular retrieval margins at the tolerance (the margin law). Margins are small in five corpora and two embedding models, so an idealised tolerance at the level of floating-point noise leaves up to 5.5% of queries exposed (at most 1.2% in any corpus once exact duplicate documents are excluded), and a threshold calibrated from our CPU INT8-FP32 comparison of a small embedding model (at the empirical 0.1% quantile of honest cosines) leaves 98–100% exposed; on a Raspberry Pi 5 running a local language model, such an attack lowers correct answers from 0.75 to 0.39. Integrity audits of compressed vector stores fare no better: on a FAISS product-quantisation index over 57,638 documents, tampered vectors that all pass the audit put the attacker's document first for 25% of targets. Verifying quantisation codes instead, with ambiguity decided by the verifier, a calibrated guard band and canonicalisation, accepted every honest vector in our samples on three platforms and left the publisher no choice. We also show that common floating-point and dynamic-INT8 inference pipelines are not bit-reproducible across batch sizes or architectures, and report pre-registered negative results on abstention, context pruning and semantic screening. We release code and data.

Keywords: retrieval-augmented generation, embedding integrity, vector databases, product quantisation, determinism, edge AI, supply-chain security

1 Introduction

Retrieval-augmented generation (RAG) lets a language model answer from a local corpus [2], and small quantised models now make fully offline RAG feasible on embedded boards [1, 13]. In disconnected deployments, such as field, industrial and defence settings, knowledge reaches the device through update packages. Our earlier work proposed signed, versioned knowledge packs for this purpose and evaluated them on a Raspberry Pi 5 [16]. It also left an open problem: a validly signed but poisoned pack passed every pack check.

This paper studies a sharper version of that problem. A knowledge pack typically ships text together with precomputed embedding vectors, because computing embeddings on a small device is slow; in our earlier study, embedding a 950-passage pack on the Pi's CPU took about 29 minutes [16]. The signature then covers the vectors, but nothing guarantees that the vectors encode the text. An attacker who controls the publishing pipeline, or an insider, can ship benign text with vectors chosen to steer retrieval. The same gap exists in any vector database: what is stored is a vector, often compressed, and audits compare stored vectors with recomputed ones under some tolerance. Embedding weaknesses are recognised as a top risk for LLM applications [17], and per-embedding signatures have been proposed as a defence [18]. We ask what such checks actually guarantee, and how to make them sound.

We address four research questions with experiments on a Raspberry Pi 5 running a local Qwen2.5-3B model, a desktop for scale, and an Apple M2 laptop as a third platform:

  • RQ1. If a verifier accepts shipped vectors within a cosine tolerance of recomputed ones, how many queries can an attacker hijack, and can this be predicted without running attacks?

  • RQ2. How exposed are the compressed storage formats of vector databases to the same attack?

  • RQ3. Can exact verification close the gap across heterogeneous hardware, and what does it require?

  • RQ4. What does verification cost on the CPU of an edge device that also runs the language model, and what happens end to end?

Our contributions are:

  1. The margin law (Sect. 3): for an optimal attacker, the hijack rate under tolerance τ\tau equals the empirical distribution of angular retrieval margins at arccos τ\tau. It matches attack simulation exactly and lets an operator measure exposure without attacking. On all answerable SQuAD 2.0 questions and four BEIR test sets (five corpora) with two embedding models, margins are small, so even float-noise tolerances leave measurable exposure, and a threshold calibrated from our CPU INT8-FP32 comparison leaves 98–100% of queries exposed (Sect. 5.1).

  2. Exposure of compressed vector stores (Sect. 5.2): tolerance-based audits against SQ8, SQ4, PQ and binary storage leave 2–15%, 55–89%, about 100% and 100% of queries exposed. On real FAISS indexes, an executed attack on product quantisation passes the tolerance check for every tampered vector and puts the attacker's document first for 25% of targets; code-level verification blocks all of them.

  3. Exact code-level verification (Sect. 5.3): comparing quantisation codes, with ambiguity decided only by the verifier, a guard band calibrated to measured float noise and a verify-and-canonicalise rule, accepted every honest vector in our samples on three platforms and four compute backends, without special hardware. We also show that floating-point and dynamic-INT8 pipelines are not bit-reproducible across batch sizes or architectures.

  4. Measured on-device cost and end-to-end impact (Sects. 5.4 and 5.5): verification on the device's CPU costs the concurrently running LLM 23–31% of its decoding speed, the attack lowers the device's correct answers from 0.75 to 0.39 under the INT8 reference threshold, and layered pack verification rejects all twelve structural update attacks we tested.

  5. Pre-registered negative results (Sect. 5.6) on abstention, context pruning and semantic screening, and an open release of code, data and the protocol with its deviation log.

References (42)