How ryancodrai/turbovec works
1. Repository shape
- This is a Rust-first vector search engine with a Python extension package and a separate benchmark/evaluation harness.
- The architecture is centered on a core Rust crate (turbovec) that is reused by the Python wrapper crate (turbovec-python).
2. Core engine boundary
- turbovec/src is the main subsystem: it owns vector encoding, search, packing, rotation, persistence, and error handling.
- The public API exposed from turbovec/src/lib.rs appears to be built around two index types: TurboQuantIndex for dense vector indexing and IdMapIndex for stable external IDs and deletes.
3. Ingest / encode pipeline
- Raw vectors are ingested into the index, then transformed into a compressed representation.
- The pipeline described in the README is: normalize → apply a shared random rotation → scalar-quantize each coordinate → bit-pack the codes → store a per-vector length renormalization scalar.
- That last scalar is a key architectural detail: it is computed at ingest time and later used during scoring to correct bias without extra query-time storage overhead.
4. Search pipeline
- Queries follow a mirrored path: the query is rotated into the same quantized space, then scored directly against packed codes.
- Search avoids decompression of the corpus; the hot path is a SIMD scoring kernel that computes approximate inner products from the packed representation.
- Results are produced through a heap/top-k selection step, returning scores plus either internal slots or external IDs depending on the index type.
5. Performance-critical implementation
- The core search kernels are architecture-specific: NEON on ARM, AVX-512BW on modern x86, with an AVX2 fallback.
- This is not just a portability detail; it defines the runtime boundary. The crate is compiled with an x86-64-v3 baseline, and AVX-512 is enabled only when detected at runtime.
6. Filtering and hybrid retrieval
- search() supports allowlists / slot bitmasks so filtering happens inside the SIMD search path, not as a post-filter.
- Architecturally, this means the vector index can serve as a second-stage reranker after an external system narrows candidates by SQL, ACL, tenant, or time window.
- The design avoids over-fetching and preserves top-k recall within the allowed subset.
7. Stable IDs and deletion semantics
- IdMapIndex adds an ID mapping layer on top of the compressed vector storage.
- Its role is to decouple internal storage slots from user-facing u64 IDs, supporting stable lookup, O(1)-style remove semantics, and persistence with external IDs preserved.
- This is the main boundary for applications that need document IDs rather than dense slot indices.
8. Persistence / I/O
- The io and dump_state example indicate that index state can be written to and loaded from disk as a standalone artifact.
- The README names two persisted formats: one for the plain vector index and one for the ID-mapped variant, which means serialization is part of the core architecture, not an afterthought.
9. Python distribution layer
- turbovec-python is a separate crate/package that builds the Python extension module and ships Python-facing wrappers under python/turbovec.
- It exposes the same conceptual split as the Rust API: basic vector index, ID-mapped index, plus integration adapters for LangChain, LlamaIndex, Haystack, and Agno.
- Those adapters are thin compatibility boundaries that let turbovec replace in-memory vector stores in existing agent/RAG frameworks.
10. Testing and correctness boundary
- The Rust tests cover encoding, rotation, codebook behavior, concurrent search, filtering, ID mapping, persistence/versioning, and kernel correctness.
- The Python tests validate the binding layer and framework integrations, so the repo has separate correctness surfaces for core algorithms and external API compatibility.
11. Benchmarking and evaluation subsystem
- benchmarks/ is a self-contained measurement harness with scripts for recall, compression, and speed, plus archived JSON outputs and chart generation.
- It compares turbovec across dimensions, bit widths, and CPU families, and also contains proof-of-concept comparison code against baseline approaches.
- This subsystem is important architecturally because it validates both the algorithmic claims and the hardware-specific kernel behavior.
12. Tooling and release flow
- The repo is managed as a Rust workspace with Python packaging via maturin, plus GitHub Actions for releasing both crates.io and PyPI artifacts.
- That means the deliverable boundary is dual: a native Rust library for systems users and a Python package for application-level integration.
13. What to draw in an architecture diagram
- Show three main zones: core Rust indexing engine, Python binding/integration layer, and benchmark/documentation tooling.
- Inside the core engine, depict the flow from vector ingest → quantized storage → SIMD search → top-k output, with side branches for ID mapping, filtering, and persistence.
- Annotate the search kernel with its CPU-specific SIMD implementations and the Python layer as a wrapper around the same Rust core rather than a separate implementation.
Main entry points: lib.rs turbovec · __init__.py Python API · search.rs Search · encode.rs Encode
Components 19
Core Rust engine
Main vector indexing engine and native search pipeline.
- turbovec · Top-level Rust library exposing the public indexing API.
turbovec/src/lib.rs - Encode · Normalizes vectors and converts them into quantized codes.
turbovec/src/encode.rs - Rotation · Applies the shared random rotation used by ingest and query paths.
turbovec/src/rotation.rs - Codebook · Defines scalar quantization behavior for compressed vector codes.
turbovec/src/codebook.rs - Packing · Stores quantized codes in packed form for compact search.
turbovec/src/pack.rs - Search · Runs approximate search over packed vectors and produces top-k results.
turbovec/src/search.rs - Id map · Maps stable external u64 IDs onto internal storage slots and handles removals.
turbovec/src/id_map.rs - Persistence · Loads and writes persisted index state for standalone use.
turbovec/src/io.rs - Errors · Shared error handling for the Rust core API.
turbovec/src/error.rs - SIMD kernels · Architecture-specific scoring implementations for ARM and x86.
Python package
Python extension module and framework adapters built on the Rust core.
- Python ext · Native extension module that wraps the Rust library for Python.
turbovec-python/src/lib.rs - Python API · Python-facing package exposing the index types and bindings.
turbovec-python/python/turbovec/__init__.py - LangChain · Compatibility adapter for LangChain integrations.
turbovec-python/python/turbovec/langchain.py - LlamaIndex · Compatibility adapter for LlamaIndex integrations.
turbovec-python/python/turbovec/llama_index.py - Haystack · Compatibility adapter for Haystack integrations.
turbovec-python/python/turbovec/haystack.py - Agno · Compatibility adapter for Agno integrations.
turbovec-python/python/turbovec/agno.py
Benchmarks
Measurement and evaluation harness for recall, compression, and speed.
- Bench suite · Benchmark scripts for recall, compression, and speed measurements.
benchmarks/suite - Results · Archived benchmark outputs and comparison artifacts.
benchmarks/results - PoC compare · Prototype comparison code and baseline result sets.
benchmarks/rabitq_poc
Connections 22
- turbovec → Encode: uses · Public index API feeds vectors into the ingest pipeline.
- Encode → Rotation: applies · Ingest rotates vectors into the shared quantized space.
- Encode → Codebook: quantizes · Coordinates are scalar-quantized into compact codes.
- Codebook → Packing: packs · Quantized codes are bit-packed for storage and search.
- turbovec → Search: exposes · Search is the primary query entry point of the crate.
- Search → Rotation: mirrors · Queries are rotated before scoring against packed codes.
- Search → Packing: scans · Hot path scores directly from packed representation.
- Search → SIMD kernels: dispatches · CPU-specific SIMD kernels implement the scoring hot path.
- turbovec → Id map: wraps · ID-mapped index builds stable external IDs on top of core storage.
- Id map → Search: returns ids · Search can emit external IDs instead of internal slots.
- Id map → Persistence: persists · Mapped IDs are preserved in serialized index state.
- turbovec → Persistence: serializes · Core index state can be dumped and restored from disk.
- turbovec → Errors: reports · Shared error types define the crate boundary.
- Python ext → turbovec: binds · Python extension wraps the Rust core rather than reimplementing it.
- Python API → Python ext: imports · Python package exposes the native extension to users.
- Python API → LangChain: adapts · Framework adapter for LangChain.
- Python API → LlamaIndex: adapts · Framework adapter for LlamaIndex.
- Python API → Haystack: adapts · Framework adapter for Haystack.
- Python API → Agno: adapts · Framework adapter for Agno.
- Bench suite → turbovec: measures · Benchmark suite exercises the Rust engine across recall, speed, and compression.
- Bench suite → Results: writes · Benchmark runs produce archived JSON outputs and charts.
- PoC compare → turbovec: compares · Prototype analysis compares turbovec against baseline approaches.