compache 0.14.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. compache-0.14.0/LICENCE.md +202 -0
  2. compache-0.14.0/PKG-INFO +174 -0
  3. compache-0.14.0/README.md +148 -0
  4. compache-0.14.0/benchmarks/README.md +23 -0
  5. compache-0.14.0/benchmarks/beam/README.md +72 -0
  6. compache-0.14.0/benchmarks/beam/beam.py +549 -0
  7. compache-0.14.0/benchmarks/beam/run.py +89 -0
  8. compache-0.14.0/benchmarks/compare/README.md +58 -0
  9. compache-0.14.0/benchmarks/compare/live.py +406 -0
  10. compache-0.14.0/benchmarks/compare/run.py +317 -0
  11. compache-0.14.0/benchmarks/docchat/README.md +108 -0
  12. compache-0.14.0/benchmarks/docchat/docchat.py +1244 -0
  13. compache-0.14.0/benchmarks/docchat/domains.json +66 -0
  14. compache-0.14.0/benchmarks/docchat/prompts/answerer.md +1 -0
  15. compache-0.14.0/benchmarks/docchat/prompts/judge.md +9 -0
  16. compache-0.14.0/benchmarks/docchat/prompts/writer.md +14 -0
  17. compache-0.14.0/benchmarks/docchat/run.py +498 -0
  18. compache-0.14.0/benchmarks/docchat/sources.json +2561 -0
  19. compache-0.14.0/benchmarks/live/README.md +95 -0
  20. compache-0.14.0/benchmarks/live/apps.py +313 -0
  21. compache-0.14.0/benchmarks/live/run.py +1314 -0
  22. compache-0.14.0/docs/README.md +12 -0
  23. compache-0.14.0/docs/assets/compare-cost.svg +89 -0
  24. compache-0.14.0/docs/assets/compare-live.svg +61 -0
  25. compache-0.14.0/docs/assets/data/answers.json +8 -0
  26. compache-0.14.0/docs/assets/data/compare-live.json +48 -0
  27. compache-0.14.0/docs/assets/data/compare.json +93 -0
  28. compache-0.14.0/docs/assets/data/live.json +130 -0
  29. compache-0.14.0/docs/assets/data/openclaw.json +21 -0
  30. compache-0.14.0/docs/assets/data/policy-grid.json +1809 -0
  31. compache-0.14.0/docs/assets/data/requests.json +215 -0
  32. compache-0.14.0/docs/assets/data/thread.json +356 -0
  33. compache-0.14.0/docs/assets/headline.svg +36 -0
  34. compache-0.14.0/docs/assets/live-cost.svg +121 -0
  35. compache-0.14.0/docs/assets/openclaw-cost.svg +45 -0
  36. compache-0.14.0/docs/assets/policy-map.svg +151 -0
  37. compache-0.14.0/docs/assets/preview.svg +17 -0
  38. compache-0.14.0/docs/assets/requests.svg +110 -0
  39. compache-0.14.0/docs/assets/thread-dependencies.svg +188 -0
  40. compache-0.14.0/docs/assets/workflow.svg +39 -0
  41. compache-0.14.0/docs/calculator.md +73 -0
  42. compache-0.14.0/docs/comparisons.md +119 -0
  43. compache-0.14.0/docs/guide.md +278 -0
  44. compache-0.14.0/docs/how-it-works.md +78 -0
  45. compache-0.14.0/docs/integrations.md +157 -0
  46. compache-0.14.0/examples/quickstart/apply.py +42 -0
  47. compache-0.14.0/examples/quickstart/labels.jsonl +71 -0
  48. compache-0.14.0/examples/quickstart/threads.jsonl.gz +0 -0
  49. compache-0.14.0/integrations/hermes/README.md +34 -0
  50. compache-0.14.0/integrations/hermes/__init__.py +9 -0
  51. compache-0.14.0/integrations/hermes/plugin.yaml +10 -0
  52. compache-0.14.0/pyproject.toml +68 -0
  53. compache-0.14.0/pyproject.toml.orig +57 -0
  54. compache-0.14.0/scripts/figures.py +949 -0
  55. compache-0.14.0/scripts/openclaw_comparison.mjs +44 -0
  56. compache-0.14.0/scripts/pypi_readme.py +50 -0
  57. compache-0.14.0/scripts/request_sizes.py +85 -0
  58. compache-0.14.0/site/app.mjs +543 -0
  59. compache-0.14.0/site/baselines.mjs +66 -0
  60. compache-0.14.0/site/charts.mjs +55 -0
  61. compache-0.14.0/site/charts.test.mjs +36 -0
  62. compache-0.14.0/site/data.test.mjs +92 -0
  63. compache-0.14.0/site/drawn.mjs +52 -0
  64. compache-0.14.0/site/engine.mjs +662 -0
  65. compache-0.14.0/site/engine.test.mjs +150 -0
  66. compache-0.14.0/site/index.html +317 -0
  67. compache-0.14.0/site/methodology.html +145 -0
  68. compache-0.14.0/site/models.mjs +21 -0
  69. compache-0.14.0/site/models.test.mjs +42 -0
  70. compache-0.14.0/site/policy.mjs +23 -0
  71. compache-0.14.0/site/policy.test.mjs +170 -0
  72. compache-0.14.0/site/preview.png +0 -0
  73. compache-0.14.0/site/scenario.mjs +128 -0
  74. compache-0.14.0/site/scenario.test.mjs +195 -0
  75. compache-0.14.0/site/starts.mjs +8 -0
  76. compache-0.14.0/site/style.css +328 -0
  77. compache-0.14.0/site/traces.mjs +122 -0
  78. compache-0.14.0/site/worker.mjs +5 -0
  79. compache-0.14.0/skills/compache-label-dependencies/SKILL.md +55 -0
  80. compache-0.14.0/skills/compache-label-dependencies/agents/openai.yaml +4 -0
  81. compache-0.14.0/src/compache/__init__.py +54 -0
  82. compache-0.14.0/src/compache/__main__.py +3 -0
  83. compache-0.14.0/src/compache/_tls.py +47 -0
  84. compache-0.14.0/src/compache/api.py +761 -0
  85. compache-0.14.0/src/compache/cli.py +665 -0
  86. compache-0.14.0/src/compache/defaults.py +113 -0
  87. compache-0.14.0/src/compache/demo/labels.jsonl +71 -0
  88. compache-0.14.0/src/compache/demo/threads.jsonl.gz +0 -0
  89. compache-0.14.0/src/compache/errors.py +5 -0
  90. compache-0.14.0/src/compache/hermes.py +284 -0
  91. compache-0.14.0/src/compache/labels.py +336 -0
  92. compache-0.14.0/src/compache/langchain.py +65 -0
  93. compache-0.14.0/src/compache/langfuse.py +738 -0
  94. compache-0.14.0/src/compache/litellm.py +306 -0
  95. compache-0.14.0/src/compache/live.py +1443 -0
  96. compache-0.14.0/src/compache/mlflow.py +439 -0
  97. compache-0.14.0/src/compache/models.json +156 -0
  98. compache-0.14.0/src/compache/models.py +156 -0
  99. compache-0.14.0/src/compache/notes.py +365 -0
  100. compache-0.14.0/src/compache/optimizer/__init__.py +51 -0
  101. compache-0.14.0/src/compache/optimizer/cache_breaks.py +755 -0
  102. compache-0.14.0/src/compache/optimizer/contracts.py +196 -0
  103. compache-0.14.0/src/compache/optimizer/distribution.py +1384 -0
  104. compache-0.14.0/src/compache/optimizer/edit_accounting.py +324 -0
  105. compache-0.14.0/src/compache/optimizer/header_traffic.py +225 -0
  106. compache-0.14.0/src/compache/optimizer/host_ledger.py +318 -0
  107. compache-0.14.0/src/compache/optimizer/parts.py +435 -0
  108. compache-0.14.0/src/compache/optimizer/recovery.py +250 -0
  109. compache-0.14.0/src/compache/optimizer/replay.py +638 -0
  110. compache-0.14.0/src/compache/optimizer/retention.py +996 -0
  111. compache-0.14.0/src/compache/optimizer/session.py +1269 -0
  112. compache-0.14.0/src/compache/optimizer/shared_prefix.py +465 -0
  113. compache-0.14.0/src/compache/optimizer/solve.py +382 -0
  114. compache-0.14.0/src/compache/optimizer/usage.py +49 -0
  115. compache-0.14.0/src/compache/otel.py +390 -0
  116. compache-0.14.0/src/compache/profile.py +643 -0
  117. compache-0.14.0/src/compache/proxy.py +352 -0
  118. compache-0.14.0/src/compache/py.typed +0 -0
  119. compache-0.14.0/src/compache/record.py +238 -0
  120. compache-0.14.0/src/compache/threads.py +892 -0
  121. compache-0.14.0/src/compache/wire.py +1548 -0
  122. compache-0.14.0/src/compache/wrap.py +417 -0
  123. compache-0.14.0/tests/fakes.py +616 -0
  124. compache-0.14.0/tests/helpers.py +107 -0
  125. compache-0.14.0/tests/test_api.py +748 -0
  126. compache-0.14.0/tests/test_beam.py +333 -0
  127. compache-0.14.0/tests/test_cache_breaks.py +299 -0
  128. compache-0.14.0/tests/test_citation_protection.py +136 -0
  129. compache-0.14.0/tests/test_cli.py +231 -0
  130. compache-0.14.0/tests/test_defaults.py +82 -0
  131. compache-0.14.0/tests/test_distribution_planner.py +346 -0
  132. compache-0.14.0/tests/test_docchat.py +308 -0
  133. compache-0.14.0/tests/test_edit_accounting.py +274 -0
  134. compache-0.14.0/tests/test_header_traffic.py +142 -0
  135. compache-0.14.0/tests/test_hermes.py +455 -0
  136. compache-0.14.0/tests/test_labels.py +221 -0
  137. compache-0.14.0/tests/test_langfuse.py +705 -0
  138. compache-0.14.0/tests/test_litellm.py +442 -0
  139. compache-0.14.0/tests/test_live.py +1699 -0
  140. compache-0.14.0/tests/test_mlflow.py +863 -0
  141. compache-0.14.0/tests/test_notes.py +208 -0
  142. compache-0.14.0/tests/test_otel.py +557 -0
  143. compache-0.14.0/tests/test_ping_continuation.py +221 -0
  144. compache-0.14.0/tests/test_ping_endpoint_payoff.py +134 -0
  145. compache-0.14.0/tests/test_ping_private_suffix.py +292 -0
  146. compache-0.14.0/tests/test_ping_receipts.py +701 -0
  147. compache-0.14.0/tests/test_profile.py +234 -0
  148. compache-0.14.0/tests/test_proxy.py +364 -0
  149. compache-0.14.0/tests/test_quickstart.py +173 -0
  150. compache-0.14.0/tests/test_record.py +236 -0
  151. compache-0.14.0/tests/test_reopen_tool.py +280 -0
  152. compache-0.14.0/tests/test_replay.py +429 -0
  153. compache-0.14.0/tests/test_request_tariff.py +56 -0
  154. compache-0.14.0/tests/test_retention_recipe.py +675 -0
  155. compache-0.14.0/tests/test_session.py +205 -0
  156. compache-0.14.0/tests/test_session_accounting.py +292 -0
  157. compache-0.14.0/tests/test_shared_prefix.py +244 -0
  158. compache-0.14.0/tests/test_solve.py +246 -0
  159. compache-0.14.0/tests/test_threads.py +515 -0
  160. compache-0.14.0/tests/test_usage_snapshot.py +45 -0
  161. compache-0.14.0/tests/test_wire.py +866 -0
  162. compache-0.14.0/tests/test_within_run_calls.py +207 -0
  163. compache-0.14.0/tests/test_wrap.py +545 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: compache
3
+ Version: 0.14.0
4
+ Summary: Fit prompt caching and context compaction to your own conversation traces.
5
+ Keywords: llm,prompt-caching,context-compaction,context-engineering,token-cost,openai,anthropic,claude,gemini,langchain,litellm,hermes-agent,langfuse
6
+ Author: Richard Debets
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENCE.md
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.11
20
+ Project-URL: Homepage, https://github.com/BarendPotijk/compache
21
+ Project-URL: Documentation, https://github.com/BarendPotijk/compache/blob/main/docs/guide.md
22
+ Project-URL: Calculator, https://barendpotijk.github.io/compache/
23
+ Project-URL: Source, https://github.com/BarendPotijk/compache
24
+ Project-URL: Issues, https://github.com/BarendPotijk/compache/issues
25
+ Description-Content-Type: text/markdown
26
+
27
+ # compache
28
+
29
+ **Stop paying for your whole chat history on every message.**
30
+
31
+ [![Tests](https://github.com/BarendPotijk/compache/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/BarendPotijk/compache/actions/workflows/tests.yml) ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-2a78d6) ![No dependencies](https://img.shields.io/badge/dependencies-none-2a78d6) [![Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-2a78d6)](https://github.com/BarendPotijk/compache/blob/v0.14.0/LICENCE.md)
32
+
33
+ compache sits between your chatbot and the model API. It learns from your own conversations which parts of the history still matter and when your users come back, then sends less and caches better. The rest of your application stays as it is.
34
+
35
+ ![Billed per 1,000 user messages on Claude Haiku 5.5: $2.68 without compache, $1.45 with. Right answers out of 208: 125 without, 135 with](https://raw.githubusercontent.com/BarendPotijk/compache/v0.14.0/docs/assets/headline.svg)
36
+
37
+ [Get started](https://github.com/BarendPotijk/compache/tree/v0.14.0#get-started) · [Works with](https://github.com/BarendPotijk/compache/tree/v0.14.0#works-with) · [Results](https://github.com/BarendPotijk/compache/tree/v0.14.0#results) · [Cost calculator](https://barendpotijk.github.io/compache/) · [Docs](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/README.md)
38
+
39
+ ## Why long chats get expensive
40
+
41
+ Models have no memory, so your app sends the whole conversation with every message: each question, each answer, each document it ever retrieved. There are two ways to pay less, and **they work against each other**:
42
+
43
+ - **Prompt caching** makes repeated text cheap, until the user takes a break and the cache expires. On Claude that takes five minutes.
44
+ - **Trimming** (compaction) sends less text, but rewriting the history throws the cache away, and the model can lose something it needs.
45
+
46
+ compache is **compaction + cache**, decided together:
47
+
48
+ ![A 26-message chat: the whole history grows to 89k tokens, compache sends at most 25k. It trims on every message where the cache had expired, and pings keep the cache warm through other breaks](https://raw.githubusercontent.com/BarendPotijk/compache/v0.14.0/docs/assets/requests.svg)
49
+
50
+ - **Trims at the right moment.** When the cache has expired, the history has to be paid for in full anyway. That is when compache trims it.
51
+ - **Keeps the cache warm.** While a user is away for a short break, a tiny request (a ping) keeps the cache alive, if that costs less than losing it. Where your users stay away longer, it asks Claude for its one-hour cache instead.
52
+ - **Keeps the rest in reach.** Trimmed text leaves a short notice. When the model needs it, it can fetch it back before your app sees the reply.
53
+
54
+ ## Get started
55
+
56
+ ```sh
57
+ pip install compache
58
+ ```
59
+
60
+ **1. Record.** One line around the client you already have. Your requests and replies do not change.
61
+
62
+ ```python
63
+ import compache
64
+ from anthropic import Anthropic
65
+
66
+ client = compache.wrap(Anthropic(), record="compache-record", sample=0.1)
67
+ ```
68
+
69
+ The record holds sizes, times and token usage, **never text**. For one message in ten, the model is asked afterwards which earlier parts its reply needed, which adds about 5% to the bill while you record. In our runs some 600 messages were enough.
70
+
71
+ **2. Fit.** compache prices every candidate setting on your own traffic and prints what you would save, before anything in your app changes.
72
+
73
+ ```sh
74
+ compache fit compache-record --model claude-haiku-5-5
75
+ ```
76
+
77
+ **3. Apply.** Same line, with the result.
78
+
79
+ ```python
80
+ client = compache.wrap(Anthropic(), "policy.json")
81
+ ```
82
+
83
+ That is all. There are no thresholds to tune.
84
+
85
+ <details>
86
+ <summary><b>Try it now</b>, on four sample chats in a few seconds, without an API key</summary>
87
+
88
+ ```sh
89
+ compache demo -o policy.json
90
+ ```
91
+
92
+ ```text
93
+ Fitted on 4 sample threads, 71 turns (71 labelled) for claude-sonnet-5-5.
94
+
95
+ Keep questions from the last 4 turns, answers from the last 9 turns and retrieved text from the last turn.
96
+ Send up to 1 keep-warm ping while a user is away.
97
+ 82% of what the labelled turns need from earlier turns stays in view. The rest is fetched back, and that call is in the cost.
98
+ $16.10 per 1,000 turns against $50.25 keeping everything: 68% less.
99
+ Caching alone, at its best, would cost $18.66.
100
+
101
+ Wrote policy.json
102
+ ```
103
+
104
+ In a clone of this repository, `python examples/quickstart/apply.py` then plays one of those chats, the one in the figure above, message by message.
105
+ </details>
106
+
107
+ <details>
108
+ <summary><b>Already have chat logs?</b> Skip the recording</summary>
109
+
110
+ ```sh
111
+ compache pull langfuse -o threads.jsonl.gz # or: mlflow, otel. Your own chat log works as it is
112
+ compache fit threads.jsonl.gz --labels labels.jsonl --model claude-haiku-5-5
113
+ ```
114
+
115
+ Labels say, for a sample of messages, which earlier parts were needed. A [coding-agent skill](https://github.com/BarendPotijk/compache/blob/v0.14.0/skills/compache-label-dependencies/SKILL.md) writes them. Without labels compache keeps the whole history and tunes the pings. [Guide](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/guide.md)
116
+ </details>
117
+
118
+ ## Works with
119
+
120
+ | Your stack | What you add |
121
+ |---|---|
122
+ | OpenAI, Anthropic and Google GenAI SDKs, sync, async and streaming | `compache.wrap(client, "policy.json")` |
123
+ | LangChain and LangGraph on `ChatOpenAI` | `compache.langchain.clients(...)` and `middleware()` |
124
+ | OpenAI Agents SDK, Pydantic AI, LlamaIndex, Agno, AutoGen, Strands, Haystack, Langfuse's OpenAI drop-in | The wrapped client, [one line each](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/integrations.md#python-frameworks) |
125
+ | LiteLLM | `compache.litellm.install(...)`, or a callback in your LiteLLM proxy |
126
+ | Hermes | `context.engine: compache` |
127
+ | Anything with a base URL: the Vercel AI SDK, OpenClaw and other agent harnesses | `compache proxy --policy policy.json` |
128
+ | Your own prompt assembly | `policy.session(thread_id)` |
129
+
130
+ Everything runs in your own process and talks only to your model provider. No state is kept outside the process, so trimming works in serverless functions and across deploys. Keep-warm pings need a process that stays up; without one, fit with `ping_counts=(0,)`. A request the provider refuses after compache changed it is sent again as your app wrote it. [All integrations](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/integrations.md)
131
+
132
+ ## Why learn it from your data?
133
+
134
+ Because every chatbot needs a different answer. Three workloads, three settings, each priced by the provider's cache rules on conversations compache had not seen, against sending everything:
135
+
136
+ | Chatbot | What compache learned | Cost |
137
+ |:--|:--|:-:|
138
+ | **Chat with documents** ([DocChat](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/docchat/README.md)) | Questions and answers matter for long. Retrieved text is rarely needed after one message, so it goes | **43%&nbsp;to&nbsp;89%&nbsp;less** |
139
+ | **Long personal chats** ([BEAM](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/beam/README.md)) | What the user said matters. Earlier replies of the assistant can go | **57%&nbsp;to&nbsp;91%&nbsp;less** |
140
+ | **Data analysis** ([LongDS](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/README.md)) | Almost every step builds on earlier ones. Keep nearly everything, and time the pings | **0%&nbsp;to&nbsp;32%&nbsp;less** |
141
+
142
+ On DocChat that is against Claude's 5-minute cache, and against its 1-hour cache [30% to 79%](https://github.com/BarendPotijk/compache/tree/v0.14.0#results). How long users stay away matters as much. The same document chats, with three kinds of users:
143
+
144
+ ![The same chats with users who return after 30 seconds, 4 minutes and 30 minutes: sending everything costs 1.8, 5.9 and 8.9 times what compache's setting costs](https://raw.githubusercontent.com/BarendPotijk/compache/v0.14.0/docs/assets/policy-map.svg)
145
+
146
+ A fixed rule such as "keep the last 20 messages" or "summarize at 75% of the window" is one setting for all of these.
147
+
148
+ ## Results
149
+
150
+ | | Measured on | Cost |
151
+ |:--|:--|:-:|
152
+ | **Claude Haiku 5.5**, against the 5-minute cache | Live calls, billed, four integrations | **42%&nbsp;to&nbsp;49%&nbsp;less** |
153
+ | **Claude Haiku 5.5**, against the 1-hour cache | Live calls, billed, short chats | **18%&nbsp;less** |
154
+ | **GPT-6 Luna**, against the 30-minute cache | Live calls, billed, one integration | **2%&nbsp;to&nbsp;5%&nbsp;less** |
155
+ | **Claude Sonnet 5.5**, against the 5-minute cache | DocChat, modeled cost | **43%&nbsp;to&nbsp;89%&nbsp;less** |
156
+ | **Claude Sonnet 5.5**, against the 1-hour cache | DocChat, modeled cost | **30%&nbsp;to&nbsp;79%&nbsp;less** |
157
+
158
+ **It pays off most** in long chats with a lot of retrieved or tool text, where users pause longer than the cache lasts. **It pays off least** in short chats and where the cache outlasts the breaks: on GPT-6 Luna these users were always back in time, so there was little to save. If your app already uses Claude's 1-hour cache, the 1-hour row is yours: its writes cost more and its entries last longer, so there is less left to save, most of all in short chats. [The long cache](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md#the-long-cache)
159
+
160
+ **Answers hold up.** In every measurement, the number of right answers with and without compache differs by no more than chance. On GPT-6 Luna it was slightly lower, on too few messages to call. [Live runs](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/live/README.md) · [All benchmarks](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/README.md)
161
+
162
+ **What would you save?** Put your numbers in the [cost calculator](https://barendpotijk.github.io/compache/), or drop a chat log or a `policy.json` on it: it is read in your browser and sent nowhere. It compares with your own rules, other tools' defaults or what you pay now.
163
+
164
+ ## Next to what you already use
165
+
166
+ | You use | compache adds |
167
+ |---|---|
168
+ | Prompt caching, the 1-hour cache included | What to do when the cache is about to expire, and what to drop once it has |
169
+ | Keep the last N messages, or summarize at a threshold | N learned per kind of text, cuts timed to the cache, and trimmed text the model can fetch back |
170
+ | OpenClaw or provider compaction at fixed thresholds | A setting fitted to your traffic. Modeled on Claude Sonnet 5.5, [48% to 54% cheaper than OpenClaw's defaults](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md#openclaw) |
171
+ | A cache tool such as caching.ai, or one-hour cache entries | Sending less. Modeled on document chats, [30% to 70% cheaper](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md) than the cheapest cache setting alone |
172
+ | Headroom or OptScale Kompressor | They shrink single tool results, compache decides which parts stay and when the cache is kept warm. Live on document chats, [36% and 26% cheaper](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md#live) with the answers of the whole history |
173
+
174
+ [Guide](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/guide.md) · [Integrations](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/integrations.md) · [How it works](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/how-it-works.md) · [Other tools compared](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md) · [Calculator](https://barendpotijk.github.io/compache/) · [Issues](https://github.com/BarendPotijk/compache/issues) · [Apache-2.0](https://github.com/BarendPotijk/compache/blob/v0.14.0/LICENCE.md)
@@ -0,0 +1,148 @@
1
+ # compache
2
+
3
+ **Stop paying for your whole chat history on every message.**
4
+
5
+ [![Tests](https://github.com/BarendPotijk/compache/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/BarendPotijk/compache/actions/workflows/tests.yml) ![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-2a78d6) ![No dependencies](https://img.shields.io/badge/dependencies-none-2a78d6) [![Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-2a78d6)](https://github.com/BarendPotijk/compache/blob/v0.14.0/LICENCE.md)
6
+
7
+ compache sits between your chatbot and the model API. It learns from your own conversations which parts of the history still matter and when your users come back, then sends less and caches better. The rest of your application stays as it is.
8
+
9
+ ![Billed per 1,000 user messages on Claude Haiku 5.5: $2.68 without compache, $1.45 with. Right answers out of 208: 125 without, 135 with](https://raw.githubusercontent.com/BarendPotijk/compache/v0.14.0/docs/assets/headline.svg)
10
+
11
+ [Get started](https://github.com/BarendPotijk/compache/tree/v0.14.0#get-started) · [Works with](https://github.com/BarendPotijk/compache/tree/v0.14.0#works-with) · [Results](https://github.com/BarendPotijk/compache/tree/v0.14.0#results) · [Cost calculator](https://barendpotijk.github.io/compache/) · [Docs](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/README.md)
12
+
13
+ ## Why long chats get expensive
14
+
15
+ Models have no memory, so your app sends the whole conversation with every message: each question, each answer, each document it ever retrieved. There are two ways to pay less, and **they work against each other**:
16
+
17
+ - **Prompt caching** makes repeated text cheap, until the user takes a break and the cache expires. On Claude that takes five minutes.
18
+ - **Trimming** (compaction) sends less text, but rewriting the history throws the cache away, and the model can lose something it needs.
19
+
20
+ compache is **compaction + cache**, decided together:
21
+
22
+ ![A 26-message chat: the whole history grows to 89k tokens, compache sends at most 25k. It trims on every message where the cache had expired, and pings keep the cache warm through other breaks](https://raw.githubusercontent.com/BarendPotijk/compache/v0.14.0/docs/assets/requests.svg)
23
+
24
+ - **Trims at the right moment.** When the cache has expired, the history has to be paid for in full anyway. That is when compache trims it.
25
+ - **Keeps the cache warm.** While a user is away for a short break, a tiny request (a ping) keeps the cache alive, if that costs less than losing it. Where your users stay away longer, it asks Claude for its one-hour cache instead.
26
+ - **Keeps the rest in reach.** Trimmed text leaves a short notice. When the model needs it, it can fetch it back before your app sees the reply.
27
+
28
+ ## Get started
29
+
30
+ ```sh
31
+ pip install compache
32
+ ```
33
+
34
+ **1. Record.** One line around the client you already have. Your requests and replies do not change.
35
+
36
+ ```python
37
+ import compache
38
+ from anthropic import Anthropic
39
+
40
+ client = compache.wrap(Anthropic(), record="compache-record", sample=0.1)
41
+ ```
42
+
43
+ The record holds sizes, times and token usage, **never text**. For one message in ten, the model is asked afterwards which earlier parts its reply needed, which adds about 5% to the bill while you record. In our runs some 600 messages were enough.
44
+
45
+ **2. Fit.** compache prices every candidate setting on your own traffic and prints what you would save, before anything in your app changes.
46
+
47
+ ```sh
48
+ compache fit compache-record --model claude-haiku-5-5
49
+ ```
50
+
51
+ **3. Apply.** Same line, with the result.
52
+
53
+ ```python
54
+ client = compache.wrap(Anthropic(), "policy.json")
55
+ ```
56
+
57
+ That is all. There are no thresholds to tune.
58
+
59
+ <details>
60
+ <summary><b>Try it now</b>, on four sample chats in a few seconds, without an API key</summary>
61
+
62
+ ```sh
63
+ compache demo -o policy.json
64
+ ```
65
+
66
+ ```text
67
+ Fitted on 4 sample threads, 71 turns (71 labelled) for claude-sonnet-5-5.
68
+
69
+ Keep questions from the last 4 turns, answers from the last 9 turns and retrieved text from the last turn.
70
+ Send up to 1 keep-warm ping while a user is away.
71
+ 82% of what the labelled turns need from earlier turns stays in view. The rest is fetched back, and that call is in the cost.
72
+ $16.10 per 1,000 turns against $50.25 keeping everything: 68% less.
73
+ Caching alone, at its best, would cost $18.66.
74
+
75
+ Wrote policy.json
76
+ ```
77
+
78
+ In a clone of this repository, `python examples/quickstart/apply.py` then plays one of those chats, the one in the figure above, message by message.
79
+ </details>
80
+
81
+ <details>
82
+ <summary><b>Already have chat logs?</b> Skip the recording</summary>
83
+
84
+ ```sh
85
+ compache pull langfuse -o threads.jsonl.gz # or: mlflow, otel. Your own chat log works as it is
86
+ compache fit threads.jsonl.gz --labels labels.jsonl --model claude-haiku-5-5
87
+ ```
88
+
89
+ Labels say, for a sample of messages, which earlier parts were needed. A [coding-agent skill](https://github.com/BarendPotijk/compache/blob/v0.14.0/skills/compache-label-dependencies/SKILL.md) writes them. Without labels compache keeps the whole history and tunes the pings. [Guide](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/guide.md)
90
+ </details>
91
+
92
+ ## Works with
93
+
94
+ | Your stack | What you add |
95
+ |---|---|
96
+ | OpenAI, Anthropic and Google GenAI SDKs, sync, async and streaming | `compache.wrap(client, "policy.json")` |
97
+ | LangChain and LangGraph on `ChatOpenAI` | `compache.langchain.clients(...)` and `middleware()` |
98
+ | OpenAI Agents SDK, Pydantic AI, LlamaIndex, Agno, AutoGen, Strands, Haystack, Langfuse's OpenAI drop-in | The wrapped client, [one line each](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/integrations.md#python-frameworks) |
99
+ | LiteLLM | `compache.litellm.install(...)`, or a callback in your LiteLLM proxy |
100
+ | Hermes | `context.engine: compache` |
101
+ | Anything with a base URL: the Vercel AI SDK, OpenClaw and other agent harnesses | `compache proxy --policy policy.json` |
102
+ | Your own prompt assembly | `policy.session(thread_id)` |
103
+
104
+ Everything runs in your own process and talks only to your model provider. No state is kept outside the process, so trimming works in serverless functions and across deploys. Keep-warm pings need a process that stays up; without one, fit with `ping_counts=(0,)`. A request the provider refuses after compache changed it is sent again as your app wrote it. [All integrations](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/integrations.md)
105
+
106
+ ## Why learn it from your data?
107
+
108
+ Because every chatbot needs a different answer. Three workloads, three settings, each priced by the provider's cache rules on conversations compache had not seen, against sending everything:
109
+
110
+ | Chatbot | What compache learned | Cost |
111
+ |:--|:--|:-:|
112
+ | **Chat with documents** ([DocChat](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/docchat/README.md)) | Questions and answers matter for long. Retrieved text is rarely needed after one message, so it goes | **43%&nbsp;to&nbsp;89%&nbsp;less** |
113
+ | **Long personal chats** ([BEAM](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/beam/README.md)) | What the user said matters. Earlier replies of the assistant can go | **57%&nbsp;to&nbsp;91%&nbsp;less** |
114
+ | **Data analysis** ([LongDS](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/README.md)) | Almost every step builds on earlier ones. Keep nearly everything, and time the pings | **0%&nbsp;to&nbsp;32%&nbsp;less** |
115
+
116
+ On DocChat that is against Claude's 5-minute cache, and against its 1-hour cache [30% to 79%](https://github.com/BarendPotijk/compache/tree/v0.14.0#results). How long users stay away matters as much. The same document chats, with three kinds of users:
117
+
118
+ ![The same chats with users who return after 30 seconds, 4 minutes and 30 minutes: sending everything costs 1.8, 5.9 and 8.9 times what compache's setting costs](https://raw.githubusercontent.com/BarendPotijk/compache/v0.14.0/docs/assets/policy-map.svg)
119
+
120
+ A fixed rule such as "keep the last 20 messages" or "summarize at 75% of the window" is one setting for all of these.
121
+
122
+ ## Results
123
+
124
+ | | Measured on | Cost |
125
+ |:--|:--|:-:|
126
+ | **Claude Haiku 5.5**, against the 5-minute cache | Live calls, billed, four integrations | **42%&nbsp;to&nbsp;49%&nbsp;less** |
127
+ | **Claude Haiku 5.5**, against the 1-hour cache | Live calls, billed, short chats | **18%&nbsp;less** |
128
+ | **GPT-6 Luna**, against the 30-minute cache | Live calls, billed, one integration | **2%&nbsp;to&nbsp;5%&nbsp;less** |
129
+ | **Claude Sonnet 5.5**, against the 5-minute cache | DocChat, modeled cost | **43%&nbsp;to&nbsp;89%&nbsp;less** |
130
+ | **Claude Sonnet 5.5**, against the 1-hour cache | DocChat, modeled cost | **30%&nbsp;to&nbsp;79%&nbsp;less** |
131
+
132
+ **It pays off most** in long chats with a lot of retrieved or tool text, where users pause longer than the cache lasts. **It pays off least** in short chats and where the cache outlasts the breaks: on GPT-6 Luna these users were always back in time, so there was little to save. If your app already uses Claude's 1-hour cache, the 1-hour row is yours: its writes cost more and its entries last longer, so there is less left to save, most of all in short chats. [The long cache](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md#the-long-cache)
133
+
134
+ **Answers hold up.** In every measurement, the number of right answers with and without compache differs by no more than chance. On GPT-6 Luna it was slightly lower, on too few messages to call. [Live runs](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/live/README.md) · [All benchmarks](https://github.com/BarendPotijk/compache/blob/v0.14.0/benchmarks/README.md)
135
+
136
+ **What would you save?** Put your numbers in the [cost calculator](https://barendpotijk.github.io/compache/), or drop a chat log or a `policy.json` on it: it is read in your browser and sent nowhere. It compares with your own rules, other tools' defaults or what you pay now.
137
+
138
+ ## Next to what you already use
139
+
140
+ | You use | compache adds |
141
+ |---|---|
142
+ | Prompt caching, the 1-hour cache included | What to do when the cache is about to expire, and what to drop once it has |
143
+ | Keep the last N messages, or summarize at a threshold | N learned per kind of text, cuts timed to the cache, and trimmed text the model can fetch back |
144
+ | OpenClaw or provider compaction at fixed thresholds | A setting fitted to your traffic. Modeled on Claude Sonnet 5.5, [48% to 54% cheaper than OpenClaw's defaults](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md#openclaw) |
145
+ | A cache tool such as caching.ai, or one-hour cache entries | Sending less. Modeled on document chats, [30% to 70% cheaper](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md) than the cheapest cache setting alone |
146
+ | Headroom or OptScale Kompressor | They shrink single tool results, compache decides which parts stay and when the cache is kept warm. Live on document chats, [36% and 26% cheaper](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md#live) with the answers of the whole history |
147
+
148
+ [Guide](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/guide.md) · [Integrations](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/integrations.md) · [How it works](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/how-it-works.md) · [Other tools compared](https://github.com/BarendPotijk/compache/blob/v0.14.0/docs/comparisons.md) · [Calculator](https://barendpotijk.github.io/compache/) · [Issues](https://github.com/BarendPotijk/compache/issues) · [Apache-2.0](https://github.com/BarendPotijk/compache/blob/v0.14.0/LICENCE.md)
@@ -0,0 +1,23 @@
1
+ # Benchmarks
2
+
3
+ One package, three workloads, three different policies. Cost is against keeping the full history, on conversations the fit did not see, under three declared return patterns: users back after 30 seconds, 4 minutes or 30 minutes at the median.
4
+
5
+ | Dataset | What it is | What the fit chose | Saving |
6
+ |---|---|---|---|
7
+ | [DocChat](docchat/README.md) | 30 document chats in five domains, 1,227 turns, with retrieval. Dependencies measured by withholding history | Keep questions and answers, keep retrieved text for one turn. 0 to 3 pings, one-hour cache entries for users who take half an hour | 43% to 89% |
8
+ | [BEAM](beam/README.md) | 90 personal chats of 130k to 1M tokens, no retrieval. Evidence from the dataset's graded questions | Keep every user message, drop earlier assistant text. 0 to 3 pings | 57% to 91% |
9
+ | LongDS | 68 data-analysis tasks of about 26k tokens. Each turn builds on the recorded work of earlier ones | Keep everything and tune the pings in five of six cases. Cut to the last 20 turns in one | 0% to 32% |
10
+
11
+ - **The policy follows the workload.** Where old retrieved text is the bulk and is rarely needed, it goes. Where assistant text is the bulk, that goes. Where almost every turn builds on earlier ones, nothing goes and only the pings are tuned.
12
+ - **Held out.** The fitted policy was the cheapest candidate on the unseen conversations in 18 of 21 cases across the three datasets, and within 3% in the other three.
13
+ - **Answers hold.** On DocChat, Claude Sonnet 5.5 answered 24 of 30 held-out turns correctly from the policy's view and 25 from the full history, on a fifth of the tokens.
14
+
15
+ Costs are modeled: every request and ping is priced with the provider's cache rules at the threads' own timestamps, and a cut pays for fetching back what it archived. DocChat and BEAM rebuild from the commands on their pages. The LongDS conversion is not in the repository.
16
+
17
+ ## Live
18
+
19
+ [Live model calls](live/README.md): DocChat conversations played at their users' pace through five ways in, and what the provider billed. On Claude Haiku 5.5 the fitted policies cut the bill by 42% to 49% with as many answers right, whether fitted on past traces or on the model's own notes. On GPT-6 Luna, whose cache outlasts these users' breaks, they saved 2% to 5%.
20
+
21
+ ## Other tools
22
+
23
+ [Compare](compare/README.md): Headroom, Kompressor and the cheapest way to keep the whole history cached, against compache. Modeled, 30% to 70% under the cheapest cache setting. Live, the lowest bill with the answers of the whole history. [Read more](../docs/comparisons.md)
@@ -0,0 +1,72 @@
1
+ # BEAM
2
+
3
+ Long personal chats with no retrieval, where almost all the tokens are assistant text. compache keeps every user message, drops earlier assistant text and saves **57% to 91%** against keeping everything.
4
+
5
+ [BEAM](https://huggingface.co/datasets/Mohammadta/BEAM) holds 90 single-thread chats of roughly 130k, 500k and 1M tokens. Each has 20 rubric-graded questions and the IDs of the messages that hold their evidence. The adapter turns it into threads, evidence labels and a fixed train/test split. Nothing from BEAM is bundled: it is licensed CC BY-SA 4.0, so converted files inherit that licence. The dialogue is LLM-generated.
6
+
7
+ ## Result
8
+
9
+ [`run.py`](run.py) fits on the training conversations of one size and one return pattern and prices the policy on that size's test conversations. Prices are 1.25 for a cache write, 0.1 for a read and 5 for output, on a 1M-token window. The saving includes the cost of fetching back what the cut loses.
10
+
11
+ | Size | Cache lifetime | Returns | Pings chosen | Keep everything, tokens per turn | Saving on test |
12
+ |---|---|---|---|---|---|
13
+ | 500K | 5 min | fast | up to 3 | 52k | 79% |
14
+ | 500K | 5 min | mixed | up to 3 | 188k | 91% |
15
+ | 500K | 5 min | slow | none | 349k | 89% |
16
+ | 500K | 30 min | fast | up to 1 | 41k | 76% |
17
+ | 500K | 30 min | mixed | up to 3 | 58k | 81% |
18
+ | 500K | 30 min | slow | up to 3 | 206k | 91% |
19
+ | 100K | 5 min | fast | up to 1 | 19k | 61% |
20
+ | 100K | 5 min | mixed | up to 3 | 59k | 83% |
21
+ | 100K | 5 min | slow | none | 102k | 85% |
22
+ | 100K | 30 min | fast | none | 17k | 57% |
23
+ | 100K | 30 min | mixed | up to 3 | 21k | 63% |
24
+ | 100K | 30 min | slow | up to 3 | 62k | 84% |
25
+
26
+ - **One cut, different pings.** Every fitted policy keeps every user message and drops earlier assistant text. The ping count is what changes with how users return.
27
+ - **Held out.** The fitted policy was the cheapest candidate on the test conversations in 10 of the 12 cases and within 0.03% in the other two.
28
+ - **What it keeps answerable.** That cut leaves 83% of the assessed test questions answerable from the view, at 8% of the tokens. Recency would not: for about 1% of questions the whole evidence lies in the last tenth of the chat, while 83% cite user messages only.
29
+
30
+ | Cut | Train: answerable | Train: tokens (with fetch-back) | Test: answerable | Test: tokens (with fetch-back) |
31
+ |---|---|---|---|---|
32
+ | Keep every user message, drop earlier assistant text | 82.5% | 8.5% (10.8%) | 83.0% | 8.2% (10.4%) |
33
+ | Also keep 200 turns of assistant text | 86.8% | 44% (51%) | | |
34
+ | Also keep 500 turns of assistant text | 90.1% | 78% (89%) | | |
35
+ | Also keep 1,000 turns of assistant text | 97.6% | 98% (104%) | 97.4% | 97% (102%) |
36
+
37
+ These are counts on recorded text. What a model recovers by reopening an archived message needs a live run.
38
+
39
+ ## Build
40
+
41
+ ```sh
42
+ REV=3205395e897e7318c7b094ef4e6047b9b82dbb03
43
+ mkdir beam
44
+ for f in 100K 500K 1M; do
45
+ curl -L -o beam/$f-00000-of-00001.parquet \
46
+ https://huggingface.co/datasets/Mohammadta/BEAM/resolve/$REV/data/$f-00000-of-00001.parquet
47
+ done
48
+ pip install pyarrow
49
+ python benchmarks/beam/beam.py --source beam --output beam-mixed --clock mixed
50
+
51
+ # one row of the table: fit on the training chats of a size, price on its test chats
52
+ PYTHONPATH=benchmarks/beam python benchmarks/beam/run.py --data beam-mixed --size 100K --ttl 300
53
+ ```
54
+
55
+ The adapter checks each file against its pinned SHA-256, every thread against the thread format and every label against what its turn could see. All 90 conversations convert in under a minute into about 150 MB: `traces/`, `labels/` and `manifest.json`, whose `threads` list names each thread's split.
56
+
57
+ | Size | Threads (train / test) | Chat turns per thread | Tokens per thread |
58
+ |---|---|---|---|
59
+ | 100K | 13 / 7 | 94 to 196 | 100k to 225k |
60
+ | 500K | 23 / 12 | 386 to 712 | 323k to 857k |
61
+ | 1M | 23 / 12 | 778 to 1,504 | 711k to 1.85M |
62
+
63
+ ## Choices
64
+
65
+ | Topic | Choice |
66
+ |---|---|
67
+ | Turns | One user message and its reply. A thread has no retrievals |
68
+ | Questions | Appended as the last 20 turns, with BEAM's reference answer as the output. BEAM asks each one independently, so fit returns on the first `chat_runs` turns only |
69
+ | Evidence | A question is assessed when each evidence ID names exactly one message. All named messages are required together. BEAM gives no span, so each quote is the first 200 characters of its message |
70
+ | Unknown | 191 questions name no evidence, 180 of them abstention questions. Four 1M conversations restart their message numbering, which leaves 41 more ambiguous. Both are labelled unknown. 1,568 questions are assessed |
71
+ | Split | Inside each size, threads are ordered by SHA-256 of `beam-split-v1:<thread_id>` and the first third is the test set |
72
+ | Clock | BEAM dates each session and times nothing inside it. A session starts at 09:00 UTC on its date. Inside it the idle gap is a declared scenario, lognormal with sigma 1.2: `fast` 30 s, `mixed` 4 min or `slow` 30 min at the median. An answer takes one second plus its length at 60 tokens a second |