Meet Turbovec: A Rust Vector Index with Python Bindings, and Built on Google’s TurboQuant Algorithm

0


Vector search underpins most retrieval-augmented generation (RAG) pipelines. At scale, it gets expensive. Storing 10 million document embeddings in float32 consumes 31 GB of RAM. For dev teams running local or on-premise inference, that number creates real constraints.

A new open-source library called turbovec addresses this directly. It is a vector index written in Rust with Python bindings. It is built on TurboQuant, a quantization algorithm from Google Research. The same 10-million-document corpus fits in 4 GB with turbovec. On ARM hardware, search speed beats FAISS IndexPQFastScan by 12–20%.

The TurboQuant Paper

TurboQuant was introduced by Google’s research team. The Google team proposes TurboQuant as a data-oblivious quantizer. It achieves near-optimal distortion rates across all bit-widths and dimensions. It requires zero training and zero passes over the data.

Most production-grade vector quantizers, including FAISS’s Product Quantization, requires a codebook training step. You must run k-means over a representative sample of your vectors before indexing begins. If your corpus grows or shifts, you may need to retrain and rebuild the index entirely. TurboQuant skips all of that. It uses an analytical property of rotated vectors instead of a data-dependent calibration.

How turbovec Quantizes Vectors

The quantization pipeline has four steps:

(1) Each vector is normalized. The length (norm) is stripped and stored as a single float. Every vector becomes a unit direction on a high-dimensional hypersphere.

(2) A random rotation is applied. All vectors are multiplied by the same random orthogonal matrix. After rotation, each coordinate independently follows a Beta distribution. In high dimensions, this converges to Gaussian N(0, 1/d). This holds for any input data — the rotation makes the coordinate distribution predictable.

(3) Lloyd-Max scalar quantization is applied. Because the distribution is known analytically, the optimal bucket boundaries and centroids can be precomputed from the math alone. For 2-bit quantization, that means 4 buckets per coordinate. For 4-bit, it means 16 buckets. No data passes are needed.

(4) The quantized coordinates are bit-packed into bytes. A 1536-dimensional vector shrinks from 6,144 bytes in FP32 to 384 bytes at 2-bit. That is a 16x compression ratio.

At search time, the query is rotated once into the same domain. Scoring happens directly against the codebook values. The scoring kernel uses SIMD intrinsics — NEON on ARM and AVX-512BW on modern x86, with an AVX2 fallback — with nibble-split lookup tables for throughput.

TurboQuant achieves distortion within approximately 2.7x of the information-theoretic Shannon lower bound.

Recall and Speed: The Numbers

All benchmarks use 100K vectors, 1,000 queries, k=64, and report the median of 5 runs.

For recall, turbovec compares against FAISS IndexPQ (LUT256, nbits=8, float32 LUT). This is a strong baseline: FAISS uses a higher-precision LUT at scoring time and k-means++ for codebook training. Despite this, TurboQuant and FAISS are within 0–1 point at R@1 for OpenAI embeddings at d=1536 and d=3072. Both converge to 1.0 recall by k=4–8. GloVe at d=200 is harder. At that dimension, TurboQuant trails FAISS by 3–6 points at R@1, closing by k≈16–32.

On speed, ARM results (Apple M3 Max) show turbovec beating FAISS IndexPQFastScan by 12–20% across every configuration. On x86 (Intel Xeon Platinum 8481C / Sapphire Rapids, 8 vCPUs), turbovec wins every 4-bit configuration by 1–6%. It runs within ~1% of FAISS on 2-bit single-threaded. Two configurations sit slightly behind FAISS: 2-bit multi-threaded at d=1536 and d=3072. There, the inner accumulate loop is too short for unrolling amortization. FAISS’s AVX-512 VBMI path holds the edge in those two cases (2–4%).

Python API

Installation is a single command: pip install turbovec. The primary class is TurboQuantIndex, initialized with a dimension and bit width.

Copy CodeCopiedUse a different Browser

from turbovec import TurboQuantIndex

index = TurboQuantIndex(dim=1536, bit_width=4)
index.add(vectors)
scores, indices = index.search(query, k=10)
index.write(“my_index.tq”)

A second class, IdMapIndex, supports stable external uint64 IDs that survive deletes. Removal is O(1) by ID. This is useful for document stores where vectors are frequently updated or deleted.

turbovec integrates with LangChain (pip install turbovec[langchain]), LlamaIndex (pip install turbovec[llama-index]), and Haystack (pip install turbovec[haystack]). The Rust crate is available via cargo add turbovec.

Marktechpost’s Visual Explainer

@import url(‘https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap’);

#tv-guide-root *,
#tv-guide-root *::before,
#tv-guide-root *::after {
box-sizing: border-box !important;
margin: 0 !important;
padding: 0 !important;
}

#tv-guide-root {
font-family: ‘Inter’, sans-serif !important;
background: #080808 !important;
border-radius: 14px !important;
overflow: hidden !important;
max-width: 780px !important;
margin: 0 auto !important;
border: 1px solid #383838 !important;
box-shadow: 0 0 0 1px #222, 0 24px 64px rgba(0,0,0,0.7) !important;
}

/* ── Rainbow gradient util ── */
#tv-guide-root .tvg-rainbow {
background: linear-gradient(90deg,#ff4444,#ff8800,#ffdd00,#44ff88,#00ccff,#7744ff,#ff44cc) !important;
}

/* ── Header ── */
#tv-guide-root .tvg-header {
background: #000 !important;
padding: 20px 28px !important;
display: flex !important;
align-items: center !important;
justify-content: space-between !important;
flex-wrap: wrap !important;
gap: 10px !important;
border-bottom: 1px solid #383838 !important;
position: relative !important;
}

#tv-guide-root .tvg-header::after {
content: ” !important;
position: absolute !important;
bottom: 0 !important; left: 0 !important; right: 0 !important;
height: 1px !important;
background: linear-gradient(90deg,#ff4444,#ff8800,#ffdd00,#44ff88,#00ccff,#7744ff,#ff44cc) !important;
opacity: 0.6 !important;
}

#tv-guide-root .tvg-header-left {
display: flex !important;
align-items: center !important;
gap: 14px !important;
}

#tv-guide-root .tvg-logo-badge {
font-family: ‘Inter’, sans-serif !important;
font-weight: 900 !important;
font-size: 18px !important;
color: #fff !important;
letter-spacing: -0.02em !important;
background: none !important;
-webkit-background-clip: unset !important;
-webkit-text-fill-color: #fff !important;
background-clip: unset !important;
}

#tv-guide-root .tvg-header-divider {
width: 1px !important;
height: 22px !important;
background: #282828 !important;
}

#tv-guide-root .tvg-header-title {
font-family: ‘Inter’, sans-serif !important;
font-weight: 600 !important;
font-size: 14px !important;
color: #e0e0e0 !important;
letter-spacing: -0.01em !important;
}

#tv-guide-root .tvg-header-sub {
font-size: 11px !important;
color: #666 !important;
font-weight: 400 !important;
margin-top: 2px !important;
}

#tv-guide-root .tvg-step-counter {
font-family: ‘JetBrains Mono’, monospace !important;
font-size: 11px !important;
color: #666 !important;
font-weight: 500 !important;
letter-spacing: 0.06em !important;
}

/* ── Progress bar ── */
#tv-guide-root .tvg-progress-bar {
height: 2px !important;
background: #141414 !important;
}

#tv-guide-root .tvg-progress-fill {
height: 100% !important;
background: linear-gradient(90deg,#ff4444,#ff8800,#ffdd00,#44ff88,#00ccff,#7744ff,#ff44cc) !important;
transition: width 0.4s cubic-bezier(.4,0,.2,1) !important;
}

/* ── Slides ── */
#tv-guide-root .tvg-slides-wrap {
position: relative !important;
width: 100% !important;
}

#tv-guide-root .tvg-slides-track {
width: 100% !important;
}

#tv-guide-root .tvg-slide {
display: none !important;
width: 100% !important;
padding: 30px 28px 24px !important;
background: #080808 !important;
opacity: 0 !important;
transition: opacity 0.3s ease !important;
}

#tv-guide-root .tvg-slide.tvg-active {
display: block !important;
opacity: 1 !important;
}

/* ── Slide label ── */
#tv-guide-root .tvg-slide-label {
display: inline-flex !important;
align-items: center !important;
gap: 8px !important;
margin-bottom: 14px !important;
}

#tv-guide-root .tvg-slide-label-text {
font-size: 10px !important;
font-weight: 600 !important;
letter-spacing: 0.12em !important;
text-transform: uppercase !important;
color: #666 !important;
}

#tv-guide-root .tvg-label-bar {
height: 2px !important;
width: 28px !important;
border-radius: 2px !important;
background: linear-gradient(90deg,#ff4444,#ff8800,#ffdd00,#44ff88,#00ccff,#7744ff,#ff44cc) !important;
}

/* ── Slide heading ── */
#tv-guide-root .tvg-slide-heading {
font-family: ‘Inter’, sans-serif !important;
font-weight: 800 !important;
font-size: 26px !important;
color: #ffffff !important;
line-height: 1.15 !important;
letter-spacing: -0.03em !important;
margin-bottom: 10px !important;
}

#tv-guide-root .tvg-slide-desc {
font-size: 13.5px !important;
color: #888 !important;
line-height: 1.7 !important;
margin-bottom: 20px !important;
max-width: 580px !important;
font-weight: 400 !important;
}

/* ── Code block ── */
#tv-guide-root .tvg-code-wrap {
background: #0d0d0d !important;
border-radius: 10px !important;
overflow: hidden !important;
border: 1px solid #383838 !important;
}

#tv-guide-root .tvg-code-topbar {
display: flex !important;
align-items: center !important;
justify-content: space-between !important;
padding: 9px 14px !important;
background: #111 !important;
border-bottom: 1px solid #383838 !important;
}

#tv-guide-root .tvg-code-dots {
display: flex !important;
gap: 6px !important;
}

#tv-guide-root .tvg-code-dots span {
width: 9px !important;
height: 9px !important;
border-radius: 50% !important;
display: block !important;
}

#tv-guide-root .tvg-code-dots span:nth-child(1) { background: #333 !important; }
#tv-guide-root .tvg-code-dots span:nth-child(2) { background: #2a2a2a !important; }
#tv-guide-root .tvg-code-dots span:nth-child(3) { background: #222 !important; }

#tv-guide-root .tvg-code-lang {
font-family: ‘JetBrains Mono’, monospace !important;
font-size: 10px !important;
color: #555 !important;
letter-spacing: 0.08em !important;
text-transform: uppercase !important;
}

#tv-guide-root .tvg-code-copy {
background: transparent !important;
border: 1px solid #444 !important;
border-radius: 5px !important;
color: #888 !important;
font-family: ‘JetBrains Mono’, monospace !important;
font-size: 10px !important;
padding: 3px 9px !important;
cursor: pointer !important;
transition: all 0.2s !important;
letter-spacing: 0.04em !important;
}

#tv-guide-root .tvg-code-copy:hover {
background: #1e1e1e !important;
color: #fff !important;
border-color: #666 !important;
}

#tv-guide-root pre.tvg-pre {
padding: 16px 18px !important;
overflow-x: auto !important;
font-family: ‘JetBrains Mono’, monospace !important;
font-size: 12.5px !important;
line-height: 1.8 !important;
color: #bbb !important;
background: transparent !important;
white-space: pre !important;
}

#tv-guide-root .kw { color: #00ccff !important; }
#tv-guide-root .fn { color: #44ff88 !important; }
#tv-guide-root .st { color: #ffdd00 !important; }
#tv-guide-root .cm { color: #555 !important; font-style: italic !important; }
#tv-guide-root .nb { color: #ff8800 !important; }
#tv-guide-root .num { color: #ff44cc !important; }

/* ── Chips ── */
#tv-guide-root .tvg-chips {
display: flex !important;
flex-wrap: wrap !important;
gap: 8px !important;
margin-top: 18px !important;
}

#tv-guide-root .tvg-chip {
background: #0e0e0e !important;
border: 1px solid #383838 !important;
border-radius: 6px !important;
padding: 7px 12px !important;
font-size: 12px !important;
color: #888 !important;
font-weight: 500 !important;
display: flex !important;
align-items: center !important;
gap: 6px !important;
}

#tv-guide-root .tvg-chip .tvg-chip-icon {
font-size: 13px !important;
}

/* ── Note box ── */
#tv-guide-root .tvg-note {
background: #0c0c0c !important;
border: 1px solid #383838 !important;
border-left: 2px solid #ff8800 !important;
border-radius: 0 7px 7px 0 !important;
padding: 11px 15px !important;
font-size: 12.5px !important;
color: #999 !important;
line-height: 1.65 !important;
margin-top: 14px !important;
}

#tv-guide-root .tvg-note strong {
font-weight: 600 !important;
color: #ff8800 !important;
}

/* ── Inline code ── */
#tv-guide-root .icode {
font-family: ‘JetBrains Mono’, monospace !important;
font-size: 11.5px !important;
background: #111 !important;
border: 1px solid #383838 !important;
color: #44ff88 !important;
padding: 1px 6px !important;
border-radius: 4px !important;
}

/* ── Footer credit ── */
#tv-guide-root .tvg-slide-footer {
display: flex !important;
align-items: center !important;
gap: 8px !important;
margin-top: 20px !important;
padding-top: 14px !important;
border-top: 1px solid #141414 !important;
}

#tv-guide-root .tvg-footer-dot {
width: 5px !important;
height: 5px !important;
border-radius: 50% !important;
background: linear-gradient(135deg,#ff4444,#7744ff) !important;
flex-shrink: 0 !important;
}

#tv-guide-root .tvg-footer-text {
font-size: 10.5px !important;
color: #888 !important;
font-weight: 500 !important;
letter-spacing: 0.03em !important;
}

#tv-guide-root .tvg-footer-link {
font-size: 10.5px !important;
color: #bbb !important;
font-weight: 600 !important;
text-decoration: none !important;
border-bottom: 1px solid #555 !important;
}

/* ── Nav ── */
#tv-guide-root .tvg-nav {
display: flex !important;
align-items: center !important;
justify-content: space-between !important;
padding: 16px 28px 20px !important;
background: #000 !important;
border-top: 1px solid #141414 !important;
}

#tv-guide-root .tvg-nav-btn {
display: flex !important;
align-items: center !important;
gap: 7px !important;
padding: 9px 20px !important;
border-radius: 8px !important;
font-family: ‘Inter’, sans-serif !important;
font-size: 12.5px !important;
font-weight: 600 !important;
cursor: pointer !important;
transition: all 0.2s !important;
border: 1px solid transparent !important;
letter-spacing: -0.01em !important;
}

#tv-guide-root .tvg-btn-prev {
background: transparent !important;
border-color: #383838 !important;
color: #555 !important;
}

#tv-guide-root .tvg-btn-prev:hover:not(:disabled) {
background: #0e0e0e !important;
color: #888 !important;
border-color: #444 !important;
}

#tv-guide-root .tvg-btn-next {
background: #fff !important;
border-color: #fff !important;
color: #000 !important;
}

#tv-guide-root .tvg-btn-next:hover:not(:disabled) {
background: #e0e0e0 !important;
border-color: #e0e0e0 !important;
}

#tv-guide-root .tvg-nav-btn:disabled {
opacity: 0.2 !important;
cursor: not-allowed !important;
}

/* ── Dots ── */
#tv-guide-root .tvg-dots {
display: flex !important;
gap: 6px !important;
align-items: center !important;
}

#tv-guide-root .tvg-dot-btn {
width: 5px !important;
height: 5px !important;
border-radius: 50% !important;
background: #222 !important;
border: none !important;
cursor: pointer !important;
padding: 0 !important;
transition: all 0.25s !important;
}

#tv-guide-root .tvg-dot-btn.active {
background: #fff !important;
width: 18px !important;
border-radius: 3px !important;
}

/* ── Mobile ── */
@media (max-width: 640px) {
#tv-guide-root .tvg-slide {
padding: 22px 18px 18px !important;
}
#tv-guide-root .tvg-header {
padding: 14px 18px !important;
}
#tv-guide-root .tvg-slide-heading {
font-size: 20px !important;
}
#tv-guide-root .tvg-nav {
padding: 13px 18px 16px !important;
}
#tv-guide-root pre.tvg-pre {
font-size: 11px !important;
}
#tv-guide-root .tvg-nav-btn {
padding: 8px 14px !important;
font-size: 12px !important;
}
}

turbovec

How to Use turbovec
TurboQuant vector search — Rust + Python

01 / 07

Overview

What is turbovec?
turbovec is a vector index written in Rust with Python bindings. It is built on Google Research’s TurboQuant algorithm — a data-oblivious quantizer that requires zero codebook training. A 10 million document corpus that occupies 31 GB as float32 fits in 4 GB with turbovec.
16x compression at 2-bit
💨 Beats FAISS on ARM by 12–20%
🔒 Fully local — no data egress
📦 MIT licensed

Step 1

Installation
Install the Python package from PyPI with a single command. For Rust, add the crate via Cargo.

terminal
copy

# Python
pip install turbovec

# Rust
cargo add turbovec

Note: To build from source, install maturin then run maturin build –release inside the turbovec-python/ directory. For Rust, run cargo build –release.

Step 2

Basic Usage — TurboQuantIndex
TurboQuantIndex is the primary class. Initialize it with a vector dim and a bit_width of 2 or 4. Vectors are indexed immediately on add() — no training step required.

python
copy

from turbovec import TurboQuantIndex

index = TurboQuantIndex(dim=1536, bit_width=4)

# Add vectors (numpy float32 array, shape [n, dim])
index.add(vectors)
index.add(more_vectors) # incremental adds are fine

# Search: returns top-k scores and positional indices
scores, indices = index.search(query, k=10)

Step 3

Stable IDs — IdMapIndex
Use IdMapIndex when you need external uint64 IDs that survive deletes. Removal is O(1) by ID — useful for document stores where vectors change over time.

python
copy

import numpy as np
from turbovec import IdMapIndex

index = IdMapIndex(dim=1536, bit_width=4)

# Map vectors to your own uint64 external IDs
index.add_with_ids(vectors, np.array([1001, 1002, 1003], dtype=np.uint64))

# Search returns your external IDs, not positional indices
scores, ids = index.search(query, k=10)

# O(1) delete by external IDnindex.remove(1002)

Step 4

Save & Load an Index
Both index types support persistent storage. TurboQuantIndex writes to .tq files. IdMapIndex writes to .tvim files.

python
copy

from turbovec import TurboQuantIndex, IdMapIndex

# TurboQuantIndex —> .tq
index.write(“my_index.tq”)
loaded = TurboQuantIndex.load(“my_index.tq”)

# IdMapIndex —> .tvim
index.write(“my_index.tvim”)
loaded = IdMapIndex.load(“my_index.tvim”)

Step 5

Framework Integrations
turbovec ships optional extras for LangChain, LlamaIndex, and Haystack. Install the extra that matches your stack.

terminal
copy

# LangChain
pip install turbovec[langchain]

# LlamaIndex
pip install turbovec[llama-index]

# Haystack
pip install turbovec[haystack]

Tip: Each integration plugs turbovec in as a drop-in vector store. See docs/integrations/ in the repo for full usage examples with each framework.

Step 6

Using turbovec in Rust
The Rust API mirrors the Python API. Both TurboQuantIndex and IdMapIndex are available. All x86_64 builds target AVX2 as baseline; AVX-512 is enabled at runtime via feature detection.

rust
copy

use turbovec::TurboQuantIndex;

let mut index = TurboQuantIndex::new(1536, 4);
index.add(&vectors);

let results = index.search(&queries, 10);

index.write(“index.tv”).unwrap();
let loaded = TurboQuantIndex::load(“index.tv”).unwrap();

📚 Full API: docs/api.md
⭐ github.com/RyanCodrai/turbovec
← Prev

Next →

(function(){
var total=7, cur=0;
var progress=document.getElementById(‘tvg-progress’);
var counter=document.getElementById(‘tvg-counter’);
var prevBtn=document.getElementById(‘tvg-prev’);
var nextBtn=document.getElementById(‘tvg-next’);
var dotsWrap=document.getElementById(‘tvg-dots’);
var slides=document.querySelectorAll(‘#tv-guide-root .tvg-slide’);

// Build dot nav
for(var i=0;i<total;i++){
var d=document.createElement('button');
d.className='tvg-dot-btn'+(i===0?' active':'');
d.setAttribute('data-i',i);
d.onclick=(function(idx){return function(){tvgGoTo(idx);};})(i);
dotsWrap.appendChild(d);
}

function tvgGoTo(n){
// Hide current, show next using class toggle — no transforms, no height hacks
slides[cur].classList.remove('tvg-active');
cur=n;
slides[cur].classList.add('tvg-active');
progress.style.width=((cur+1)/total*100)+'%';
counter.textContent=(cur+1<10?'0':'')+(cur+1)+' / 0'+total;
prevBtn.disabled=cur===0;
nextBtn.disabled=cur===total-1;
nextBtn.innerHTML=cur===total-1?'✓ Done':'Next →';
var dots=dotsWrap.querySelectorAll('.tvg-dot-btn');
for(var i=0;i40) tvgNav(dx<0?1:-1);
startX=null;
},{passive:true});

})();

Key Takeaways

  • No codebook training. turbovec indexes vectors instantly — no k-means, no rebuilds as the corpus grows.
  • 16x compression. A 1536-dim float32 vector shrinks from 6,144 bytes to 384 bytes at 2-bit quantization.
  • Faster than FAISS on ARM. turbovec beats FAISS IndexPQFastScan by 12–20% on ARM across every configuration.
  • Near-optimal distortion. TurboQuant achieves distortion within ~2.7x of the Shannon lower bound — provably near the theoretical limit.
  • Fully local. No managed service, no data egress — pairs with any open-source embedding model for an air-gapped RAG stack.

Check out the Repo here. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us

The post Meet Turbovec: A Rust Vector Index with Python Bindings, and Built on Google’s TurboQuant Algorithm appeared first on MarkTechPost.



Source link

You might also like
Leave A Reply

Your email address will not be published.