ranxianglei / billion-context
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
ranxianglei / billion-context
billion-context English | 中文 Context-compression plugin — billion-context is all you need. small context windows (100K is enough) · 5× fewer tokens · month-long single sessions (billions of tokens) · high compression quality npm install -g billion-context —prefix=~/.local
上下文压缩插件 — billion-context 是你所需要的一切。小上下文窗口(100K 足矣)· 代币减少 5 倍 · 长达一个月的单次会话(数十亿代币)· 高质量压缩 npm install -g billion-context —prefix=~/.local
Cache health at a glance: a healthy session keeps a 95–97% prefix-cache hit rate — compression itself costs ≤2%. Sustained lower? Check attribution with /acp or /acp-cache (see FAQ); usual causes, in order: upstream cache TTL expiry · model switch · a bili bug (please report) · other/unknown.
缓存健康状况一目了然:健康的会话保持 95–97% 的前缀缓存命中率 — 压缩本身的成本 ≤2%。如果持续偏低?请使用 /acp 或 /acp-cache 检查归因(参见常见问题解答);常见原因按顺序排列:上游缓存 TTL 过期 · 模型切换 · bili 错误(请报告)· 其他/未知。
Community QQ Group: 1056132097 (full) 1108730198 (full) 1129868472 (open) 📄 Paper / Preprint Model-Driven Incremental Hierarchical Compression: Training-Free Multi-Generational Context Management for Long-Lived Coding Agents (English, v0.2)
社区 QQ 群:1056132097(已满)1108730198(已满)1129868472(开放)📄 论文 / 预印本《模型驱动的增量分层压缩:面向长寿命编码代理的免训练多代上下文管理》(英文,v0.2)
📝 The paper itself is open-sourced under the MIT License as part of the codebase (paper/). It is a living document — anyone may edit it; improvements are welcome via pull request. A production-scale longitudinal study: 4.5 months, three hosts, 174,327 model calls, 18.76B cumulative input tokens (~24.7B across all hosts), zero window violations on 204,800-token models, marathon sessions of 8,584–12,049 calls.
📝 该论文本身作为代码库(paper/)的一部分在 MIT 许可下开源。这是一份动态文档 — 任何人都可以编辑;欢迎通过 pull request 提交改进。一项生产规模的纵向研究:4.5 个月,三个主机,174,327 次模型调用,187.6 亿累计输入代币(所有主机总计约 247 亿),在 204,800 代币模型上零窗口违规,马拉松式会话达 8,584–12,049 次调用。
📊 Independent Third-Party Benchmarks 1,500-Item Cross-Benchmark Evaluation (LongMemEval-S · ContextBench · MemoryAgentBench) (中文版) — head-to-head comparison of billion-context (v0.1.202) against full context and 3 RAG arms (bm25, embedding, embedding-rerank) with DeepSeek V4.1 Flash, Qwen3-Embedding-8B, Qwen3-Reranker-4B, and Pi Agent: #1 on ContextBench (0.3097 Utilized F1, -58.3% cost vs full), +16.6% over best RAG on LongMemEval-S (79.20% vs 62.60%, -71.1% independent-session cost vs full), and 100% survival on 1.48M-token MemoryAgentBench TTL (30× steady-state compression where full fails 199/199).
📊 独立第三方基准测试 1,500 项交叉基准评估(LongMemEval-S · ContextBench · MemoryAgentBench)(中文版)— billion-context (v0.1.202) 与全上下文及 3 种 RAG 方案(bm25、embedding、embedding-rerank)的正面比较,使用 DeepSeek V4.1 Flash、Qwen3-Embedding-8B、Qwen3-Reranker-4B 和 Pi Agent:在 ContextBench 上排名第一(0.3097 Utilized F1,成本比全上下文降低 58.3%),在 LongMemEval-S 上比最佳 RAG 高出 16.6%(79.20% 对 62.60%,独立会话成本比全上下文降低 71.1%),并在 1.48M 代币的 MemoryAgentBench TTL 测试中实现 100% 生存(在全上下文 199/199 失败的情况下实现 30 倍稳态压缩)。
billion-context sits between any agent and its model API, rewriting Anthropic/OpenAI streams with acp-kernel compression. The model decides when and what to compress into high-fidelity summaries — not a hard truncation limit.
billion-context 位于任何代理及其模型 API 之间,通过 acp-kernel 压缩重写 Anthropic/OpenAI 流。由模型决定何时以及将什么内容压缩为高保真摘要 — 而非硬性的截断限制。
Why Long coding sessions blow up context. Each provider charges per token, and once you pass the context window the session degrades or dies. billion-context compresses consumed conversation into layered summaries so you can run a single session for days — billions of tokens through one context window. Unlike a host’s built-in summarizer, compression here is incremental, reversible, and prefix-cache friendly: summaries are written in small ranges, can be decompressed on demand, and the cache prefix stays intact.
为什么长编码会话会撑爆上下文。每个提供商都按代币收费,一旦超过上下文窗口,会话就会降级或终止。billion-context 将已消耗的对话压缩为分层摘要,因此你可以运行单次会话数天 — 通过一个上下文窗口处理数十亿代币。与宿主内置的摘要器不同,此处的压缩是增量的、可逆的且对前缀缓存友好:摘要以小范围写入,可按需解压缩,且缓存前缀保持完整。
How it works Context-management tools The proxy injects four context-management tools into the conversation; the model calls them itself as context grows, and the proxy executes compress server-side so folded ranges stay summarized in history until restored: compress — fold a message range into a detailed summary. decompress — restore a compressed range when exact details are needed again. search_context — keyword search over compressed summaries and visible messages. acp_status — context-usage overview plus which ranges are still compressible.
工作原理 上下文管理工具 代理将四个上下文管理工具注入对话;随着上下文增长,模型会自动调用它们,代理在服务器端执行压缩,因此折叠的范围在历史记录中保持摘要状态,直到被恢复:compress — 将消息范围折叠为详细摘要。decompress — 当再次需要确切细节时恢复压缩范围。search_context — 对压缩摘要和可见消息进行关键字搜索。acp_status — 上下文使用概览以及哪些范围仍可压缩。
Which do I need? Pick by your client: Client Use pi billion-context — bili pi (launcher) or bili plugin install pi (native); standalone billion-context-pi remains usable — details: docs/clients.md opencode (1.x / 2.x) billion-context — bili opencode (launcher) or bili plugin install opencode (native); standalone opencode-acp remains usable on 1.x — full guide: OpenCode omp billion-context via bili omp (built-in plugin) or bili plugin install omp (self-spawning native plugin, no launcher) dsh bili dsh (launcher — full native plugin via —patch) or bili plugin install dsh ≡ dsh plugin —profile
我需要哪一个?根据你的客户端选择:客户端使用 pi billion-context — bili pi (启动器) 或 bili plugin install pi (原生);独立版 billion-context-pi 仍然可用 — 详情:docs/clients.md opencode (1.x / 2.x) billion-context — bili opencode (启动器) 或 bili plugin install opencode (原生);独立版 opencode-acp 在 1.x 上仍然可用 — 完整指南:OpenCode omp billion-context 通过 bili omp (内置插件) 或 bili plugin install omp (自启动原生插件,无启动器) dsh bili dsh (启动器 — 通过 —patch 实现完整原生插件) 或 bili plugin install dsh ≡ dsh plugin —profile