---
title: "Prompt compression — 提示词压缩"
source: "https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9"
wiki: "systems-analysis.info/int"
article: "Prompt_compression_—_提示词压缩"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:Machine learning"
  - "Category:Prompt engineering"
revision_id: 6008
wiki_created_at: 2026-09-06T23:57:05Z
wiki_modified_at: 2026-09-06T23:57:05Z
downloaded_at: 2026-09-07T23:11:31Z
---

# Prompt compression — 提示词压缩

**提示词压缩**（英语：*prompt compression*）是提示词工程中的一系列方法，旨在缩短供大型语言模型 (LLM)使用的输入文本（提示词）的长度，同时保留关键信息<sup>[\[1\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-jha2024-1)</sup>。随着 LLM 的上下文窗口增长到数百万词元（token）（例如 Google Gemini），处理超长文本成为可能，但也带来了新的挑战：高昂的调用成本、增加的延迟，以及因“中间丢失”（lost-in-the-middle）效应导致的推理质量下降<sup>[\[2\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-survey2024-2)</sup>。

提示词压缩通过在缩短的输入中集中最重要的数据并舍弃冗余信息来解决这些问题。这降低了超出上下文限制的风险，加快了生成速度，并降低了成本，同时保持了回答的准确性<sup>[\[3\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-datacamp-guide-3)</sup>。

## 提示词压缩方法

提示词压缩方法可分为几个主要类别。

### 词元删除（过滤）

这种方法在于从原始文本中删除信息量最少的词元、短语或句子，而不改变其余部分。词元的重要性通过启发式方法确定。

- **LLMLingua**：由微软开发的一种方法，它计算每个词元的困惑度（perplexity），并删除那些对文本可预测性影响不大的词元。在其**LongLLMLingua**版本中，该方法被调整用于长文档，会考虑文本片段与用户特定查询的相关性<sup>[\[4\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-jiang2023_llmlingua-4)</sup>。
- **Selective-Context**：使用一个小型语言模型来评估每个词元的*自信息量*（self-information），并舍弃信息量最低的词元<sup>[\[5\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-li2023_selective-5)</sup>。
- **PCRL** (Prompt Compression via Reinforcement Learning)：通过强化学习训练一个智能体（agent），使其为每个词元做出“保留”或“删除”的决策，旨在最大化最终答案的质量指标（如 ROUGE）<sup>[\[6\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-jung2023_pcrl-6)</sup>。

### 抽象式压缩（摘要）

在这种方法中，一个压缩器模型（通常规模较小）会生成原始文本的简短抽象摘要，然后将该摘要传递给主 LLM。

- **RECOMP** (Retrieval-Compression-Prompting)：为知识库中的每个文档预先生成一个简短的摘要（*summary*），该摘要会考虑用户可能的查询（*query-aware summary*）。这不仅可以压缩信息，还可以对其进行预处理<sup>[\[7\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-xu2024_recomp-7)</sup>。
- **PRCA** (Prompt Compression with Reinforced Context Aggregation)：将摘要模型训练与强化学习相结合，以生成能最大程度提高主 LLM 回答质量的摘要<sup>[\[8\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-yang2023_prca-8)</sup>。
- **Prompt-SAW** (Semantic Aware Winnowing)：在进行摘要前，从文本中提取知识图谱（实体和关系），筛选出相关的图谱节点，并基于这些节点生成压缩后的文本<sup>[\[9\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-ali2024_promptsaw-9)</sup>。

### 抽取式压缩

该方法从原始文本中提取关键片段（句子、段落），而不对其进行改写。

- **Reranker-LLMs**：使用一个重排序模型（*reranker*），评估每个段落或文档对当前查询的重要性，并仅选择最相关的部分<sup>[\[10\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-pradeep2023_reranker-10)</sup>。
- **CompAct**：展示了一种迭代式的抽取-摘要方法。模型 последовательно处理长文本的片段，对其进行压缩，并检查信息是否足以回答问题。如果不足，则添加下一个片段并再次压缩，从而在保持质量的同时实现显著的压缩率<sup>[\[11\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-yoon2024_compact-11)</sup>。

### 蒸馏与“记忆词元”

这是一类新方法，模型不再接收文本，而是接收经过专门训练的替代词元或包含压缩信息的嵌入（embedding）。

- **Gist Tokens**：对 LLM 进行微调，使其能将长指令“折叠”成一小组特殊的“要点词元”（*gist-tokens*）（例如，用 20-30 个词元代替数千个词元）。这些词元随后被用来替代原始提示词，可实现高达 26 倍的压缩率，且质量损失极小<sup>[\[12\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-mu2023_gist-12)</sup>。
- **Soft Prompt Tuning**：不使用文本提示词，而是使用可训练的“虚拟词元”（嵌入），这些词元经过调整以解决特定任务。
- **SelfCP**：提出使用冻结的 LLM 本身作为压缩器。通过向其输入带有特殊标记的文本片段，模型会生成一个密集表示（*memory tokens*），然后模型自己使用这个表示来生成答案<sup>[\[13\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-gao2024_selfcp-13)</sup>。

## 效果与权衡

- **加速与成本降低**：由于 Transformer 的复杂度随序列长度呈二次方增长（\$O(n^2)\$），将提示词缩短几倍可以显著节省计算资源。例如，*gist tokens* 在 26 倍的压缩率下，可节省高达 40% 的 FLOPs<sup>[\[12\]](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_note-mu2023_gist-12)</sup>。
- **质量提升**：有时，如果原始文本包含噪声或分散注意力的细节，提示词压缩甚至可以提高回答的质量。删除不相关的上下文有助于模型更好地专注于任务的重要方面。
- **质量权衡（忠实度）**：过于激进的压缩可能导致重要细节（如日期、姓名、否定词）的丢失，从而降低回答的质量。抽象式方法尤其容易出现幻觉（hallucination）的风险。控制压缩后提示词的完整性和准确性（*faithfulness*）是一项关键挑战。

## 与其他领域的关系

- **检索增强生成（Retrieval-Augmented Generation, RAG）**：RAG 与提示词压缩密切相关。RAG 可以被视为一个外部压缩阶段：它不是处理整个数据库，而是搜索并选择相关的文档。提示词压缩是对 RAG 的补充，它在将已检索到的文档送入 LLM 之前进一步减少其体积。
- **In-Context Learning**：上下文中的示例（demonstrations）会显著增加提示词的长度。压缩这些示例（例如，通过“指令蒸馏”*Instruction Distillation*，即用一条简短的指令代替多个示例）是一个活跃的研究领域。

## 参考文献

- Ali, M. et al. (2024). *Prompt-SAW: Semantic-Aware Winnowing for Prompt Compression*. <a href="https://arxiv.org/abs/2403.00000" class="external text" rel="nofollow">arXiv:2403.00000</a>.
- Gao, J.; Cao, Z.; Li, W. (2024). *SelfCP: Compressing Over-Limit Prompt via the Frozen Large Language Model Itself*. <a href="https://arxiv.org/abs/2405.17052" class="external text" rel="nofollow">arXiv:2405.17052</a>.
- Jiang, H. et al. (2023). *LLMLingua: Compressing Prompts for Accelerated Inference of Large Language Models*. <a href="https://arxiv.org/abs/2310.05736" class="external text" rel="nofollow">arXiv:2310.05736</a>.
- Jiang, H. et al. (2023). *LongLLMLingua: Accelerating and Enhancing LLMs in Long-Context Scenarios via Prompt Compression*. <a href="https://arxiv.org/abs/2310.06839" class="external text" rel="nofollow">arXiv:2310.06839</a>.
- Jung, H.; Kim, K. (2023). *PCRL: Discrete Prompt Compression with Reinforcement Learning*. <a href="https://arxiv.org/abs/2308.08758" class="external text" rel="nofollow">arXiv:2308.08758</a>.
- Li, M. et al. (2023). *Selective-Context: Compressing Context to Summarise and Answer Questions*. <a href="https://arxiv.org/abs/2307.00000" class="external text" rel="nofollow">arXiv:2307.00000</a>.
- Mu, J. et al. (2023). *Learning to Compress Prompts with Gist Tokens*. <a href="https://papers.nips.cc/paper_files/paper/2023/hash/3d77c6dcc7f143aa2154e7f4d5e22d68-Abstract-Conference.html" class="external text" rel="nofollow">NeurIPS 2023</a>.
- Xu, F.; Shi, W.; Choi, E. (2023). *RECOMP: Improving Retrieval-Augmented LMs with Compression and Selective Augmentation*. <a href="https://arxiv.org/abs/2310.04408" class="external text" rel="nofollow">arXiv:2310.04408</a>.
- Yang, C. et al. (2023). *PRCA: Prompt Compression with Reinforced Context Aggregation*. <a href="https://arxiv.org/abs/2311.00000" class="external text" rel="nofollow">arXiv:2311.00000</a>.
- Yoon, J. et al. (2024). *CompAct: Interactive Prompt Compression for Long-Document QA*. <a href="https://arxiv.org/abs/2402.00000" class="external text" rel="nofollow">arXiv:2402.00000</a>.
- Zhang, S. et al. (2024). *Efficient Prompting Methods for Large Language Models: A Survey*. <a href="https://arxiv.org/abs/2404.01077" class="external text" rel="nofollow">arXiv:2404.01077</a>.
- Jha, S. et al. (2024). *Characterizing Prompt Compression Methods for Long Context Inference*. <a href="https://arxiv.org/abs/2407.08892" class="external text" rel="nofollow">arXiv:2407.08892</a>.

## 注释

1.  <span id="cite_note-jha2024-1">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-jha2024_1-0) Jha, S., et al. (2024). «Characterizing Prompt Compression Methods for Long Context Inference». *arXiv*. <a href="https://arxiv.org/html/2407.08892v1" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-survey2024-2">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-survey2024_2-0) «Efficient Prompting Methods for Large Language Models: A Survey». *arXiv*. <a href="https://arxiv.org/html/2404.01077v2" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-datacamp-guide-3">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-datacamp-guide_3-0) «Prompt Compression: A Guide With Python Examples». *DataCamp*. <a href="https://www.datacamp.com/tutorial/prompt-compression" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-jiang2023_llmlingua-4">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-jiang2023_llmlingua_4-0) Jiang, H., et al. (2023). «LLMLingua: Compressing Prompts for Accelerated Inference of Large Language Models». *arXiv*.</span>
5.  <span id="cite_note-li2023_selective-5">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-li2023_selective_5-0) Li, M. (2023). «Compressing context to summarize and answer questions». *arXiv*.</span>
6.  <span id="cite_note-jung2023_pcrl-6">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-jung2023_pcrl_6-0) Jung, H., & Kim, K. (2023). «Learning to Compress Prompts with Reinforcement Learning». *arXiv*.</span>
7.  <span id="cite_note-xu2024_recomp-7">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-xu2024_recomp_7-0) Xu, F., et al. (2024). «RECOMP: Improving Retrieval-Augmented LMs with Compression and Selective Augmentation». *arXiv*.</span>
8.  <span id="cite_note-yang2023_prca-8">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-yang2023_prca_8-0) Yang, C., et al. (2023). «PRCA: A new framework for prompt compression». *arXiv*.</span>
9.  <span id="cite_note-ali2024_promptsaw-9">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-ali2024_promptsaw_9-0) Ali, M., et al. (2024). «Prompt-SAW: A new method for prompt compression». *arXiv*.</span>
10. <span id="cite_note-pradeep2023_reranker-10">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-pradeep2023_reranker_10-0) Pradeep, R., et al. (2023). «How to select the best passages for RAG?». *arXiv*.</span>
11. <span id="cite_note-yoon2024_compact-11">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-yoon2024_compact_11-0) Yoon, J., et al. (2024). «CompAct: A new framework for interactive prompt compression». *arXiv*.</span>
12. <span id="cite_note-mu2023_gist-12">↑ <sup>[12.0](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-mu2023_gist_12-0)</sup> <sup>[12.1](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-mu2023_gist_12-1)</sup> Mu, J., et al. (2023). «Learning to Compress Prompts with Gist Tokens». *OpenReview*. <a href="https://openreview.net/forum?id=2DtxPCL3T5" class="external autonumber" rel="nofollow">[4]</a></span>
13. <span id="cite_note-gao2024_selfcp-13">[↑](https://systems-analysis.info/int/Prompt_compression_%E2%80%94_%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%8E%8B%E7%BC%A9#cite_ref-gao2024_selfcp_13-0) Gao, C., et al. (2024). «SelfCP: Compressing Over-Limit Prompt via the Frozen Large Language Model Itself». *arXiv*. <a href="https://arxiv.org/html/2405.17052v2" class="external autonumber" rel="nofollow">[5]</a></span>
