RAG 真的能“不暴露私有數據”嗎?答案是:可以
你是否認真考慮過 RAG 流水線中的文檔隱私?這篇文章也許能提供一個有幫助的方向。。
為什么“Standard RAG → Cloud Search”在隱私上行不通
Standard RAG 的做法是把明文文檔塞進 prompt。對于企業合同、病歷或個人筆記等輸入,這是完全不可行的——從設計上你就在暴露敏感數據。
Parametric RAG (PRAG) 試圖把知識“烘進”LoRA 權重,但在實踐中碰上兩堵墻:
- 運維負擔與時延。每份文檔都需要各自的 synthetic Q&A 生成以及定制化的 LoRA 微調。在線服務時還要在這些 adapter 之間周轉切換,真實世界的時延與運維開銷難以接受。
- 表示不對齊。模型從 synthetic Q&A 學到的內容,往往與 Standard RAG 的表征與檢索方式對不上,導致在 OOD 輸入上的泛化較弱。
什么是 DistilledPRAG?(一句話版)
通過知識蒸餾,讓“學生模型”(parametric RAG)在對齊文檔結構與內部激活的前提下,逼近“教師模型”(standard RAG)的推理能力,并且全程不發送明文。
實操要點
- 先合成,再對齊。構造 289,079 個覆蓋單文檔與跨文檔場景的 Q&A 樣本。對學生模型,用特殊的 mask tokens 替代原始文檔;一個 parameter generator 將每份文檔“翻譯”為對應的 LoRA。隨后在兩條戰線進行蒸餾——hidden states 與 output distributions——讓學生對齊教師。
- 訓練/推理同構。訓練時拼接多份文檔;推理時檢索 top-k、拼接,然后生成一份 unified LoRA 來生成答案——而不是像 PRAG/DyPRAG 那樣為每份文檔各自生成 LoRA 再相加或取平均。

Figure 1: Inference Paradigms for standard RAG, PRAG, DyPRAG, and DistilledPRAG. (1) Standard RAG inputs the plaintext documents and question. (2) PRAG generates QA pairs per document to fine-tune LoRA adapters, and sums them to obtain document aggregated representations for LLM injection. (3) DyPRAG translates individual documents to its LoRA and averages them to achieve document aggregation for LLM injection. (4) DistilledPRAG concatenates documents to parameter generator to create cross-document LoRA, and masks documents with question as input, more similar to standard RAG. [Source].
Figure 1 對比了 Standard RAG、PRAG、DyPRAG 與 DistilledPRAG 的推理模式。DistilledPRAG 會檢索并拼接多份文檔,然后“一次性”生成單個跨文檔 LoRA——其輸入流更接近 Standard RAG。
深入解析:DistilledPRAG 的三個核心組件

Figure 2: The Architecture of DistilledPRAG Model. 1. Use DeepSeek-V3 to mine knowledge from a single document and augmented cross-documents by random concatenation. 2. Train a parameter generator to map documents to a LoRA for student LLM, enabling it to mimic a teacher RAG's reasoning by minimizing differences in hidden states and logits on synthetic data. [Source].
Figure 2 展示了 DistilledPRAG 中的 parameter generator 的工作方式:LongT5 對文檔編碼 → 按層索引的可學習 queries 執行 cross-attention pooling → self-attention encoder 進一步提煉信號 → FFN 產生目標 LoRA。僅訓練 generator;base LLM 與 document encoder 均凍結。
合成數據:讓跨文檔推理成為默認模式
- 來源。隨機從 2WQA 訓練集采樣 30,000 篇文檔。生成約 139,723 個單文檔 Q&A,再通過拼接生成約 149,356 個跨文檔 Q&A——合計為 289,079。
- 目標。覆蓋單文檔事實,同時強化跨文檔整合,讓模型在多文檔輸入下學會生成單個、整體性的 LoRA。
parameter generator:從長文檔到單個 LoRA 包
- Encoder。使用 LongT5 將文檔映射為序列表征。
- Cross-attention。用按“layer”索引的可學習 queries 對文檔表征做 cross-attention,得到 H0。
- Self-attention + FFN。進一步編碼 H0,并直接回歸目標 LoRA Δθ。
- 凍結部分。僅訓練生成器 Genω;保持基礎模型參數 θ 與文檔編碼器 ψ 凍結。
對齊目標:generation、hidden states 與 logits
- Generation loss。在文檔被 mask、僅可見問題的輸入條件下,最小化答案的 NLL。
- Hidden-state alignment。跨層的余弦損失 Lcos,采用逐層增權,靠近輸出層權重更高。
- Logit alignment。token 級 KL 散度 LKL,用于對齊輸出分布。
推理范式:與訓練嚴格同構
用 BM25 檢索 top-3 文檔 → 按檢索順序拼接 → 用特殊的 mask tokens 替換文檔得到 x~ → parameter generator 產出單個 LoRA Δθ → 使用適配后的基礎模型 fθ+Δθ 回答。全程不暴露明文。
評價

Figure 3: Overall F1(%) performance of DistilledPRAG and baselines on 2WQA, HQA, PQA and CWQ datasets. Bold indicates the best performance, and underlined indicates the second best. [Source].
設置。以各子任務 dev 集的前 300 個問題計算 F1 (%)。檢索固定為 BM25(top-3)。訓練僅使用 2WQA。基線包括 Standard RAG、PRAG、DyPRAG 與 PISCO。
主要結果:
- LLaMA-8B。DistilledPRAG 平均為 36.1,優于 Standard RAG(33.8),并明顯領先 DyPRAG(29.6)與 PRAG(28.2)。在 CWQ(開放域復雜查詢)上達到 49.0——在相同 base 的所有變體中最佳。
- LLaMA-1B。DistilledPRAG 為 28.3,對比 Standard RAG(24.6)、DyPRAG(18.3)與 PRAG(27.0)。
- Mistral-7B。DistilledPRAG 為 23.1,優于 Standard RAG(20.6)與 PISCO(21.6)。
結論。即便只在 2WQA 上訓練,DistilledPRAG 在 HQA、PQA、CWQ 等 OOD 數據集上也能保持競爭力,甚至領先。證據表明,同時對齊結構與激活比單靠 synthetic QA 的遷移更有效。
思考
關鍵洞見在于把多文檔證據壓縮為一個跨文檔的 LoRA,并用“二重對齊”(hidden states + logits)讓學生模型在從未見過明文的情況下逼近教師的決策邊界。本質上,這是把檢索上下文從顯式的 context window 轉移到了隱式的 parameter channel。
兩項現實成本值得注意:計算量隨 mask 長度與 base model 規模增長;同時 generator 在 OOD 輸入上的魯棒性仍需壓測。可以通過兩點改進權衡:(a) 將單一、統計初始化的 mask 升級為分層、可組合的 token 集合;(b) 在 generator 中加入結構化稀疏與可驗證的信息流約束——兩者都旨在獲得更好的延遲-隱私 Pareto。
進一步地,把“single LoRA”泛化為一個 task-graph-aware 的 LoRA 組件混合體,其中不同的證據簇激活可解釋的低秩子空間;并行配套一個可審計的 retrieval trace,使多跳推理在可解釋性與誤差控制上同步增強,而非在多跳中累積失真。
參考文獻: Privacy-Preserving Reasoning with Knowledge-Distilled Parametric Retrieval Augmented Generation(???https://arxiv.org/pdf/2509.01088v1)??
本文轉載自??PyTorch研習社??,作者:AI研究生

















