TurboQuant Tools
MCP server for compressing AI embeddings by 5-7x using TurboQuant (PolarQuant + QJL), with tools to compress, decompress, estimate savings, and embed+compress vectors.
README
🧊 TurboQuant Tools
Compress AI embeddings by 5–7× with near-lossless quality.
CLI + Python Library + MCP Server for extreme vector compression using Google's TurboQuant (PolarQuant + QJL) — wrapped in a clean numpy-first API.
🚀 Quick Start
pip install turboquant-tools
Compress a .npy embedding file:
turboquant compress embeddings.npy compressed.tq
Restore:
turboquant decompress compressed.tq restored.npy
Estimate savings:
turboquant estimate embeddings.npy --bits 3
# Original: 153.00 MB -> Compressed: 20.13 MB (7.60×, save 87%)
📦 What's Inside
| Command / Tool | Description |
|---|---|
turboquant compress |
Compress .npy embeddings → .tq binary |
turboquant decompress |
Restore .tq → .npy |
turboquant estimate |
Predict compression ratio before running |
turboquant mcp-server |
MCP stdio server (AI agent integration) |
Python compress() |
Compress numpy arrays in code |
Python decompress() |
Restore in code |
🔧 CLI Reference
compress
turboquant compress INPUT [OUTPUT] [OPTIONS]
| Option | Default | Description |
|---|---|---|
INPUT |
— | .npy file with float32 embeddings (n, d) |
OUTPUT |
{stem}_tq{b}.tq |
Output .tq file |
-b, --bits |
3 |
Bit width (3 or 4) |
-o, --output |
— | Alternative to positional OUTPUT |
--no-qjl |
off | Skip QJL correction (faster, lower quality) |
Examples:
# Basic 3-bit compression
turboquant compress wiki_embeddings.npy wiki.tq
# 4-bit compression (higher quality)
turboquant compress embeddings.npy -b 4
# Fast mode (no QJL)
turboquant compress big_set.npy -b 3 --no-qjl
decompress
turboquant decompress INPUT [OUTPUT]
estimate
turboquant estimate INPUT [--bits N]
🐍 Python API
from turboquant_tools import compress, decompress, estimate_savings
import numpy as np
# Load or generate embeddings
vectors = np.random.randn(10000, 384).astype(np.float32)
# Compress (5–7× reduction)
compressed = compress(vectors, bits=3, use_qjl=False)
print(f"{vectors.nbytes / 1e6:.1f} MB → {compressed.nbytes / 1e6:.1f} MB ({compressed.memory.ratio:.1f}×)")
# Restore
restored = decompress(compressed)
print(f"MAE: {np.abs(restored - vectors).mean():.4f}")
# Estimate without running
est = estimate_savings(n_vectors=100000, dim=768, bits=3)
print(est) # Original: X MB -> Compressed: Y MB (7.60×, save 87%)
CompressedVectors objects carry metadata:
compressed.n_vectors # original count
compressed.dim # original dimension
compressed.nbytes # compressed size in bytes
compressed.memory # MemoryBytes(original, compressed, ratio)
compressed.data # raw .tq bytes (save to disk)
🤖 MCP Server (AI Agents)
TurboQuant Tools ships with a native MCP server for AI agent integration — works with any MCP-compatible host (Hermes, Claude Desktop, etc.).
Start
turboquant mcp-server
Register in your MCP client
Hermes Agent (~/.hermes/config.yaml):
mcp_servers:
turboquant-tools:
command: turboquant
args: ["mcp-server"]
enabled: true
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"turboquant-tools": {
"command": "turboquant",
"args": ["mcp-server"]
}
}
}
Available Tools
| Tool | Description |
|---|---|
compress_embeddings |
Compress vectors in-memory |
decompress_embeddings |
Restore compressed vectors |
estimate_savings_mcp |
Predict compression ratio |
embed_and_compress |
Embed texts via API + compress in one step |
📊 Performance
Measured on random float32 embeddings (CPU, no GPU needed):
| Vectors | Dim | Mode | Original | Compressed | Ratio | MAE |
|---|---|---|---|---|---|---|
| 20 | 384 | PolarQuant 3-bit | 30 KB | 10 KB | 3.0× | 2.6 |
| 20 | 384 | TurboQuant (QJL) | 30 KB | 20 KB | 1.5× | 3.3 |
| 100K | 384 | PolarQuant 3-bit | 153 MB | 20 MB | 7.6× | — |
Use cases:
- RAG pipelines — compress vector DB indexes
- Edge devices — fit embeddings in limited RAM
- Storage savings — reduce cloud costs for large vector stores
- Memory-bound agents — compress context vectors on the fly
🧪 Development
git clone https://github.com/FreezeVII/turboquant-tools.git
cd turboquant-tools
pip install -e .
pip install pytest
pytest tests/
Run tests
pytest tests/ -v
🧱 How It Works
Two-stage compression inspired by Google's TurboQuant:
- PolarQuant — Random Hadamard rotation + scalar quantization to 3–4 bits per dimension. Captures magnitude and direction.
- QJL (optional) — Quantized Johnson-Lindenstrauss residual correction. Recovers high-frequency detail lost in PolarQuant.
Both stages run CPU-only via PyTorch — no GPU required. The .tq binary format uses a 30-byte header with magic bytes (TQT2) + packed indices and norms.
Under the hood this wraps OnlyTerp/turboquant, a reference PyTorch implementation.
📄 License
MIT — see LICENSE.
🙌 Contributing
PRs welcome! Ideas:
- FAISS index compression (
compress_faiss) - Onnx / numpy-only backend (no PyTorch dep)
- Streaming compression for billion-scale datasets
- Pre-built wheels for faster install
<p align="center">Made with 🧊 for the vector search community.</p>
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。