tokenfold 0.5.3__tar.gz → 0.5.4__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.
- {tokenfold-0.5.3 → tokenfold-0.5.4}/Cargo.lock +10 -10
- {tokenfold-0.5.3 → tokenfold-0.5.4}/Cargo.toml +1 -1
- {tokenfold-0.5.3 → tokenfold-0.5.4}/PKG-INFO +55 -49
- {tokenfold-0.5.3 → tokenfold-0.5.4}/README.md +54 -48
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-py/Cargo.toml +1 -1
- {tokenfold-0.5.3 → tokenfold-0.5.4}/LICENSE +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/Cargo.toml +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/README.md +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/benches/THRESHOLDS.toml +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/benches/compression_bench.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/allocation.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/budget.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/codec.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/errors.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/filters.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/holdout.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/input.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/lib.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/measurement.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/modes.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/pipeline/mod.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/pipeline/tests.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/profiles.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/report.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/retrieval_store.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/safety.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/stats.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/status.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/token_estimator.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/diff.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/json.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/json_dict.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/json_fold.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/json_prune.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/log_fold.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/logs.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/mod.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/redaction.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/src/transforms/schema.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/tests/golden.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/tests/integration.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-core/tests/property_tests.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/crates/tokenfold-py/src/lib.rs +0 -0
- {tokenfold-0.5.3 → tokenfold-0.5.4}/pyproject.toml +0 -0
|
@@ -1109,7 +1109,7 @@ dependencies = [
|
|
|
1109
1109
|
|
|
1110
1110
|
[[package]]
|
|
1111
1111
|
name = "tokenfold-adapters"
|
|
1112
|
-
version = "0.5.
|
|
1112
|
+
version = "0.5.4"
|
|
1113
1113
|
dependencies = [
|
|
1114
1114
|
"serde",
|
|
1115
1115
|
"serde_json",
|
|
@@ -1118,7 +1118,7 @@ dependencies = [
|
|
|
1118
1118
|
|
|
1119
1119
|
[[package]]
|
|
1120
1120
|
name = "tokenfold-admin"
|
|
1121
|
-
version = "0.5.
|
|
1121
|
+
version = "0.5.4"
|
|
1122
1122
|
dependencies = [
|
|
1123
1123
|
"ed25519-dalek",
|
|
1124
1124
|
"serde",
|
|
@@ -1128,7 +1128,7 @@ dependencies = [
|
|
|
1128
1128
|
|
|
1129
1129
|
[[package]]
|
|
1130
1130
|
name = "tokenfold-cli"
|
|
1131
|
-
version = "0.5.
|
|
1131
|
+
version = "0.5.4"
|
|
1132
1132
|
dependencies = [
|
|
1133
1133
|
"clap",
|
|
1134
1134
|
"serde",
|
|
@@ -1143,7 +1143,7 @@ dependencies = [
|
|
|
1143
1143
|
|
|
1144
1144
|
[[package]]
|
|
1145
1145
|
name = "tokenfold-core"
|
|
1146
|
-
version = "0.5.
|
|
1146
|
+
version = "0.5.4"
|
|
1147
1147
|
dependencies = [
|
|
1148
1148
|
"proptest",
|
|
1149
1149
|
"regex",
|
|
@@ -1158,25 +1158,25 @@ dependencies = [
|
|
|
1158
1158
|
|
|
1159
1159
|
[[package]]
|
|
1160
1160
|
name = "tokenfold-image"
|
|
1161
|
-
version = "0.5.
|
|
1161
|
+
version = "0.5.4"
|
|
1162
1162
|
|
|
1163
1163
|
[[package]]
|
|
1164
1164
|
name = "tokenfold-learn"
|
|
1165
|
-
version = "0.5.
|
|
1165
|
+
version = "0.5.4"
|
|
1166
1166
|
dependencies = [
|
|
1167
1167
|
"tokenfold-core",
|
|
1168
1168
|
]
|
|
1169
1169
|
|
|
1170
1170
|
[[package]]
|
|
1171
1171
|
name = "tokenfold-output"
|
|
1172
|
-
version = "0.5.
|
|
1172
|
+
version = "0.5.4"
|
|
1173
1173
|
dependencies = [
|
|
1174
1174
|
"tokenfold-core",
|
|
1175
1175
|
]
|
|
1176
1176
|
|
|
1177
1177
|
[[package]]
|
|
1178
1178
|
name = "tokenfold-proxy"
|
|
1179
|
-
version = "0.5.
|
|
1179
|
+
version = "0.5.4"
|
|
1180
1180
|
dependencies = [
|
|
1181
1181
|
"clap",
|
|
1182
1182
|
"ctrlc",
|
|
@@ -1190,7 +1190,7 @@ dependencies = [
|
|
|
1190
1190
|
|
|
1191
1191
|
[[package]]
|
|
1192
1192
|
name = "tokenfold-py"
|
|
1193
|
-
version = "0.5.
|
|
1193
|
+
version = "0.5.4"
|
|
1194
1194
|
dependencies = [
|
|
1195
1195
|
"pyo3",
|
|
1196
1196
|
"serde_json",
|
|
@@ -1199,7 +1199,7 @@ dependencies = [
|
|
|
1199
1199
|
|
|
1200
1200
|
[[package]]
|
|
1201
1201
|
name = "tokenfold-rag"
|
|
1202
|
-
version = "0.5.
|
|
1202
|
+
version = "0.5.4"
|
|
1203
1203
|
dependencies = [
|
|
1204
1204
|
"tokenfold-core",
|
|
1205
1205
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tokenfold
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.4
|
|
4
4
|
Classifier: Development Status :: 4 - Beta
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -47,20 +47,7 @@ Tokenfold Select ranks the context that matters most when token budgets get tigh
|
|
|
47
47
|
|
|
48
48
|
</div>
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- [Installation](#installation)
|
|
53
|
-
- [How it works](#how-it-works)
|
|
54
|
-
- [Quick start](#quick-start)
|
|
55
|
-
- [MCP & agents](#coding-agents-and-mcp-integration)
|
|
56
|
-
- [Core](#tokenfold-core)
|
|
57
|
-
- [Select](#tokenfold-select)
|
|
58
|
-
- [Benchmarks](#measured-results)
|
|
59
|
-
- [Extended tooling](#extended-tooling)
|
|
60
|
-
- [Safety and auditability](#safety-and-auditability)
|
|
61
|
-
- [Reproduce the results](#reproduce-the-results)
|
|
62
|
-
- [Contributing](#contributing)
|
|
63
|
-
- [License](#license)
|
|
50
|
+
[Install](#installation) | [Quick start](#quick-start) | [How it works](#how-it-works) | [MCP & agents](#coding-agents-and-mcp-integration) | [Core](#tokenfold-core) | [Select](#tokenfold-select) | [Benchmarks](#measured-results) | [Safety](#safety-and-auditability)
|
|
64
51
|
|
|
65
52
|
<br />
|
|
66
53
|
|
|
@@ -73,6 +60,9 @@ cargo install tokenfold-cli # Standalone CLI
|
|
|
73
60
|
cargo add tokenfold-core # Rust library
|
|
74
61
|
```
|
|
75
62
|
|
|
63
|
+
These installs provide Core. For optional query-aware model scoring, see
|
|
64
|
+
[Select setup](#tokenfold-select); its models and runtime setup are separate.
|
|
65
|
+
|
|
76
66
|
<table>
|
|
77
67
|
<tr>
|
|
78
68
|
<td align="center" width="33%">
|
|
@@ -106,9 +96,18 @@ cargo add tokenfold-core # Rust library
|
|
|
106
96
|
|
|
107
97
|
## How it works
|
|
108
98
|
|
|
99
|
+
- **Core (default):** folds repeated structure without removing data. The
|
|
100
|
+
compact payload decodes to the original JSON value.
|
|
101
|
+
- **[Recoverable pruning](#recoverable-lossy-pruning) (opt-in):** model-free
|
|
102
|
+
rules rank eligible JSON rows; omissions are stored locally before replacement
|
|
103
|
+
with `$tf_ref` handles. This is the path behind the **96.3% showcase**, not Select.
|
|
104
|
+
- **[Select](#tokenfold-select) (separate):** a model scores groups against your
|
|
105
|
+
query; your allocator keeps selected original text under a token budget.
|
|
106
|
+
Select does not automatically store omissions or create recovery handles.
|
|
107
|
+
|
|
109
108
|
### What the model sees
|
|
110
109
|
|
|
111
|
-
```
|
|
110
|
+
```jsonc
|
|
112
111
|
// Input (conceptual illustration - 2 rows shown; small inputs like this
|
|
113
112
|
// pass through unchanged under the never-larger guard)
|
|
114
113
|
[{"id":1,"role":"admin"},{"id":2,"role":"member"}]
|
|
@@ -143,10 +142,6 @@ object shape again.
|
|
|
143
142
|
in-memory round trip before emitting; lossy pruning is strictly opt-in and
|
|
144
143
|
recoverable.
|
|
145
144
|
|
|
146
|
-
For tabular arrays, Tokenfold folds repeated keys into
|
|
147
|
-
header columns (`__tf_cols__`). No model runs in the Core engine, and every
|
|
148
|
-
lossless transform is verified by exact decode.
|
|
149
|
-
|
|
150
145
|
#### How Tokenfold decides what to fold
|
|
151
146
|
|
|
152
147
|
```mermaid
|
|
@@ -196,6 +191,35 @@ inputs and provenance live in [`tests/fixtures/readme_metrics.json`](tests/fixtu
|
|
|
196
191
|
|
|
197
192
|
## Quick start
|
|
198
193
|
|
|
194
|
+
### Python: compress JSON directly
|
|
195
|
+
|
|
196
|
+
After `pip install tokenfold`, try this self-contained example. Thirty uniform
|
|
197
|
+
records provide enough repeated structure to demonstrate lossless folding:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
import json
|
|
201
|
+
from tokenfold import InputFormat, compress
|
|
202
|
+
|
|
203
|
+
records = [{"id": i, "role": "member", "status": "active"} for i in range(30)]
|
|
204
|
+
result = compress(json.dumps(records), format=InputFormat.JSON)
|
|
205
|
+
print(f"{result.report.original_tokens} -> {result.report.compressed_tokens} tokens "
|
|
206
|
+
f"({result.saved_pct():.1f}% saved)")
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Send `result.payload` (bytes) to the model. Use `tokenfold.decode` when your
|
|
210
|
+
application needs the original JSON shape again. Small or irregular inputs may
|
|
211
|
+
pass through unchanged under the never-larger guard.
|
|
212
|
+
|
|
213
|
+
### CLI: inspect and compress a file
|
|
214
|
+
|
|
215
|
+
Install the CLI with `cargo install tokenfold-cli` or use a
|
|
216
|
+
[checksummed GitHub Release](https://github.com/snchimata/tokenfold/releases/latest), then:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
tokenfold inspect payload.json --format json
|
|
220
|
+
tokenfold compress payload.json --format json --output payload.compact.json
|
|
221
|
+
```
|
|
222
|
+
|
|
199
223
|
### Drop-in proxy for OpenAI-compatible clients
|
|
200
224
|
|
|
201
225
|
Start the local proxy once, then point an existing client at it. The proxy
|
|
@@ -277,28 +301,6 @@ sequenceDiagram
|
|
|
277
301
|
| Rust | `cargo add tokenfold-core` | Native embedding |
|
|
278
302
|
| MCP | `tokenfold mcp serve` | Agents and editors |
|
|
279
303
|
|
|
280
|
-
For files and stdin, install the CLI with `cargo install tokenfold-cli` or use a
|
|
281
|
-
[checksummed GitHub Release](https://github.com/snchimata/tokenfold/releases/latest), then:
|
|
282
|
-
|
|
283
|
-
```bash
|
|
284
|
-
tokenfold inspect payload.json --format json
|
|
285
|
-
tokenfold compress payload.json --format json --output payload.compact.json
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
For direct Python calls, use the same Core engine and typed receipt:
|
|
289
|
-
|
|
290
|
-
```python
|
|
291
|
-
from tokenfold import InputFormat, compress
|
|
292
|
-
|
|
293
|
-
# Accepts raw JSON bytes or str (messages, tools, or schemas)
|
|
294
|
-
request_json_bytes = b'{"messages": [{"role": "user", "content": "hello"}]}'
|
|
295
|
-
result = compress(request_json_bytes, format=InputFormat.OPENAI_JSON)
|
|
296
|
-
|
|
297
|
-
# For standalone JSON records, use: format=InputFormat.JSON
|
|
298
|
-
compressed_payload = result.payload # bytes
|
|
299
|
-
print(f"Saved {result.report.saved_tokens} tokens ({result.saved_pct():.1f}%)")
|
|
300
|
-
```
|
|
301
|
-
|
|
302
304
|
### Presets
|
|
303
305
|
|
|
304
306
|
| Preset | Behavior |
|
|
@@ -326,11 +328,15 @@ python examples/quickstart.py # Python: compress messages, request bodies,
|
|
|
326
328
|
node examples/quickstart.mjs # TypeScript/Node: compress, inspect, read the receipt
|
|
327
329
|
cargo run -p tokenfold-core --example quickstart # Rust: the embedded core API
|
|
328
330
|
python examples/lossy_pruning.py # CLI: opt-in recoverable pruning, end to end
|
|
331
|
+
python examples/contextdoctor_report.py # source checkout: offline outcome/regression controls
|
|
329
332
|
```
|
|
330
333
|
|
|
331
334
|
[`examples/quickstart.ipynb`](examples/quickstart.ipynb) is the guided tour of the whole
|
|
332
335
|
Python surface: everything `quickstart.py` shows, plus previews, budgets and presets,
|
|
333
|
-
provider payloads, recoverable pruning
|
|
336
|
+
provider payloads, recoverable pruning previews, and the offline ContextDoctor controls.
|
|
337
|
+
Its separately provisioned Select v3 CUDA example is explicitly enabled; set
|
|
338
|
+
`RUN_SELECT_V3 = False` for a core-only tour. See the [evaluation guide](eval/README.md)
|
|
339
|
+
for ContextDoctor's source-only interface and evidence limits.
|
|
334
340
|
|
|
335
341
|
### Coding agents and MCP integration
|
|
336
342
|
|
|
@@ -395,13 +401,13 @@ not the v3 architecture or loader.
|
|
|
395
401
|
| Output | Compressed payload + exact receipt | Group relevance scores; caller-owned allocation |
|
|
396
402
|
|
|
397
403
|
<details>
|
|
398
|
-
<summary><strong>
|
|
404
|
+
<summary><strong>Optional tokenfold-select 0.5.4 SDK: Select v2 setup</strong></summary>
|
|
399
405
|
|
|
400
|
-
V3 is provisioned separately through its model card. The
|
|
406
|
+
V3 is provisioned separately through its model card. The version-aligned 0.5.4 SDK
|
|
401
407
|
continues to use the v2 backend below; this README update does not change it.
|
|
402
408
|
|
|
403
409
|
**Select v2 is the default scorer backend in the optional `tokenfold-select`
|
|
404
|
-
0.5.
|
|
410
|
+
0.5.4 package: local FP32 ONNX inference, original text, whole-group ranking.**
|
|
405
411
|
Provision the separate pinned model artifact, generate explicit runtime approval,
|
|
406
412
|
and invoke `tokenfold --experimental select`. Core remains model-free and
|
|
407
413
|
deterministic; installing or upgrading Tokenfold does not silently load a model
|
|
@@ -410,13 +416,13 @@ The separate model bundle also carries Safetensors weights and a custom referenc
|
|
|
410
416
|
loader; ONNX remains the CLI worker default. V2 is an experimental preview:
|
|
411
417
|
[Both formats are published under Apache-2.0](https://huggingface.co/snchimata/tokenfold-select-v2).
|
|
412
418
|
Synthetic CPU parity is verified, but task-quality and cold/warm performance
|
|
413
|
-
qualification are still open. The [example
|
|
414
|
-
|
|
419
|
+
qualification are still open. The notebook's [separate v3 CUDA example](examples/quickstart.ipynb#10-tokenfold-select-v3-local-cuda-ranking)
|
|
420
|
+
is explicitly enabled and needs a provisioned v3 bundle; it does not change this SDK's defaults.
|
|
415
421
|
|
|
416
422
|
<details>
|
|
417
423
|
<summary><strong>Python: try Tokenfold Select v2 (ONNX)</strong></summary>
|
|
418
424
|
|
|
419
|
-
Install `tokenfold-select[onnx]==0.5.
|
|
425
|
+
Install `tokenfold-select[onnx]==0.5.4` and `huggingface_hub==1.33.0`, then download
|
|
420
426
|
only the ONNX profile at the pinned release commit:
|
|
421
427
|
|
|
422
428
|
```python
|
|
@@ -25,20 +25,7 @@ Tokenfold Select ranks the context that matters most when token budgets get tigh
|
|
|
25
25
|
|
|
26
26
|
</div>
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- [Installation](#installation)
|
|
31
|
-
- [How it works](#how-it-works)
|
|
32
|
-
- [Quick start](#quick-start)
|
|
33
|
-
- [MCP & agents](#coding-agents-and-mcp-integration)
|
|
34
|
-
- [Core](#tokenfold-core)
|
|
35
|
-
- [Select](#tokenfold-select)
|
|
36
|
-
- [Benchmarks](#measured-results)
|
|
37
|
-
- [Extended tooling](#extended-tooling)
|
|
38
|
-
- [Safety and auditability](#safety-and-auditability)
|
|
39
|
-
- [Reproduce the results](#reproduce-the-results)
|
|
40
|
-
- [Contributing](#contributing)
|
|
41
|
-
- [License](#license)
|
|
28
|
+
[Install](#installation) | [Quick start](#quick-start) | [How it works](#how-it-works) | [MCP & agents](#coding-agents-and-mcp-integration) | [Core](#tokenfold-core) | [Select](#tokenfold-select) | [Benchmarks](#measured-results) | [Safety](#safety-and-auditability)
|
|
42
29
|
|
|
43
30
|
<br />
|
|
44
31
|
|
|
@@ -51,6 +38,9 @@ cargo install tokenfold-cli # Standalone CLI
|
|
|
51
38
|
cargo add tokenfold-core # Rust library
|
|
52
39
|
```
|
|
53
40
|
|
|
41
|
+
These installs provide Core. For optional query-aware model scoring, see
|
|
42
|
+
[Select setup](#tokenfold-select); its models and runtime setup are separate.
|
|
43
|
+
|
|
54
44
|
<table>
|
|
55
45
|
<tr>
|
|
56
46
|
<td align="center" width="33%">
|
|
@@ -84,9 +74,18 @@ cargo add tokenfold-core # Rust library
|
|
|
84
74
|
|
|
85
75
|
## How it works
|
|
86
76
|
|
|
77
|
+
- **Core (default):** folds repeated structure without removing data. The
|
|
78
|
+
compact payload decodes to the original JSON value.
|
|
79
|
+
- **[Recoverable pruning](#recoverable-lossy-pruning) (opt-in):** model-free
|
|
80
|
+
rules rank eligible JSON rows; omissions are stored locally before replacement
|
|
81
|
+
with `$tf_ref` handles. This is the path behind the **96.3% showcase**, not Select.
|
|
82
|
+
- **[Select](#tokenfold-select) (separate):** a model scores groups against your
|
|
83
|
+
query; your allocator keeps selected original text under a token budget.
|
|
84
|
+
Select does not automatically store omissions or create recovery handles.
|
|
85
|
+
|
|
87
86
|
### What the model sees
|
|
88
87
|
|
|
89
|
-
```
|
|
88
|
+
```jsonc
|
|
90
89
|
// Input (conceptual illustration - 2 rows shown; small inputs like this
|
|
91
90
|
// pass through unchanged under the never-larger guard)
|
|
92
91
|
[{"id":1,"role":"admin"},{"id":2,"role":"member"}]
|
|
@@ -121,10 +120,6 @@ object shape again.
|
|
|
121
120
|
in-memory round trip before emitting; lossy pruning is strictly opt-in and
|
|
122
121
|
recoverable.
|
|
123
122
|
|
|
124
|
-
For tabular arrays, Tokenfold folds repeated keys into
|
|
125
|
-
header columns (`__tf_cols__`). No model runs in the Core engine, and every
|
|
126
|
-
lossless transform is verified by exact decode.
|
|
127
|
-
|
|
128
123
|
#### How Tokenfold decides what to fold
|
|
129
124
|
|
|
130
125
|
```mermaid
|
|
@@ -174,6 +169,35 @@ inputs and provenance live in [`tests/fixtures/readme_metrics.json`](tests/fixtu
|
|
|
174
169
|
|
|
175
170
|
## Quick start
|
|
176
171
|
|
|
172
|
+
### Python: compress JSON directly
|
|
173
|
+
|
|
174
|
+
After `pip install tokenfold`, try this self-contained example. Thirty uniform
|
|
175
|
+
records provide enough repeated structure to demonstrate lossless folding:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
import json
|
|
179
|
+
from tokenfold import InputFormat, compress
|
|
180
|
+
|
|
181
|
+
records = [{"id": i, "role": "member", "status": "active"} for i in range(30)]
|
|
182
|
+
result = compress(json.dumps(records), format=InputFormat.JSON)
|
|
183
|
+
print(f"{result.report.original_tokens} -> {result.report.compressed_tokens} tokens "
|
|
184
|
+
f"({result.saved_pct():.1f}% saved)")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Send `result.payload` (bytes) to the model. Use `tokenfold.decode` when your
|
|
188
|
+
application needs the original JSON shape again. Small or irregular inputs may
|
|
189
|
+
pass through unchanged under the never-larger guard.
|
|
190
|
+
|
|
191
|
+
### CLI: inspect and compress a file
|
|
192
|
+
|
|
193
|
+
Install the CLI with `cargo install tokenfold-cli` or use a
|
|
194
|
+
[checksummed GitHub Release](https://github.com/snchimata/tokenfold/releases/latest), then:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
tokenfold inspect payload.json --format json
|
|
198
|
+
tokenfold compress payload.json --format json --output payload.compact.json
|
|
199
|
+
```
|
|
200
|
+
|
|
177
201
|
### Drop-in proxy for OpenAI-compatible clients
|
|
178
202
|
|
|
179
203
|
Start the local proxy once, then point an existing client at it. The proxy
|
|
@@ -255,28 +279,6 @@ sequenceDiagram
|
|
|
255
279
|
| Rust | `cargo add tokenfold-core` | Native embedding |
|
|
256
280
|
| MCP | `tokenfold mcp serve` | Agents and editors |
|
|
257
281
|
|
|
258
|
-
For files and stdin, install the CLI with `cargo install tokenfold-cli` or use a
|
|
259
|
-
[checksummed GitHub Release](https://github.com/snchimata/tokenfold/releases/latest), then:
|
|
260
|
-
|
|
261
|
-
```bash
|
|
262
|
-
tokenfold inspect payload.json --format json
|
|
263
|
-
tokenfold compress payload.json --format json --output payload.compact.json
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
For direct Python calls, use the same Core engine and typed receipt:
|
|
267
|
-
|
|
268
|
-
```python
|
|
269
|
-
from tokenfold import InputFormat, compress
|
|
270
|
-
|
|
271
|
-
# Accepts raw JSON bytes or str (messages, tools, or schemas)
|
|
272
|
-
request_json_bytes = b'{"messages": [{"role": "user", "content": "hello"}]}'
|
|
273
|
-
result = compress(request_json_bytes, format=InputFormat.OPENAI_JSON)
|
|
274
|
-
|
|
275
|
-
# For standalone JSON records, use: format=InputFormat.JSON
|
|
276
|
-
compressed_payload = result.payload # bytes
|
|
277
|
-
print(f"Saved {result.report.saved_tokens} tokens ({result.saved_pct():.1f}%)")
|
|
278
|
-
```
|
|
279
|
-
|
|
280
282
|
### Presets
|
|
281
283
|
|
|
282
284
|
| Preset | Behavior |
|
|
@@ -304,11 +306,15 @@ python examples/quickstart.py # Python: compress messages, request bodies,
|
|
|
304
306
|
node examples/quickstart.mjs # TypeScript/Node: compress, inspect, read the receipt
|
|
305
307
|
cargo run -p tokenfold-core --example quickstart # Rust: the embedded core API
|
|
306
308
|
python examples/lossy_pruning.py # CLI: opt-in recoverable pruning, end to end
|
|
309
|
+
python examples/contextdoctor_report.py # source checkout: offline outcome/regression controls
|
|
307
310
|
```
|
|
308
311
|
|
|
309
312
|
[`examples/quickstart.ipynb`](examples/quickstart.ipynb) is the guided tour of the whole
|
|
310
313
|
Python surface: everything `quickstart.py` shows, plus previews, budgets and presets,
|
|
311
|
-
provider payloads, recoverable pruning
|
|
314
|
+
provider payloads, recoverable pruning previews, and the offline ContextDoctor controls.
|
|
315
|
+
Its separately provisioned Select v3 CUDA example is explicitly enabled; set
|
|
316
|
+
`RUN_SELECT_V3 = False` for a core-only tour. See the [evaluation guide](eval/README.md)
|
|
317
|
+
for ContextDoctor's source-only interface and evidence limits.
|
|
312
318
|
|
|
313
319
|
### Coding agents and MCP integration
|
|
314
320
|
|
|
@@ -373,13 +379,13 @@ not the v3 architecture or loader.
|
|
|
373
379
|
| Output | Compressed payload + exact receipt | Group relevance scores; caller-owned allocation |
|
|
374
380
|
|
|
375
381
|
<details>
|
|
376
|
-
<summary><strong>
|
|
382
|
+
<summary><strong>Optional tokenfold-select 0.5.4 SDK: Select v2 setup</strong></summary>
|
|
377
383
|
|
|
378
|
-
V3 is provisioned separately through its model card. The
|
|
384
|
+
V3 is provisioned separately through its model card. The version-aligned 0.5.4 SDK
|
|
379
385
|
continues to use the v2 backend below; this README update does not change it.
|
|
380
386
|
|
|
381
387
|
**Select v2 is the default scorer backend in the optional `tokenfold-select`
|
|
382
|
-
0.5.
|
|
388
|
+
0.5.4 package: local FP32 ONNX inference, original text, whole-group ranking.**
|
|
383
389
|
Provision the separate pinned model artifact, generate explicit runtime approval,
|
|
384
390
|
and invoke `tokenfold --experimental select`. Core remains model-free and
|
|
385
391
|
deterministic; installing or upgrading Tokenfold does not silently load a model
|
|
@@ -388,13 +394,13 @@ The separate model bundle also carries Safetensors weights and a custom referenc
|
|
|
388
394
|
loader; ONNX remains the CLI worker default. V2 is an experimental preview:
|
|
389
395
|
[Both formats are published under Apache-2.0](https://huggingface.co/snchimata/tokenfold-select-v2).
|
|
390
396
|
Synthetic CPU parity is verified, but task-quality and cold/warm performance
|
|
391
|
-
qualification are still open. The [example
|
|
392
|
-
|
|
397
|
+
qualification are still open. The notebook's [separate v3 CUDA example](examples/quickstart.ipynb#10-tokenfold-select-v3-local-cuda-ranking)
|
|
398
|
+
is explicitly enabled and needs a provisioned v3 bundle; it does not change this SDK's defaults.
|
|
393
399
|
|
|
394
400
|
<details>
|
|
395
401
|
<summary><strong>Python: try Tokenfold Select v2 (ONNX)</strong></summary>
|
|
396
402
|
|
|
397
|
-
Install `tokenfold-select[onnx]==0.5.
|
|
403
|
+
Install `tokenfold-select[onnx]==0.5.4` and `huggingface_hub==1.33.0`, then download
|
|
398
404
|
only the ONNX profile at the pinned release commit:
|
|
399
405
|
|
|
400
406
|
```python
|
|
@@ -16,7 +16,7 @@ name = "tokenfold_py"
|
|
|
16
16
|
crate-type = ["cdylib", "rlib"]
|
|
17
17
|
|
|
18
18
|
[dependencies]
|
|
19
|
-
tokenfold-core = { version = "0.5.
|
|
19
|
+
tokenfold-core = { version = "0.5.4", path = "../tokenfold-core" }
|
|
20
20
|
serde_json = { workspace = true }
|
|
21
21
|
pyo3 = { version = "0.29.0", features = ["abi3-py39"] }
|
|
22
22
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|