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
Metadata
Release files for kvcrush 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kvcrush-0.1.0.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kvcrush-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / kvcrush-0.1.0.tar.gz
| Download URL | kvcrush-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6594a7e1c494a6247794dd07febdf7c3d3ac8d9e9e9f2dcb2acf4a81ead1694
|
|
BLAKE2b-256 checksum How to use checksums |
47d4b040bb88b417b0225b686e2ffa8fd518f0d128c1433526a9237ce9c4b6be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.10
|
Release files / kvcrush-0.1.0-py3-none-any.whl
| Download URL | kvcrush-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
150862e7e171d97c623875e0b87f9b7fce5fc8aaa9cd6854b9a914d5016df84c
|
|
BLAKE2b-256 checksum How to use checksums |
900317cf484a2539188efb03df9e17cdc8795a5b402355a9da89a24bafb3888f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.10
|