Crush KV cache 6x. 1-4 bits per value, near-zero loss. Based on Google TurboQuant.
Project description
TurboQuant
Extreme compression for numerical data. 10-16x smaller. Inspired by Google's TurboQuant research.
Install
pip install turboquant # coming soon — for now, copy turboquant.py
Usage
from turboquant import TurboQuant
# Your data — prices, sensors, metrics, anything numerical
data = [99.5, 100.2, 100.8, 101.1, 100.7, ...]
# Compress
tq = TurboQuant(bits=4) # 4-bit = ~10x compression
compressed = tq.compress(data) # returns bytes
# Decompress
restored = tq.decompress(compressed)
# Check
print(f"Size: {len(data)*8:,}B -> {len(compressed):,}B ({len(data)*8/len(compressed):.0f}x)")
print(f"Error: {tq.relative_error(data, restored):.2f}%")
Compression vs Accuracy
| Bits | Compression | Best For |
|---|---|---|
| 4-bit | ~10x | Time-series storage, dashboards, approximate queries |
| 3-bit | ~13x | Pattern search, similarity matching, trend analysis |
| 2-bit | ~16x | Rough storage, directional analysis |
| 1-bit | ~32x | Sign-only — up/down classification |
How it works
- Delta encoding — stores differences between consecutive values (makes data near-zero-mean)
- Randomized Hadamard rotation — spreads variance evenly across dimensions
- Uniform quantization — maps rotated values to N-bit integers
- Bit packing — stores efficiently
The rotation is the key: most data has uneven variance across dimensions. Rotation makes it uniform, so simple quantization works without per-block scaling overhead.
When to use it
Good for:
- Storing months/years of time-series in memory instead of days
- Compressing database columns (metrics, logs, sensor readings)
- Reducing Redis/cache memory usage
- Shipping less data over the network (IoT, microservices)
- Approximate nearest-neighbor search on compressed vectors
Not for:
- Financial trading (use exact data for execution)
- Scientific computation requiring full precision
- Data where every decimal matters
Honest benchmarks
On correlated data (prices, sensors):
- 4-bit: 10.6x compression, ~3% MAPE
- 3-bit: 12.7x compression, ~2% MAPE
On uncorrelated data (random):
- 4-bit: 10.6x compression, ~6% MAPE
- Use
compress(data, use_delta=False)for uncorrelated data
API
# Full control
tq = TurboQuant(bits=4, block_size=32, seed=42)
compressed = tq.compress(data, use_delta=True)
restored = tq.decompress(compressed)
ratio = tq.ratio(data, compressed)
error = tq.error(data, restored) # Mean absolute error
pct_error = tq.relative_error(data, restored) # MAPE %
# One-liners
from turboquant import compress, decompress
compressed = compress(data, bits=4)
restored = decompress(compressed)
# Files
from turboquant import compress_file, decompress_file
compress_file("data.csv", "data.tq", bits=4)
decompress_file("data.tq", "data_restored.json")
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kvcrush-0.1.0.tar.gz.
File metadata
- Download URL: kvcrush-0.1.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6594a7e1c494a6247794dd07febdf7c3d3ac8d9e9e9f2dcb2acf4a81ead1694
|
|
| MD5 |
de6f55d0c46494c95216d8ac6cec3f9c
|
|
| BLAKE2b-256 |
47d4b040bb88b417b0225b686e2ffa8fd518f0d128c1433526a9237ce9c4b6be
|
File details
Details for the file kvcrush-0.1.0-py3-none-any.whl.
File metadata
- Download URL: kvcrush-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
150862e7e171d97c623875e0b87f9b7fce5fc8aaa9cd6854b9a914d5016df84c
|
|
| MD5 |
3492f34254490394543b2622ac529671
|
|
| BLAKE2b-256 |
900317cf484a2539188efb03df9e17cdc8795a5b402355a9da89a24bafb3888f
|