Scripts2026年4月9日·1 分钟阅读

LLMLingua — Compress Prompts 20x with Minimal Loss

Microsoft research tool for prompt compression. Reduce token usage up to 20x while maintaining LLM performance. Solves lost-in-the-middle for RAG. MIT, 6,000+ stars.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

  1. 安装:
pip install llmlingua
  1. 压缩提示词:
from llmlingua import PromptCompressor

compressor = PromptCompressor()
result = compressor.compress_prompt(
    context=["你的长文本..."],
    instruction="总结要点。",
    target_token=500
)
print(result["compressed_prompt"])

简介

LLMLingua 是微软研究院的提示词压缩工具包,GitHub 6,000+ star,发表于 EMNLP 2023 和 ACL 2024。最高可将提示词压缩 20 倍且性能损失极小,显著节省 API 成本。对 RAG 管道中的"中间丢失"问题尤其有效。适合构建生产级 LLM 应用、需要优化 token 用量和成本的开发者。


LLMLingua — 微软研究院提示词压缩

三种方法

方法 论文 压缩率 速度
LLMLingua EMNLP 2023 最高 20x 基准
LongLLMLingua ACL 2024 4x(RAG 提升 21.4%) 相同
LLMLingua-2 ACL 2024 最高 20x 快 3-6x

性能基准

  • 通用提示词 20x 压缩,性能下降 <2%
  • RAG 任务用 1/4 token 提升 21.4%
  • LLMLingua-2 速度提升 3-6x

FAQ

Q: LLMLingua 是什么? A: 微软研究院的提示词压缩工具包,最高 20 倍压缩率,几乎不影响 LLM 性能。

Q: 免费吗? A: 完全免费开源,MIT 许可。


🙏

来源与感谢

Created by Microsoft Research. Licensed under MIT.

LLMLingua — ⭐ 6,000+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产