Practical overview
When it fits
Use Semafold when a system stores or processes numeric embeddings, retrieval representations or KV tensors and you want codec-based compression with byte accounting. Consider its NumPy backend for CPU-based use, or the documented optional backends when using supported accelerator libraries.
Who it is for
- AI infrastructure teams managing embedding or retrieval data storage.
- Developers integrating vector compression into retrieval pipelines or custom inference stacks.
- Teams exploring compression of cache-shaped key/value tensors.
Documented uses
- Encode and decode embedding vectors with a vector codec.
- Measure encoded artifact size and compression ratio for a vector workload.
- Compress cache-shaped key/value tensors using the documented TurboQuant KV codec.
Requirements & limits
The repository is public and identifies the project as Apache-2.0 licensed. The README specifies Python 3.10 or later and installation through pip.
- The default NumPy backend does not require a GPU; acceleration is optional through PyTorch (CUDA/MPS) or MLX (Metal).
- TurboQuant codecs are documented as deep imports rather than stable root-package exports.
- Compression figures in the README are tied to particular benchmark inputs, codecs and bit settings; results may differ for other workloads.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Compress and decode embedding vectors with TurboQuant MSE
Encode an embedding matrix with the TurboQuant MSE codec, inspect its reported size and ratio, and decode it.
Before you start
- Python 3.10 or later, as indicated by the repository’s Python badge.
- Semafold installed, with NumPy available.
- Embedding vectors represented as a NumPy array.
Steps
Install the package with the command below.
pip install semafoldImport
EncodeMetric,EncodeObjective,VectorEncodeRequest, andVectorDecodeRequestfromsemafold; importTurboQuantMSEConfigandTurboQuantMSEVectorCodecfromsemafold.turboquant.Create a
TurboQuantMSEVectorCodecwithTurboQuantMSEConfig(default_bits_per_scalar=3, default_rotation_seed=7), then encode the embedding array using aVectorEncodeRequestwith reconstruction objective, MSE metric, roleembedding, and seed11.Decode the resulting encoding with
codec.decode(VectorDecodeRequest(encoding=encoding)); inspectencoding.footprint.total_bytesandencoding.footprint.compression_ratio, and check that the decoded array shape matches the input.
Expected outcome
The example encodes and decodes an embedding matrix and exposes the encoding’s reported byte footprint and compression ratio.
Guide limitations
- TurboQuant is currently a deep-import surface rather than part of the stable root exports.
- Compression is lossy; the README describes distortion visibility and reports results for specific benchmark workloads, not a guaranteed ratio for every input.
Compress and decode cache-shaped K/V tensors with the preview codec
Encode and decode key and value tensors using Semafold’s TurboQuant KV preview codec.
Before you start
- Python 3.10 or later, as indicated by the repository’s Python badge.
- Semafold installed, with NumPy available.
- Key and value arrays shaped as cache tensors; the README example uses
(4, 8, 256, 128).
Steps
Install the package with the command below.
pip install semafoldImport
TurboQuantKVConfigandTurboQuantKVPreviewCodecfromsemafold.turboquant.kv.Create key and value NumPy arrays and configure a
TurboQuantKVPreviewCodecwithTurboQuantKVConfig, following the repository example atexamples/turboquant_kv_block.py.Encode and decode the tensors using the preview codec, following that example.
Expected outcome
The documented example demonstrates a TurboQuant KV codec path for cache-shaped key and value tensors.
Guide limitations
- The KV codec is on the TurboQuant deep-import surface, not the stable root exports.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 15 October 2026
- Original website title
- mindtro/semafold · Official homepage title · retained in its source language

