High-performance PyTorch Vector Quantization Engine with Lloyd-Max and QJL sign residual correction.
Project description
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.
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 tq_search-0.1.0.tar.gz.
File metadata
- Download URL: tq_search-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b58c05cc6f708a52101eff7b617acd7d2e4c0d4addd24079e850d0bc8dd5b0d
|
|
| MD5 |
df99538cf40e0d29351a50dde908f9a8
|
|
| BLAKE2b-256 |
5d7fe7d0184e68f119309f948d5e119fb6ae6b427034f3772448fdc5f6782bca
|
Provenance
The following attestation bundles were made for tq_search-0.1.0.tar.gz:
Publisher:
publish.yml on barateza/tq-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tq_search-0.1.0.tar.gz -
Subject digest:
6b58c05cc6f708a52101eff7b617acd7d2e4c0d4addd24079e850d0bc8dd5b0d - Sigstore transparency entry: 1615223782
- Sigstore integration time:
-
Permalink:
barateza/tq-search@a438bf47452cd14720105a99d38a8695ed8467c5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/barateza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a438bf47452cd14720105a99d38a8695ed8467c5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tq_search-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tq_search-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
015f8b5e7b74cd599315326dfffa2e7739536afc2832871e013749f09565cca3
|
|
| MD5 |
952e5469f023682eae7811bd0c764f80
|
|
| BLAKE2b-256 |
04dc7a6d4804cfb1d59bdd6e38d55387c4d825e51f6ee40b2e3540fd762e153c
|
Provenance
The following attestation bundles were made for tq_search-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on barateza/tq-search
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tq_search-0.1.0-py3-none-any.whl -
Subject digest:
015f8b5e7b74cd599315326dfffa2e7739536afc2832871e013749f09565cca3 - Sigstore transparency entry: 1615223783
- Sigstore integration time:
-
Permalink:
barateza/tq-search@a438bf47452cd14720105a99d38a8695ed8467c5 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/barateza
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a438bf47452cd14720105a99d38a8695ed8467c5 -
Trigger Event:
release
-
Statement type: