tq-search
High-performance PyTorch Vector Quantization Engine with Lloyd-Max codebooks and QJL sign-bit residual correction.
Overview
tq-search is a state-of-the-art vector compression and similarity search library built entirely in PyTorch. It implements the optimal quantization algorithms inspired by TurboQuant (Zandieh et al., ICLR 2026 / arXiv:2504.19874) and QJL (arXiv:2406.03482).
Unlike standard vector databases that require decompressing vector databases in RAM or VRAM to perform searches, tq-search performs asymmetric inner product similarity scoring directly on compressed 5-bit representations, reducing GPU memory usage by up to 4x–6x while keeping search results highly accurate.
Key Features
- GPU-Accelerated: Fully integrated with PyTorch, running seamlessly on CUDA and Apple Silicon MPS.
- Batched Compression & Search: Built for high-throughput similarity search, handling millions of candidate vectors concurrently.
- Asymmetric Scoring: Computes dot products directly on the compressed codebooks without decompressing residuals in memory.
- Optimal Distortion: Employs mathematically optimal Lloyd-Max codebooks fit to rotated coordinate distributions.
Installation
Install the library directly from PyPI (once published):
pip install tq-search
Or install it locally in editable mode for development:
git clone https://github.com/barateza/tq-search.git
cd tq-search
pip install -e .
Quickstart
Here is how to compress a database of embeddings and search them using tq-search:
import torch
from tq_search import TurboQuantProd
# 1. Initialize the Quantizer
# We compress 1024-dimensional embeddings into 3-bit MSE + 1-bit QJL (4 bits total)
dim = 1024
bits = 4
quantizer = TurboQuantProd(d=dim, bits=bits, device="cuda")
# 2. Compress your database vectors (Shape: [N, dim])
database_vectors = torch.randn(10000, dim, device="cuda")
# L2-normalize vectors (recommended for maximum cosine similarity accuracy)
database_vectors = database_vectors / torch.norm(database_vectors, dim=-1, keepdim=True)
compressed = quantizer.quantize(database_vectors)
# 'compressed' is a lightweight dict containing:
# - mse_indices: [N, dim] (Stage 1 indices)
# - qjl_signs: [N, dim] (Stage 2 signs)
# - residual_norm: [N] (Dynamic residual scaling factor)
# 3. Perform Asymmetric Query Search (Query remains at full precision)
query = torch.randn(1, dim, device="cuda")
query = query / torch.norm(query, dim=-1, keepdim=True)
# Directly calculate dot products across all 10,000 compressed vectors in VRAM!
scores = quantizer.inner_product(query, compressed)
print("Inner Product Scores:", scores)
Research Credits
This library is a high-performance search adaptation based on the following research papers:
- TurboQuant: "TurboQuant: Online Vector Quantization with Near-optimal Distortion Rate" (Zandieh et al., ICLR 2026) arXiv:2504.19874
- QJL Residuals: "QJL: 1-Bit Quantized JL Transform for KV Cache Quantization" (arXiv:2406.03482) arXiv:2406.03482
License
MIT License. Feel free to use, modify, and distribute.
Metadata
Release files for tq-search 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 | |
|---|---|---|---|
| tq_search-0.1.0.tar.gz | 9.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tq_search-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / tq_search-0.1.0.tar.gz
| Download URL | tq_search-0.1.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b58c05cc6f708a52101eff7b617acd7d2e4c0d4addd24079e850d0bc8dd5b0d
|
|
BLAKE2b-256 checksum How to use checksums |
5d7fe7d0184e68f119309f948d5e119fb6ae6b427034f3772448fdc5f6782bca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logRelease files / tq_search-0.1.0-py3-none-any.whl
| Download URL | tq_search-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
015f8b5e7b74cd599315326dfffa2e7739536afc2832871e013749f09565cca3
|
|
BLAKE2b-256 checksum How to use checksums |
04dc7a6d4804cfb1d59bdd6e38d55387c4d825e51f6ee40b2e3540fd762e153c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency log