Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

tensor_compress Benchmarks

The tensor_compress crate provides compression algorithms optimized for tensor data: Tensor Train decomposition, delta encoding, sparse vectors, and run-length encoding.

Tensor Train Decomposition (primary compression method)

OperationTimePeak RAM
tt_decompose_256d~50 us41.8 KB
tt_decompose_1024d~80 us60.9 KB
tt_decompose_4096d~120 us137.5 KB
tt_reconstruct_4096d~1.2 ms67.9 KB
tt_dot_product_4096d~400 ns69.2 KB
tt_cosine_similarity_4096d~1 us69.2 KB

Delta Encoding (10K sequential IDs)

OperationTimeThroughputPeak RAM
compress_ids8.0 us1.25M IDs/s~210 KB
decompress_ids33 us303K IDs/s~100 KB

Run-Length Encoding (100K values)

OperationTimeThroughputPeak RAM
rle_encode29 us3.4M values/s~445 KB
rle_decode38 us2.6M values/s~833 KB

Compression Ratios

Data TypeTechniqueRatioLossless
4096-dim embeddingsTensor Train10-20xNo (<1% error)
1024-dim embeddingsTensor Train4-8xNo (<1% error)
Sparse vectorsNative sparse3-32xYes
Sequential IDsDelta + varint4-8xYes
Repeated valuesRLE2-100xYes

Analysis

  • TT decomposition: Achieves 10-20x compression for high-dimensional embeddings (4096+)
  • TT operations in compressed space: Dot product and cosine similarity computed directly in TT format without full reconstruction
  • Delta encoding: Asymmetric - compression is 4x faster than decompression
  • Sparse format: Efficient for vectors with >50% zeros, stores only non-zero positions/values
  • RLE: Best for highly repeated data (status columns, category IDs)
  • Memory efficiency: All operations use < 1 MB for typical data sizes
  • Integration: Use SAVE COMPRESSED in shell or save_snapshot_compressed() API

Usage Recommendations

Data CharacteristicsRecommended Compression
High-dimensional embeddings (1024+)Tensor Train
Sparse embeddings (>50% zeros)Native sparse format
Sequential IDs (node IDs, row IDs)Delta + varint
Categorical columns with repeatsRLE
Mixed data snapshotsComposite (auto-detect)