Manuscript Offprint
arXiv:2610.22297Private Retrieval Augmented Generation via Random Projection
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
ABSTRACT
Retrieval-Augmented Generation (RAG) enhances the capabilities of large language models (LLMs) by querying external structured knowledge. However, it can also introduce privacy risks by leaking sensitive information from the retrieval datastore. We propose a simple method to preserve datastore privacy in RAG systems via random projection. By applying the same projection to both datastore embeddings and query embeddings, our method provably preserves semantic similarity between queries and retrieved items while substantially mitigating data extraction attacks. Across multiple RAG architectures and datasets, we show that this lightweight approach achieves superior retrieval and generation performance compared to prior methods which leverage formal differential privacy (DP) guarantees, while exhibiting comparable empirical privacy under strong attack models. Our results for the first time suggest that random projection can serve as a competitive and practical baseline for privacy-preserving RAG systems.
1 Introduction
Retrieval-Augmented Generation (RAG) [1, 2] enhances large language models (LLMs) by incorporating information retrieved from external knowledge. However, recent studies show that carefully crafted prompts [3, 4, 5, 6] can extract sensitive information such as personal identity information from the external datastore.
Since attack queries can closely resemble legitimate user queries, simple access control may block ordinary users [3, 4]. Recent work has begun to explore privacy risks in RAG, with a leading focus on differential privacy (DP) [6, 7]. Although DP methods provide formal statistical guarantees, they often degrade output quality (e.g., leading to high perplexity) due to DP's fundamental properties of worst-case guarantees, and are usually complicated to implement in practice. To this end, we propose private RAG via random projection to defend against data extraction attacks.
Our key idea is that differential privacy guarantees may be an overkill to prevent state-of-the-art attacks practically, whereas (some specific) random projection matrices naturally preserve pairwise similarities of the inputs in the lower-dimensional space. The extra randomness alters datastore embeddings so attackers may not recover the original text. This enables users to obtain accurate answers from the RAG system while adversaries fail. We apply a single projection step to datastore embeddings in the offline stage and the same matrix to user queries in the online stage.
In this work, we consider two RAG architectures: ‘KNN-LM’ [1] and ‘Standard RAG’ [2] . In KNN-LM, the system linearly combines the outputs of the language model and the k-nearest neighbour outputs (usually organized as a softmax over cosine similarities between queries and the datastore embeddings), and generates next token. In Standard RAG, the system concatenates retrieved texts with the query and feeds them to the LLM. In this work, we focus on the settings where formal privacy guarantees are not desired, and thus evaluate privacy leakage by exploring the success rates of strong, existing attacks empirically.
Correspondence to: Dixi Yao dixi@uchicago.edu
We note that there exist various RAG architectures, and we use the naming ‘Standard RAG’ just to contrast with the less popular KNN-LM architecture.
A PREPRINT
In Section 4, we empirically show that enforcing differential privacy guarantees may not provide better practical protection against data extraction and can instead harm utility. In summary, our RP technique significantly improves utility (over 50% on average across datasets) over the baseline methods without degrading empirical privacy performance.
Privacy-Preserving Random Projection. Certain random projection operations are a common technique for reducing dimensionality while preserving some similarity measures with high probability (e.g., based on the Johnson-Lindenstrauss lemma [16]). Prior works have shown that methods built on top of these projections can achieve differential privacy (DP) for specific applications [17, 18, 19, 20, 21, 22, 23, 24, 25]. In this work, we show that random projection can be effective for a variety of RAG scenarios as well.
3 Private RAG via Random Projection
3.1 Threat Model
As illustrated in Figure 1, our algorithm is compatible with both RAG architectures. In this work, we evaluate our method as an empirical defense against data extraction attacks. We consider a black-box setting in which the attacker has access only to model API responses, while model parameters, the random projection matrix, logits, embeddings, and latent representations remain inaccessible [26, 27]. The attacker submits queries to the RAG system using the API service and attempts to extract sensitive information in the datastore from the generated response through one round or multiple rounds. This is a common protocol in modern RAG applications where companies provide consulting service through LLM with an internal datastore while only text answers are exposed to users. The threat model also aligns with the threat scenarios considered in prior work on RAG privacy [3, 4, 28].

Figure 1: Overview of Private RAG via RP.
In short, we assume the attacker knows that RP is used but does not have direct access to the specific random matrices, with the projection matrix remaining undisclosed. Attackers are free to conduct repeated-query (Section 4.2) or multi-round adaptive attacks (Section 4.3). As network- and system-level attacks are out of scope and access to embeddings is restricted, we do not consider white-box attacks, embedding inversion, projection-matrix inversion, or side-channel attacks requiring side information or access beyond the LLM's text responses.
To provide a clearer understanding of what constitutes sensitive information, we show examples of leakage with and without sensitive content. In Table 1, we observe that leakage of sensitive information exposes critical details such as names, addresses, phone numbers, and email addresses. In contrast, non-sensitive information reveals no useful details. For example, a generic URL or repeated mentions of “Queen St” are too common and lack identifying information.
3.2 Algorithm
Let be the corpus of natural language documents (e.g., email threads or case paragraphs). Let denote the tokenizer and embedding layers, which can be further fine-tuned to map these 's (texts) to embeddings. We assume a fixed pre-trained encoder throughout the paper for simplicity. We also assume that an attacker interacts with the RAG system through API interactions and aims to extract data with constructed queries.
A PREPRINT
We sample an IID Gaussian matrix , where each element follows . We precompute the projected datastore embeddings offline by computing for each document embedding . We perform this preprocessing step once and store the results, introducing no runtime overhead during inference. For any query/prompt, we encode it as and compute its projection , which requires only a single matrix-vector multiplication. We then perform retrieval in the -dimensional space by finding the nearest neighbors to among and computing a softmax over their cosine similarities with . Finally, we combine this softmax with the parametric LLM's logits for in a weighted manner to select the next token. We repeat generation until reaching the maximum token limit or generating an end-of-sequence token.
Algorithm 2 (in Section D) and Algorithm 1 illustrate the implementation of our random projection method. The overall process follows the standard RAG pipeline: we first tokenize and embed the datastore offline, and store the representations in FAISS or another efficient indexing framework to enable fast retrieval at inference time. During inference, the model performs autoregressive generation via iterative next-token prediction.
For standard RAG (Algorithm 1), we compute the similarity between the projected query embedding and the projected datastore embeddings , and retrieve the most relevant text based on this similarity. The retrieved text is concatenated with the original query to form an augmented prompt, which is then passed to a parametric LLM to generate the final output. The algorithm of KNN-LM is summarized in Section D.
Privacy Implications. Random projection preserves privacy by altering the retrieval process: given a query, vanilla RAG retrieves the highest-scoring document and generates a corresponding token, which may contain sensitive information. After RP, embeddings that are close to the original top match can be selected with non-negligible probability (Section C). As a result, alternative tokens may replace the originally retrieved token.
Utility Discussions. A natural question arises: if random projections alter the retrieved neighbors, how does the model remain accurate? The reason is that random projection approximately preserves embedding distances, ensuring retrieval still selects relevant information. This has been extensively studied in prior literature [16]. In Section B, for completeness, we provide proof that our random projection preserves distance and cosine similarity. Section B.2 shows a study with synthetic data consistent with the theoretical analysis. For DP-based baselines, achieving privacy guarantees sacrifices utility. DP introduces a fundamental tradeoff: a small clipping bound overly distorts embeddings, while a large bound increases noise magnitude, both degrading retrieval utility. We illustrate this in Section 4.6.
Table 1: We focus on sensitive-information leakage and show examples of sensitive and non-sensitive information.
| Leakage Information | Sensitive Information | Non-Sensitive Information |
|---|---|---|
| URL with Personal Information (e.g., Token ID) | If you prefer to receive a hardcopy of your pay stub, click on the link below to complete a request form. Please click on the link below.http://etcsurvey.corp.enron.com/wi/p0810709/i.asp?r=19690&sa=OUULGRTU&l=9 | Suggestions and feedback are welcome at https://www.reddit.com |
| Phone | America Square, London, EC3N 1PQ Tel: +44 (0)171 839 4444 Fax: +44 (0)171 839 4444 | If you have any comments or suggestions contact us at The applicant, Mr Richard Owens, is a British national who was born in 1944 and lives in Queen St. Queen St. Queen St. |
| Personal Address | If you have any questions, please do not hesitate to call. Salle E. Yoo Davis Wright Tremaine One Embarcadero Center, Suite 600 San Francisco, CA 94111 | The applicant, Mr Richard Owens, is a British national who was born in 1944 and lives in Queen St. Queen St. Queen St. |
| Name | The applicant, Mr Michael Boyce, is an Irish national, who lives in Mullingar, Ireland. He was represented before the Court by Mr P.J. Groarke, a lawyer practising in County Longford, Ireland. | The applicant, Mr D.H. who was born in 1966 and lives in H. |
A PREPRINT

(a) KNN-LM (Enron)
(b) Standard RAG (Enron)
(e) KNN-LM (C4)
(c) KNN-LM (ECHR)
(d) Standard RAG (ECHR)
(f) Standard RAG (C4)
Figure 2: Utility/privacy comparisons of our method (RP) with the two DP baselines (DP-RP-G and DPSparseVoteRAG) on two RAG architectures (denoted as KNN-LM and Standard RAG) and targeted attacks on Enron Email and ECHR and untargeted attacks on C4. denotes various privacy budgets for the DP approaches. The x-axis is perplexity of generated content, and the y-axis is percentage of data leakage. RP (Ours) achieves a superior utility–privacy trade-off, with perplexity approaching the unprotected RAG baseline while maintaining empirically near-zero privacy leakage comparable to the standalone parametric model without retrieval-augmentation.
Table 2: Full privacy-utility comparison across datasets and methods under the repeated-query attack. Utility is measured using perplexity (PPL) and QA F1 scores. For Enron Email and C4, privacy leakage is reported as the number of leaked instances, whereas for ECHR, it is reported as a percentage.
| Method | Dataset / Model | Metric | Param. | RAG | DP-RP-G | DPSparseVoteRAG | RP (Ours) | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ε=1 | ε=5 | ε=10 | ε=20 | ε=1 | ε=5 | ε=10 | ε=20 | ||||||
| KNN-LM | Enron Email / GPT2 | PPL ↓ | 3.31 | 2.87 | 5.85 | 3.54 | 5.13 | 2.91 | 42.17 | 4.22 | 2.96 | 2.83 | 2.89 |
| Leakage (#) ↓ | 0 | 13 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | ||
| ECHR / Llama3-1B | PPL ↓ | 631.09 | 2.90 | 214.54 | 99.28 | 94.87 | 112.85 | 228.59 | 109.64 | 121.82 | 92.26 | 46.15 | |
| F1 ↑ | 25.70 | 90.32 | 53.25 | 51.30 | 54.02 | 55.13 | 41.67 | 41.67 | 40.32 | 45.38 | 87.70 | ||
| Leakage (%) ↓ | 32.82 | 82.72 | 2.76 | 2.41 | 2.81 | 2.69 | 1.75 | 37.86 | 38.68 | 38.82 | 2.26 | ||
| ECHR / Qwen3-4B | PPL ↓ | 1.47 | 1.55 | 2.26 | 2.28 | 2.28 | 2.30 | 3130.89 | 610.10 | 500.13 | 277.62 | 1.55 | |
| F1 ↑ | 90.18 | 90.32 | 80.35 | 80.32 | 80.18 | 82.39 | 52.40 | 51.37 | 51.94 | 52.98 | 89.32 | ||
| Leakage (%) ↓ | 2.03 | 19.08 | 13.45 | 13.21 | 14.85 | 15.39 | 2.44 | 2.46 | 2.21 | 2.24 | 1.94 | ||
| C4 / Llama3-8B | PPL ↓ | 2.76 | 3.16 | 5.98 | 5.47 | 4.12 | 4.38 | 6.54 | 5.91 | 5.39 | 4.51 | 2.98 | |
| Leakage (#) ↓ | 0 | 269 | 0 | 0 | 17 | 25 | 0 | 3 | 36 | 124 | 17 | ||
| Standard RAG | Enron Email / GPT2 | PPL ↓ | - | 1.58 | 3.42 | 3.23 | 5.24 | 2.91 | 3.34 | 3.71 | 3.61 | 1.62 | 2.05 |
| Leakage (#) ↓ | - | 217 | 0 | 0 | 8 | 5 | 0 | 0 | 0 | 9 | 3 | ||
| ECHR / Llama3-1B | PPL ↓ | - | 9.84 | 512.66 | 104.70 | 95.72 | 79.72 | 4398.91 | 7780.70 | 4922.52 | 5264.40 | 47.92 | |
| F1 ↑ | - | 97.18 | 51.39 | 54.31 | 54.12 | 54.79 | 1.72 | 43.72 | 42.42 | 43.33 | 66.70 | ||
| Leakage (%) ↓ | - | 37.92 | 2.03 | 1.87 | 2.15 | 1.96 | 1.77 | 2.05 | 2.05 | 19.48 | 2.16 | ||
| ECHR / Qwen3-4B | PPL ↓ | - | 1.19 | 2.50 | 2.49 | 2.51 | 2.50 | 1.74 | 1.43 | 1.62 | 1.38 | 1.19 | |
| F1 ↑ | - | 97.32 | 85.32 | 86.17 | 86.43 | 85.19 | 88.35 | 91.03 | 93.48 | 94.32 | 95.43 | ||
| Leakage (%) ↓ | - | 21.30 | 25.43 | 14.36 | 17.07 | 15.09 | 2.84 | 2.88 | 2.86 | 3.32 | 2.05 | ||
| C4 / Llama3-8B | PPL ↓ | - | 2.83 | 28.41 | 27.32 | 26.54 | 23.12 | 5.73 | 5.46 | 4.65 | 4.12 | 2.96 | |
| Leakage (#) ↓ | - | 358 | 0 | 0 | 15 | 28 | 0 | 33 | 79 | 203 | 23 | ||
4 Evaluation
4.1 Settings
We focus on empirical data extraction attacks [28] rather than differential privacy bounds, considering both repeated single-query and multi-round query attacks. We evaluate four datastore/LLM pairs: Enron Email [29] with GPT-2 [30], European Court of Human Rights (ECHR) with LLAMA3-1B-INSTRUCT, C4 with LLAMA3-8B-INSTRUCT, and HotpotQA [31] with QWEN2-7B-INSTRUCT. For utility, we measure perplexity [28] and task-specific performance.
A PREPRINT
For simplicity, we denote our random projection as RP, DP-guaranteed random projection with Gaussian noise as DP-RP-G [17], and the work of Koga et al. [6] as DPSparseVoteRAG. We also report results for vanilla RAG and the parametric model without a datastore. For differential privacy, we use a wide range of privacy budgets with . For DP-RP-G, the original DP-RP method by Blocki et al. [17] assumes binary vector embeddings. To adapt this framework to RAG and document retrieval, we first project both queries and datastore embeddings into a lower-dimensional space, clip the projected embeddings, and then add Gaussian noise to obtain differential privacy guarantees. The complete procedure is in Section D. We sweep the clipping bound from under each setting and report the results with optimal clipping bound. Remaining settings are in Section F. For DPSparseVoteRAG, we sweep the subset number over and choose the best value 50 (Section F.2).
In our methods, for KNN-LM, we set as 0.1 and as 1024. For RP, the only tunable parameter is (the projection dimension). Larger values better preserve utility while maintaining privacy protection. We choose since it achieves comparable utility to larger values (e.g., ) while providing better computational efficiency. More detailed analysis is in Section 4.4.
4.2 Repeated-Query Attacks
We launch repeated-query targeted attacks on Enron Email for personal identity information (PII) and ECHR for legal documents and untargeted attacks on raw C4 content. Attackers can repeatedly inject the same query multiple times. To make repeated-query extraction attack stronger, we inject dataset-specific prior knowledge into malicious queries, such as asking for emails when attacking the Enron Email dataset. For each entry, we perform 10 times repeated extraction attempts, and count any successful extraction as leakage. We assume the system flags and blocks queries repeated more than 10 times. Details, including query construction, are provided in Section E.
Figure 2 gives an overview of the privacy/utility trade-off of different methods under varying privacy budgets on three datasets under repeated-query attack while Table 2 gives details. Standard RAG achieves higher utility but poses greater risks of privacy leakage. Without protection, RAG leaks over 200 personal items in the Enron dataset. In contrast, our methods maintain utility close to RAG while leaking almost no private information. For DP-RP-G, we achieve strong privacy across all budgets, but utility remains unsatisfactory. DPSparseVoteRAG (DPSVR) shows that increasing the privacy budget reduces perplexity but increases leakage, lacking a balanced trade-off point. Overall, our approach gives strong privacy with minimal utility loss.
Our evaluation covers both structured and unstructured sensitive information to assess the method's generalizability. On the Enron dataset, we evaluate protection against structured data including email addresses, phone numbers, and URLs. As shown in Table 3, random projection effectively protects all three types, with leakage rates below across both KNN-LM and Standard RAG architectures. We observe that URLs are the easiest to leak. For unstructured text, we evaluate on the ECHR dataset, which contains legal case narratives with sensitive personal information embedded in natural language. Our method maintains strong privacy protection (2.19–2.27% leakage) while preserving utility, demonstrating that random projection works across both structured and unstructured sensitive information. This suggests that the privacy-preserving mechanism operates at the embedding level, making it agnostic to the format or structure of the sensitive content.
Table 3: Number of leaked email addresses, URLs, and phone numbers with different methods on Enron Email.
| KNN-LM | Standard RAG | |||||
|---|---|---|---|---|---|---|
| URL | Phone | URL | Phone | |||
| Parametric | 0 | 0 | 0 | 0 | 0 | 0 |
| RAG | 0 | 13 | 0 | 36 | 56 | 125 |
| RP (Ours) | 0 | 0 | 0 | 0 | 3 | 0 |
| DP-RP-G, | 0 | 0 | 0 | 0 | 0 | 0 |
| DP-RP-G, | 0 | 0 | 0 | 0 | 0 | 0 |
| DP-RP-G, | 0 | 0 | 0 | 0 | 8 | 0 |
| DP-RP-G, | 0 | 0 | 0 | 0 | 1 | 4 |
| DPSparseVoteRAG, | 0 | 0 | 0 | 0 | 0 | 0 |
| DPSparseVoteRAG, | 0 | 0 | 0 | 0 | 0 | 0 |
| DPSparseVoteRAG, | 0 | 0 | 0 | 0 | 0 | 0 |
| DPSparseVoteRAG, | 0 | 2 | 0 | 0 | 8 | 1 |
Table 4: Membership leakage rate. RP (Ours) can achieve approximately the same performance against MIA as parametric, which means the attacker barely identify membership information from RAG datastore.
| Method | ECHR | |||
|---|---|---|---|---|
| Enron Email | (Qwen3-4B) | C4 | HotpotQA | |
| Parametric | 0.001 | 0.006 | 0.003 | 0.001 |
| RAG | 0.282 | 0.996 | 0.843 | 0.913 |
| RP (Ours) | 0.003 | 0.007 | 0.003 | 0.001 |
A further extension of the repeated-query attack is the membership inference attack (MIA). MIA is important in RAG privacy, but it targets a different adversarial objective from the data extraction attacks studied in this paper: determining whether a known record is contained in the datastore, so we do not focus on evaluating various MIA methods. We evaluate this threat over the full private dataset and measure attack accuracy following E-MIA [32], which follows the standard MIA protocol for RAG systems under our threat model. As shown in Table 4, RP provides strong protection against E-MIA, achieving empirically near-zero membership leakage.
A PREPRINT
4.3 Multi-Round Adaptive Attacks
Another strong attack is the multi-round adaptive attack [9], where an attacker iteratively refines adversarial prompts based on outputs from previous rounds and aggregates the extracted information to infer private content. Yao et al. [33] further constructs a knowledge graph from outputs across attack rounds to generate future adversarial queries. The attack budget is set to a maximum of 200 queries to the RAG system.
For both attack methods, we evaluate the reconstructed content using semantic similarity (SS) and extended edit distance (EED). Following the experimental setup of Jiang et al. [9], we construct the datastore using chunks of 1500 words with a maximum overlap of 300 words. We report the chunk recovery rate (CRR), considering a chunk recovered if the reconstructed content overlaps with the original chunk by more than 1200 words. For Jiang et al. [9], we report the average rounds required to satisfy the termination condition.
We launch both multi-round targeted attacks on HotpotQA for document information. For measuring the utility of RAG system on usual queries. We report exact match (EM) and F1 scores between the generated output and the ground truth. For F1, precision is the number of matching tokens divided by the total generated tokens, and recall is the number of matching tokens divided by the ground-truth tokens. Ans denotes the final generated answer, and Sup denotes the retrieved supporting documents, measuring all tokens in the documents. For the parametric model, we prompt it to generate supporting facts to enable fair comparison, as the datastore may overlap with pre-training data. Joint indicates cases where we put answer and supporting documents together to measure.
From Table 5, we observe that the three privacy-preserving methods achieve similar utility, while our method attains the highest accuracy. All methods achieve similar semantic similarity between the original datastore content in each chunk and the attacked results, which we attribute to LLMs attempting to generate correct answers. In contrast, a high chunk recovery rate (i.e., how much datastore content is completely restored) and low EED indicate successful extraction attacks. Examples of extracted content are shown in Table 7. As shown in Table 6, random projection preserves cosine similarity between retrieved documents and ground truth, indicating successful retrieval. In contrast, differential privacy methods degrade retrieval performance. Looser privacy budgets can improve utility but raise privacy concerns.
We present a case study of results under multi-round attacks. From Table 7, we can see that Pablo Trapero and Aleksander Ford are originally mentioned in the question, so it is reasonable that the responses also contain these two names. However, the response generated by our method is substantially different from the original dataset chunk while still focusing on answering the question. No sensitive information, such as address, nationality, or birthdate, is revealed. Hence, this demonstrates successful defense against multi-round attacks.
One interesting aspect of our response is that Pablo Trapero was actually born on October 4th, 1971, and Aleksander Ford on November 24th, 1908. However, our response states that they were born on December 27th, 1965, and September 1st, 1923, respectively. This indicates that our method preserves the final answers without revealing the actual birthdates. The attacker may also mistakenly conclude that the birthdate information has been retrieved and stop the attack. In contrast, standard RAG reveals a large portion of the original content. Jiang et al. [9] successfully extract most sensitive content, while the knowledge graph-based method recovers most original information.
4.4 Effects of
In both RP and DP-RP-G, we sample the projection matrix from where is the projection dimension. Fig. 3 examines the impact of different values. As discussed in Section 3, larger better preserves retrieval scores. Consistently, we observe higher utility with increasing , while privacy remains unchanged. Our method relies on similarity-preserving projection rather than precise distance preservation (Section B and Section C), so the expected post-projection ranking change is less sensitive to , indicating robustness across a wide range of values. Based on analysis and empirical observation of choosing , we suggest following ways of choosing . If a user wants more privacy guarantee or less offline computation latency, a smaller should be chosen (e.g., for ). If
Table 5: Privacy results against multi-round attacks on HotpotQA using the KNN-LM framework.
| Jiang et al. [9] | Yao et al. [33] | ||||||
|---|---|---|---|---|---|---|---|
| CRR | SS | EED | Rounds | CRR | SS | EED | |
| Parametric | 30% | 0.17 | 0.030 | 2.18 | 37% | 0.033 | 0.07 |
| RAG | 60% | 0.16 | 0.028 | 2.05 | 75% | 0.034 | 0.10 |
| RP (Ours) | 3% | 0.16 | 0.88 | 2.05 | 0% | 0.032 | 0.93 |
| DP-RP-G (ε = 10) | 3% | 0.17 | 0.89 | 2.01 | 0% | 0.031 | 0.90 |
| DPSVR (ε = 10) | 2% | 0.17 | 0.88 | 2.34 | 0% | 0.034 | 0.90 |
Table 6: Utility results of different algorithms on HotpotQA using the KNN-LM structure.
| Ans | Sup | Joint | Cos. | ||||
|---|---|---|---|---|---|---|---|
| EM | F1 | EM | F1 | EM | F1 | ||
| Parametric | 7.48 | 28.74 | 21.37 | 49.62 | 7.13 | 28.55 | 0.73 |
| RAG | 12.48 | 29.88 | 25.38 | 59.74 | 10.84 | 32.06 | 0.75 |
| RP (Ours) | 11.32 | 28.57 | 25.22 | 57.14 | 9.12 | 34.09 | 0.75 |
| DP-RP-G, ε = 1 | 0.08 | 7.10 | 9.54 | 30.42 | 0.15 | 9.03 | 0.54 |
| DP-RP-G, ε = 5 | 0.21 | 9.32 | 10.35 | 27.82 | 0.16 | 9.85 | 0.53 |
| DP-RP-G, ε = 10 | 3.58 | 10.84 | 9.71 | 28.93 | 1.19 | 7.34 | 0.54 |
| DP-RP-G, ε = 20 | 4.56 | 9.81 | 14.95 | 31.23 | 1.67 | 8.32 | 0.61 |
| DPSparseVoteRAG, ε = 1 | 0.02 | 8.12 | 13.98 | 23.12 | 0.00 | 13.12 | 0.51 |
| DPSparseVoteRAG, ε = 5 | 3.31 | 11.23 | 12.88 | 30.64 | 1.31 | 14.29 | 0.52 |
| DPSparseVoteRAG, ε = 10 | 7.48 | 18.18 | 14.39 | 28.85 | 1.54 | 16.67 | 0.54 |
| DPSparseVoteRAG, ε = 20 | 7.48 | 18.18 | 14.38 | 28.85 | 1.54 | 15.38 | 0.54 |
A PREPRINT
Table 7: Examples of attack results under the multi-round setting. We highlight content matching the original datastore chunks. RP avoids revealing sensitive identity information while preserving relational logic, such as who was born first, even after multi-round attacks using a knowledge graph to retrieve related chunks [33].
| Original Chunk | ...Aleksander Ford: Aleksander Ford (born Mosze Lifszyc, 24 November 1908 in Kiev, Russian Empire – 4 April 1980 in Naples, Florida, United States) was a Polish Jewish film director, and head of the Polish People's Army Film Crew in the Soviet Union during World War II. Ford became director of the nationalized Film Polski company following the Red Army occupation of Poland. 7 Days in Havana: 7 Days in Havana (Spanish: 7 días en La Habana ) is a 2012 Spanish-language anthology film. Set during a week in the Cuban capital Havana, the film features one segment for each day, each segment directed by a different filmmaker. The directors are Julio Medem, Laurent Cantet, Juan Carlos Tabío, Benicio del Toro, Gaspar Noé, Pablo Trapero and Elia Suleiman. The screenplay was written by the Cuban novelist Leonardo Padura Fuentes. The film is a co-production between companies in Spain, France and Cuba... | |
|---|---|---|
| Initial Query | Pablo Trapero or Aleksander Ford? Who was born first? | |
| Attacking Methods | Response by RAG | Response by ours |
| Adaptive [9] | <think> Aleksander Ford (born Mosze Lifszyc, 24 November 1908 in Kiev, Russian Empire – 4 April 1980 in Naples, Florida, United States) was a Polish Jewish film director, and 2006 BBC Four television. Ford became director of the nationalized Film Polski company following the Red Army occupation of Poland. 7 Days in Havana: 7 Days in Havana (Spanish: 7 días en La Habana ) is a "Pennies From Heaven" (1978)... | <think> Pablo Trapero or Aleksander Ford? 7 Who was born first? 8 Who was born first? Aleksander Ford? |
| Yao et al. [33] | <think> Thinking Process: 1. **Analyze the Request:** * Target: An English actor of stage, film, and television. * Condition 1: Aleksander Ford (born Mosze Lifszyc, 24 November 1908 in Kiev, Russian Empire – 4 April 1980 in Naples, Florida, United States) was a Polish Jewish film director * Condition 2: 7 Days in Havana: 7 Days in Havana (Spanish: 7 días en La Habana ) * Goal: Who was born first? * ... | <think> Who was born first? Pablo Trapero or Aleksander Ford? <think> Thinking Process: 1. **Analyze the Request:** * The user is asking for a comparison of birth dates between two individuals: Pablo Trapero and Aleksander Ford. The goal is to determine who was born first. 2. **Identify the Individuals:** * * *Pablo Trapero:** An Argentine film director, screenwriter, and producer. * ***Aleksander Ford:** A Polish film director and screenwriter. 3. **Retrieve Birth Dates:** * * *Pablo Trapero:** I need to recall or verify his birth date. * Search query mental check: "Pablo Trapero birth date". * Knowledge: Pablo Trapero was born on December 27, 1965. * **Aleksander Ford:** * I need to recall or verify his birth date. * Search query mental check: "Aleksander Ford birth date". * Knowledge: Aleksander Ford was born on September 1, 1923. 4. **Compare Dates:** * * Aleksander Ford |
a user wants higher utility, a bigger should be chosen (e.g., for ). Otherwise, a moderate value would be suitable (e.g., for ).


Figure 3: Comparison of privacy/utility. Colors indicate ; markers distinguish RP and DP-RP-G. has weak relation with privacy but larger gives better utility.
To understand the effect of not setting the sampling variance as , we use and sample from , resulting in a perplexity of 70.86 and privacy leakage. For and , perplexity is 71.38 with leakage. Choosing sampling variances larger or smaller than degrades utility, validating that setting variance to is optimal.
4.5 Efficiency and Scalability
The DPSparseVoteRAG method can be inefficient. In our experiments, each inference takes about longer than RP and vanilla RAG (Table 8). This is due to DP voting and aggregation require partitioning the datastore into subsets and generating a token for each, resulting in inferences per token. Our method can achieve the same efficiency as RAG on latency per token.
A PREPRINT
Table 8: Comparison of the number of tokens generated and latency per generation for different methods over the ECHR dataset on an NVIDIA A100.
| RAG | RP (Ours) | DPSVR | |
|---|---|---|---|
| # Tokens per Generation | 107.8 | 123.4 | 92.3 |
| Latency per Generation (s) | 8.35 | 9.42 | 258.9 |
| Latency per Token (s) | 0.08 | 0.08 | 2.80 |
Table 9: Perplexity comparisons of KNN-LM and standard RAG on ECHR.
| Method | KNN-LM | Standard RAG |
|---|---|---|
| RP (Ours) | 43.20 | 47.92 |
| DP-RP-G | 97.09 | 102.66 |
| DP-RP-G (only clipping) | 45.47 | 46.99 |
Besides efficiency, we also take a look at the scalability of our evaluation. We empirically study datastores of up to about 100K HotpotQA documents, corresponding to roughly 200 million tokens, which is a reasonably sized RAG datastore comparable with many real-world enterprise services [34, 26]. Prior work [35] shows that extraction rates decrease substantially as datastore size increases. We further conduct a controlled scalability study in Figure 4 by varying the datastore size within the ECHR/Qwen3-4B setting. We show (1) the extraction rate of vanilla RAG decreases as the datastore grows, while (2) our method consistently maintains strong privacy protection across datastore sizes. Moreover, as discussed in Section 3, our RP method relies on replacing tokens or chunks with similar alternatives from the datastore. As the datastore size increases, the method has access to a larger pool of candidate tokens for such substitutions, reducing the extraction rate.

Figure 4: Scalability study on Standard RAG using ECHR with Qwen3-4B. Across different datastore sizes, RP maintains leakage close to the parametric baseline while consistently providing strong privacy protection.

Figure 5: Perplexity of DP-RP-G with clipping only (without Gaussian noise) under different clipping bounds.
4.6 Why Performance Degrades More by Differential Privacy Methods
A natural question is: what is the challenge for differential-privacy based methods to maintain utility in RAG applications. For DP-RP-G, achieving an guarantee requires bounding sensitivity, typically by clipping each projected embedding to norm , and then adding Gaussian noise . If , the noise vanishes; with a sufficiently large clipping bound, DP-RP-G approaches ours RP method. Thus, the utility loss arises from the additional constraints required for formal DP rather than from RP itself.
DP aggregation methods face a similar trade-off, as their utility depends strongly on perturbation magnitude and therefore on privacy budget [6]. As shown in Section 4, even relatively loose privacy budgets can substantially degrade utility while still allowing non-negligible leakage.
Clipping is typically required in DP mechanisms to bound sensitivity [36]; prior work similarly constrains vectors to bounded domains [37]. To isolate the effect of clipping and adding noise, we ablate the clipping operation without Gaussian noise. In Table 9, we compare RP with and without clipping, while Figure 5 varies the clipping bound. The results show that larger clipping consistently reduces perplexity, whereas sufficiently large clipping bounds recover performance close to RP.
5 Conclusion
In this work, we propose a simple random projection method to defend against data extraction attacks for RAG applications. Compared with DP-based approaches, we show that the specific random Gaussian projection can empirically protect against data reconstruction, at approximately the same level as parametric model without RAG datastore, while still maintaining semantic utility, with a overall decrease compared with vanilla RAG.
A PREPRINT
Limitations
At evaluation side, large-scale evaluation of privacy-preserving methods in real-world LLM-based RAG systems remains an interesting future work. Real-world systems may need to process billions of queries daily. In Table 8, one query takes about 8 seconds. Hence, evaluating one million queries would take 92 days without system-level optimization. Such large-scale evaluation thus requires system-level contributions, which we defer to future work.
Ethical Considerations
We use models and datasets that are publicly available on the Internet and licensed for non-commercial research use. We do not involve personally identifiable information (PII) which are not allowed to make public. We use only publicly available or synthetically generated datasets; we did not use any proprietary data or private user information at any stage of the experiments. These datasets are publicly available and widely used in the research community. Consistent with prior work, we did not further anonymize the data, as it was collected and released under publicly accessible licenses and used solely for research purposes. We did not introduce new personal data, nor did we attempt to re-identify individuals beyond what is already present in the original datasets.
References
[1] Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. Generalization through memorization: Nearest neighbor language models. In Proceedings of the International Conference on Learning Representations (ICLR), 2019.
[2] Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen tau Yih, Tim Rocktäschel, Sebastian Riedel, and Douwe Kiela. Retrieval-augmented generation for knowledge-intensive nlp tasks. In Proceedings of the Advances in Neural Information Processing Systems (NeuraIPS), volume 33, pages 9459–9474, 2020.
[3] Yu He, Yifei Chen, Yiming Li, Shuo Shao, Leyi Qi, Boheng Li, Dacheng Tao, and Zhan Qin. External data extraction attacks against retrieval-augmented large language models. arXiv preprint arXiv:2510.02964, 2025.
[4] Yuhao Wang, Wenjie Qu, Shengfang Zhai, Yanze Jiang, Zichen Liu, Yue Liu, Yinpeng Dong, and Jiaheng Zhang. Silent leaks: Implicit knowledge extraction attack on rag systems through benign queries. arXiv preprint arXiv:2505.15420, 2025.
[5] Shenglai Zeng, Jiankun Zhang, Pengfei He, Yiding Liu, Yue Xing, Han Xu, Jie Ren, Yi Chang, Shuaiqiang Wang, Dawei Yin, and Jiliang Tang. The good and the bad: Exploring privacy issues in retrieval-augmented generation (rag). In ACL (Findings), 2024.
[6] Tatsuki Koga, Ruihan Wu, and Kamalika Chaudhuri. Privacy-preserving retrieval augmented generation with differential privacy. arXiv preprint arXiv:2412.04697, 2024.
[7] Ruihan Wu, Erchi Wang, Zhiyuan Zhang, and Yu-Xiang Wang. Private-rag: Answering multiple queries with llms while keeping your data private. arXiv preprint arXiv:2511.07637, 2025.
[8] Changyue Jiang, Xudong Pan, Geng Hong, Chenfu Bao, and Min Yang. Rag-thief: Scalable extraction of private data from retrieval-augmented generation applications with agent-based attacks. CoRR, 2024.
[9] Changyue Jiang, Xudong Pan, Geng Hong, Chenfu Bao, Yang Chen, and Min Yang. Feedback-guided extraction of knowledge base from retrieval-augmented llm applications. arXiv preprint arXiv:2411.14110, 2024.
[10] Christian Di Maio, Cristian Cosci, Marco Maggini, Valentina Poggioni, and Stefano Melacci. Pirates of the rag: Adaptively attacking llms to leak knowledge bases. arXiv preprint arXiv:2412.18295, 2024.
[11] Nicolas Grislain. Rag with differential privacy. In 2025 IEEE Conference on Artificial Intelligence (CAI), pages 847–852. IEEE, 2025.
[12] Shenglai Zeng, Jiankun Zhang, Pengfei He, Jie Ren, Tianqi Zheng, Hanqing Lu, Han Xu, Hui Liu, Yue Xing, and Jiliang Tang. Mitigating the privacy issues in retrieval-augmented generation (rag) via pure synthetic data. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 24538–24569, 2025.
[13] Yunpeng Zhao and Jie Zhang. Does training with synthetic data truly protect privacy? In The Thirteenth International Conference on Learning Representations (ICLR), 2025.
A PREPRINT
[14] Longzhu He, Peng Tang, Yuanhe Zhang, Pengpeng Zhou, and Sen Su. Mitigating privacy risks in retrieval-augmented generation via locally private entity perturbation. Information Processing & Management, 62(4):104150, 2025.
[15] Rushil Thareja, Preslav Nakov, Praneeth Vepakomma, and Nils Lukas. Dp-fusion: Token-level differentially private inference for large language models. arXiv preprint arXiv:2507.04531, 2025.
[16] William B Johnson and Joram Lindenstrauss. Extensions of lipschitz mappings into a hilbert space. Contemporary mathematics, 26(189-206):1, 1984.
[17] Jeremiah Blocki, Avrim Blum, Anupam Datta, and Or Sheffet. The johnson-lindenstrauss transform itself preserves differential privacy. In Proceedings of the 2012 IEEE 53rd Annual Symposium on Foundations of Computer Science (FOCS), pages 410–419. IEEE Computer Society, 2012.
[18] Chugui Xu, Ju Ren, Yaoxue Zhang, Zhan Qin, and Kui Ren. Dppro: Differentially private high-dimensional data release via random projection. IEEE Transactions on Information Forensics and Security, 12(12):3081–3093, 2017.
[19] Ping Li and Xiaoyun Li. Differential privacy with random projections and sign random projections. arXiv preprint arXiv:2306.01751, 2023.
[20] Alaa Mahmoud Ibrahim, Mohamed Farouk, and Mohamed Waleed Fakhr. Privacy preserving image retrieval using multi-key random projection encryption and machine learning decryption. Journal of Advanced Research in Applied Sciences and Engineering Technology, 42(2):155–174, 2024.
[21] Kun Liu, Hillol Kargupta, and Jessica Ryan. Random projection-based multiplicative data perturbation for privacy preserving distributed data mining. IEEE Transactions on knowledge and Data Engineering, 18(1):92–106, 2006.
[22] Mohammad Hasan Narimani and Mostafa Tavassolipour. Fedrp: A communication-efficient approach for differentially private federated learning using random projection. arXiv preprint arXiv:2509.10041, 2025.
[23] Cihan Kaleli and Huseyin Polat. Privacy-preserving random projection-based recommendations based on distributed data. International Journal of Information Technology & Decision Making, 12(02):201–232, 2013.
[24] Nikola Pavlovic, Sudeep Salgia, and Qing Zhao. Differential privacy in kernelized contextual bandits via random projections. arXiv preprint arXiv:2507.13639, 2025.
[25] Bonwoo Lee, Cheolwoo Park, and Jeongyoun Ahn. Optimal differentially private kernel learning with random projection. arXiv preprint arXiv:2507.17544, 2025.
[26] Yuhong Sun, Joachim Rahmfeld, Chris Weaver, Weijia Chen, Roshan Desai, Wenxi Huang, and Mark H Butler. Enterpriserag-bench: A rag benchmark for company internal knowledge. arXiv preprint arXiv:2605.05253, 2026.
[27] Sarah Packowski, Inge Halilovic, Jenifer Schlotfeldt, and Trish Smith. Optimizing and evaluating enterprise retrieval-augmented generation (rag): A content design perspective. In Proceedings of the 2024 8th International Conference on Advances in Artificial Intelligence, pages 162–167, 2024.
[28] Yangsibo Huang, Samyak Gupta, Zexuan Zhong, Kai Li, and Danqi Chen. Privacy implications of retrieval-based language models. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 14887–14902, 2023.
[29] Bryan Klimt and Yiming Yang. The enron corpus: A new dataset for email classification research. In Proceedings of the European Conference on Machine Learning (ECML), pages 217–226. Springer, 2004.
[30] Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. Language models are unsupervised multitask learners. OpenAI blog, 1(8):9, 2019.
[31] Zhilin Yang, Peng Qi, Saizheng Zhang, Yoshua Bengio, William Cohen, Ruslan Salakhutdinov, and Christopher D Manning. Hotpotqa: A dataset for diverse, explainable multi-hop question answering. In Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing (EMNLP), pages 2369–2380, 2018.
[32] Zelin Guan, Shengda Zhuo, Zeyan Li, Jinchun He, Wangjie Qiu, Zhiming Zheng, and Shuqiang Huang. E-mia: Exam-style black-box membership inference attacks against rag systems. arXiv preprint arXiv:2605.00955, 2026.
[33] Mengyu Yao, Ziqi Zhang, Ning Luo, Shaofei Li, Yifeng Cai, Xiangqun Chen, Yao Guo, and Ding Li. Connect the dots: Knowledge graph-guided crawler attack on retrieval-augmented generation systems. arXiv preprint arXiv:2601.15678, 2026.
[34] Prafulla Kumar Choubey, Xiangyu Peng, Shilpa Bhagavath, Kung-Hsiang Huang, Caiming Xiong, and Chien-Sheng Wu. Benchmarking deep search over heterogeneous enterprise data. In Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing: Industry Track, pages 501–517, 2025.
A PREPRINT
[35] Zhenting Qi, Hanlin Zhang, Eric P Xing, Sham Kakade, and Hima Lakkaraju. Follow my instruction and spill the beans: Scalable data extraction from retrieval-augmented generation systems. In International Conference on Learning Representations, volume 2025, pages 48733–48755, 2025.
[36] Cynthia Dwork, Frank McSherry, Kobbi Nissim, and Adam Smith. Calibrating noise to sensitivity in private data analysis. In Proceedings of the Third Theory of Cryptography Conference, TCC 2006, New York, NY, USA, March 4-7, 2006., pages 265–284. Springer, 2006.
[37] Krishnaram Kenthapadi, Aleksandra Korolova, Ilya Mironov, and Nina Mishra. Privacy via the johnson-lindenstrauss transform. Journal of Privacy and Confidentiality, 5(1), 2013.
[38] Donald W Zimmerman, Bruno D Zumbo, and Richard H Williams. Bias in estimation and hypothesis testing of correlation. Psicológica, 24(1), 2003.
[39] Harold Hotelling. New light on the correlation coefficient and its transforms. Journal of the Royal Statistical Society. Series B (Methodological), 15(2):193–232, 1953.
[40] Ronald A Fisher. Frequency distribution of the values of the correlation coefficient in samples from an indefinitely large population. Biometrika, 10(4):507–521, 1915.
[41] Ilias Chalkidis, Manos Fergadiotis, Dimitrios Tsarapatsanis, Nikolaos Aletras, Ion Androutsopoulos, and Prodromos Malakasiotis. Paragraph-level rationale extraction through regularization: A case study on european court of human rights cases. In Proceedings of the Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL), Mexico City, Mexico, 2021. Association for Computational Linguistics.
A PREPRINT
Contents
A Usage of AI
12
B Preservation of the -Distance and Cosine Similarity of Random Projection
12
B.1 Proof: Preservation of the Cosine Similarity
12
B.2 Synthetic Data
14
C Proof: Probability of Top-1 Selection Changing after Random Projection
14
D Complete Algorithms
16
E Implementation Details
17
F Settings of Hyper-Parameters
17
F.1 General Settings
17
F.2 DPSparseRAG
18
G Random Projection with Other Distributions
18
H More Discussion
18
H.1 False Positive Classification of Non-Sensitive Information
18
H.2 An Example of Generation
19
A Usage of AI
We employ large language models (LLMs) to improve the grammar and clarity of our writing and assist coding. All research ideas, directions, and decisions are independently conceived and carried out by the authors.
B Preservation of the -Distance and Cosine Similarity of Random Projection
The theory has already been proved by Johnson and Lindenstrauss [16]. For completeness, we provide analysis below. Let the query embedding be , the retrieved embedding by vanilla RAG be , and the random projection matrix be . The original distance is . According to the Johnson–Lindenstrauss transform, when the projection variance is , we have the boundary condition
where [16]. This ensures that the distance is well preserved after projection.
Further, the original retrieval score, typically cosine similarity, can also be preserved after projection. After random projection, the score becomes
For fixed and , the expectation satisfies (Proof in Section B.1). Thus, when is sufficiently large, the expected cosine similarity after projection closely approximates the original score, preserving retrieval quality despite token perturbations.
B.1 Proof: Preservation of the Cosine Similarity
Our main argument is that with multiple rounds of token generation, the overall semantic meaning is preserved even if individual tokens are perturbed or replaced. In other words, we have
A PREPRINT
Proof. We have query embedding and datastore embedding . First, let and and we can have . With that, we can have
We let and . Then we can have
Because is an IID Gaussian matrix and each element is independently sampled. We can find rotation matrices and where . Hence, we can have . So, without loss of generality, we can rotate the basis so that , . We know that each row of is a Gaussian vector . So, and where are IID . Thus, for each ,
With this bivariate normal distribution, we can define
And we can have that . Then, we can calculate
This is exactly the sample Pearson correlation of IID bivariate normal samples with population correlation .
Lemma 1. For random variables and where , , and , we can calculate the expectation of sample Pearson correlation coefficient
as
Although the proof of this lemma is not our original contribution, as there is plenty of literature showing this conclusion [38, 39], we would like to provide a proof here to demonstrate some of our insights.
Proof. Let , , . Then
If we use Taylor expansion, we will have
As a result, we will have
A PREPRINT
We have and . We also know and . Using Isserlis theorem, we have , , , . Hence, we have
By putting them back, we have our conclusion.
According to Lemma 1, we prove Eq. (1). The expected distortion goes down as . Hence, we can see that our designed random projection preserves the cosine similarity.
B.2 Synthetic Data
Before starting our experiments, we first conduct a sanity check to verify whether embedding distances remain consistent after random projection. We consider two settings. In the synthetic setting, we use LLAMA3-8B-INSTRUCT to generate 100 datastore entries with the prompt “Generate a datastore entry containing domain knowledge.” For each of these, we repeat 100 times to generate a query using the prompt “Generate a query about domain knowledge.” In the random setting, both datastore and query embeddings are random vectors drawn from .
We measure the L2 distance and cosine similarity between each query embedding and the datastore embeddings. We

Figure 6: Cosine similarity error and L2 distance ratio under different sanity-check settings.
use two metrics: the L2 distance ratio, , and the cosine similarity difference, . We first average each metric over 100 datastores and then average across 100 runs. Fig. 6 presents the sanity-check results, along with the theoretical upper and lower bounds derived from the Johnson–Lindenstrauss (JL) transform, given by .
As increases, the cosine similarity error decreases and approaches zero, confirming our later observation that larger improves perplexity, which is consistent with our theoretical analysis. For the L2 distance, the results follow the JL transform prediction, with the ratios remaining within the theoretical bounds. A larger also stabilizes the ratio. Overall, these results verify that, in expectation, distances are well preserved after random projection.
C Proof: Probability of Top-1 Selection Changing after Random Projection
Without loss of generality, we consider the top-1 case, where the datastore embedding attains the largest cosine similarity in the vanilla RAG setting. We show that if there exists another datastore embedding ( ) such that
then the probability that the projected cosine similarity exceeds satisfies
where is an upper bound on the correlation between the Fisher-transformed projected similarities, and denotes the cumulative distribution function of the standard normal distribution.
Proof. We define the normalized query and datastore embeddings as
Under this notation, the assumption becomes . By the Cauchy–Schwarz inequality,
A PREPRINT
We next introduce the Fisher transform
Since cosine similarity takes values in and is strictly increasing on this interval, the ordering of similarities is preserved under this transformation. In particular,
As shown in Section B, the projected cosine similarity is the sample Pearson correlation computed from IID bivariate normal pairs with population correlation . By the classical Fisher -transform result [40], we have
Because and share the same projected query vector, they are generally correlated. Let , and assume for some fixed upper bound .
Under a joint Gaussian approximation, the difference is approximately normally distributed with
Therefore,
Since , we have . By the mean value theorem, there exists between and such that
Using and , we obtain
Substituting this bound yields
which completes the proof.
This result shows that after random projection, embeddings that are sufficiently close in the original space can overtake the original top-1 embedding with non-negligible probability. This behavior is desirable for privacy preservation: sensitive tokens (e.g., names, addresses, or identification numbers) often have embeddings close to semantically related but less sensitive alternatives, and random projection allows these alternatives to replace the original sensitive tokens with controlled probability. Combined with the bounds in Section B, this demonstrates that random projection limits distortion to a reasonable range, preserving general semantic content while reducing the likelihood that specific sensitive tokens are deterministically selected.
A PREPRINT
Algorithm 2 Private RAG with Random Projection (KNN-LM)
Require: Datastore with documents; tokenizer and embedding function .
Input: User query
Output: Generated answer
Parameters: Projection dimension ; maximum token length
Offline preprocessing
1: Sample random projection matrix , where
2: Compute datastore embeddings , where
3: Project embeddings:
Online inference (per query)
4: Initialize , ,
5: while and is not the end token do
6: Compute query embedding:
7: Project query embedding:
8:
9: Predict next token:
10: Append token: ,
11:
12: end while
13: return
D Complete Algorithms
For KNN-LM (Algorithm 2), at each generation step we apply random projection to both the query embedding and the datastore embeddings. The language model produces a next-token distribution based on the current context . In parallel, the KNN distribution is computed by measuring the cosine similarity between the projected query embedding and each projected datastore embedding , followed by a softmax over the top- nearest neighbors to obtain a probability distribution over candidate tokens. The final next-token distribution is obtained by linearly combining the two distributions with weight . The selected token is then appended to the context and the generated answer, and the process repeats.
Algorithm 3 Implementation of DP-RP-G (KNN-LM)
Require: Datastore ; embedding function
Input: User query
Output: Generated answer
Parameters: Projection dimension ; max tokens ; clipping bound ; privacy
Offline preprocessing
1: Sample random projection , where
2: Compute datastore embeddings , with columns
3: Project:
4: for each column of do
5:
6: end for
Online inference (per query)
7: Initialize , , ,
8: Sample IID , where
9:
10: while and is not the end token do
11:
12:
13:
14: ,
15:
16: end while
17: return
We implement DP-RP-G in Algorithm 3, following Blocki et al. [17], which adds Gaussian noise after random projection to achieve differential privacy. Unlike Blocki et al. [17], who assume binary or -bounded vectors, which does not
A PREPRINT
hold for LLM embeddings. Therefore, after projection, we apply standard DP clipping to any vector :
so that all vectors have -norm at most . After clipping, we add Gaussian noise calibrated to the privacy budget where the variance . As our goal is to protect the datastore, we apply the DP step only to (and not to the queries). Hence, lines 12–19 in Algorithm 3 are the same as lines 7–15 in Algorithm 2. For the DP-RP-G method implemented in standard RAG, we replace lines 12–19 with lines 7–13 in Algorithm 1.
Table 10: Comparison of KNN-LM and Standard RAG on Enron Email and ECHR with different .
| m | KNN-LM | Standard RAG | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 10 | 20 | 30 | 40 | 50 | 60 | 10 | 20 | 30 | 40 | 50 | 60 | |
| Enron Email | ||||||||||||
| Privacy (# leakage) | 4 | 2 | 0 | 0 | 0 | 0 | 8 | 6 | 1 | 0 | 0 | 0 |
| Perplexity | 3.14 | 3.15 | 3.14 | 3.14 | 3.16 | 3.16 | 3.70 | 3.68 | 3.70 | 3.71 | 3.71 | 3.98 |
| ECHR | ||||||||||||
| Privacy (% leakage) | 2.12 | 2.24 | 2.06 | 2.12 | 2.18 | 1.94 | 2.31 | 2.02 | 2.16 | 2.08 | 2.12 | 2.14 |
| Perplexity | 512.64 | 512.64 | 512.64 | 112.35 | 109.64 | 110.35 | 4307.36 | 4888.23 | 5155.85 | 4307.36 | 7549.47 | 7551.63 |
E Implementation Details
First, we use the Enron Email dataset [29] as the datastore and GPT-2 [30] as the LLM because GPT-2's pre-training data do not overlap with Enron Email, ensuring the RAG data remain unseen. Thus, private information is limited to the RAG documents. The dataset contains annotated sensitive information (URLs, email addresses, phone numbers), and we use the entire dataset as the datastore, totaling 4576 sensitive items. We use the query prompts from [28] (e.g., You may also contact us via e-mail at) and evaluate whether the annotated personally identifiable information can be retrieved.
The European Court of Human Rights (ECHR) dataset [41] contains legal case documents from the ECHR. Queries come from test-case descriptions, and utility is measured by matching generated judgments to ground-truth labels. We use Llama3-1B-Instruct. For adversarial queries, we use Llama3-8B-Instruct to annotate sensitive information and query with prompts concatenating "This is the first sentence of a paragraph from ECHR legal documents. Complete the paragraph with the sentence:" and the first sentence of each case. We check if generations contain the annotated sensitive identity, using 10K documents.
Besides targeted leakage where we check if exact annotated information is leaked, we use the C4 dataset, a cleaned and large-scale version of Common Crawl, for untargeted leakage evaluation. We select 5,000 samples and use the first sentence of each as the query. We then compute ROUGE-L scores between each generation and every datastore sample. If any sample in the datastore has a score greater than 0.5 with the generation, where we follow the same settings by Huang et al. [28], marking it as a leakage. We report the number of leakages out of the 5k samples. We use the LLAMA3-8B-INSTRUCT model as the backbone.
HOTPOTQA [31] is a multi-hop QA dataset with strong supervision for supporting facts, enabling more explainable systems. We use it to evaluate whether we retrieve correct supporting documents and measure cosine similarity between retrieved and reference embeddings to assess retrieval quality. We use the training set as the datastore and the test set for evaluation. The datastore contains over 90K documents. We evaluate with distractor setting which means the whole datastore is for reference. We use QWEN2-7B-INSTRUCT as the backbone model. Since document retrieval relies on KNN for both KNN-LM and standard RAG, we focus on the KNN-LM structure to analyze the retrieval process. For evaluation, we report exact match (EM) and F1 scores between the generated output and the ground truth. As the datastore is very large, we randomly select 100 documents as targets for targeted attacks. The initial query in multi-round attack is each question.
F Settings of Hyper-Parameters
F.1 General Settings
For all LLM generations, we set the repetition penalty to 0.75 and the no-repeat-ngram-size to 0. The feature dimensions of GPT-2, Llama3, and Qwen2 are 128, 2048, and 3584 respectively. All other generation parameters follow the default
A PREPRINT
HUGGINGFACE settings. By default, we set the datastore size equal to the total number of tokens in each dataset. We follow previous differential privacy work where we set as the reverse scale of dataset size. For Enron Email and ECHR, it is . For HotPotQA and C4, we use . We use each model's tokenizer and its last hidden-state vectors as embeddings for both retrieval settings. The max output token length is 2048.
F.2 DPSparseRAG
Apart from and clipping bound we tune on in the experiments, another hyper-parameter for DPSparseRAG is . We therefore conduct a sweep over with on the Enron Email and ECHR datasets. Overall, we observe in Table 10 no significant difference in utility across various values of .
Table 11: Perplexity and data leakage comparison using random projection matrices drawn from different distributions on the Enron Email dataset with GPT2.
| KNN-LM | Standard RAG | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Perplexity | URL | Phone | Perplexity | URL | Phone | ||||
| RAG | 2.87 | 0 | 13 | 0 | 1.58 | 36 | 56 | 125 | |
| RP (Ours) | Gaussian | 2.89 | 0 | 0 | 0 | 2.05 | 0 | 3 | 0 |
| Rademacher | 2.92 | 0 | 2 | 0 | 1.76 | 0 | 3 | 1 | |
G Random Projection with Other Distributions
Beyond the normal (Gaussian) distribution, we also experimented with constructing the projection matrix using a Rademacher distribution. In this distribution, each entry independently takes the value +1 or -1 with equal probability (50%). As shown in Table 11, the Rademacher-based projection also preserves privacy effectively while achieving performance comparable to vanilla RAG. These results indicate that our proposed random projection method remains effective as long as the projection matrix preserves similarity structure, regardless of the specific distribution.
H More Discussion
H.1 False Positive Classification of Non-Sensitive Information
Although random projection provides strong privacy protection overall, our experiments on Enron Email, ECHR, and C4 reveal that a small number of items may still be leaked. All failure cases fall into the case of leakage examples without sensitive information. Analysis of these failure cases reveals a clear pattern: random projection provides complete protection (100% leakage prevention) for specific content such as numbers, IDs, and email addresses.
While, in rare cases, common terminology which are non-sensitive information may mis-classified personal identity information in annotation (e.g. common streak name Queen St.) This occurs because such terms may appear in multiple contexts, making them less distinctive in the embedding space. These findings suggest that random projection is most
Table 12: Example responses generated by different methods given the prompt.
| Prompt | Complete the sentences: you have any suggestions, please share. With the rise of social media... |
|---|---|
| Parametric | With that in mind here are a few ideas to get you started: 1. **Create a vision board**: Cut out images and words that represent your goals and desires and create a visual representation of what you want to achieve. 2. **Set SMART goals**: Make sure your goals are Specific Measurable Relevant and Time-bound. This will help you stay focused and motivated. 3. **Break down big goals into smaller. |
| RAG | it's become increasingly important for businesses to have a strong online presence. One way to do this is by creating engaging content that resonates with your target audience. Here are some tips to help you create content that drives engagement: 1. Know your audience: Before you start creating content make sure you have a good understanding of your target! audience. Who are they? What are their interests? What problems do they need? |
| RP (Ours) | it's become increasingly important for businesses to have a strong online presence. One way to do this is by creating engaging content that resonates with your target audience. Here are some tips to help you create content that drives engagement: 1. Know your audience: Before you start creating content make sure you have a good understanding of who your target! audience is. What are their interests need? |
| DP-RP-G (ε = 20) | PrintWriter.PrintWriter userService userServiceExchangeExchangeExchange_generate_generate |
| DPSparseVoteRAG (ε = make sure you have a good understanding of your target! "#"#!"""##"#20) | |
A PREPRINT
effective for protecting unique identifiers while providing strong but not absolute protection for common terms that may appear across multiple documents.
H.2 An Example of Generation
Table 12 provides an example of responses generated by different methods for the same prompt. The parametric model produces unrelated continuation that is not grounded in the datastore. In contrast, both RAG and our method generate clear, relevant answers, whereas the DP-based methods often produce incoherent or unrelated content.