Architecture
BudgetVec is built as a Rust → WASM application running on Cloudflare Workers, with R2 for durable storage and KV for caching and control plane data.
System Diagram
┌──────────────┐
│ Client │
│ (SDK / HTTP) │
└──────┬───────┘
│ HTTPS
▼
┌──────────────────────────┐
│ Cloudflare Worker │
│ (Rust → WASM, 691 KB) │
│ │
│ ┌─────────────────────┐ │
│ │ Router / Auth │ │
│ │ Tenant isolation │ │
│ └─────────┬───────────┘ │
│ │ │
│ ┌─────────▼───────────┐ │
│ │ Ingestion Pipeline │ │
│ │ Validate → Encode │ │
│ │ → WAL batch │ │
│ └─────────┬───────────┘ │
│ │ │
│ ┌─────────▼───────────┐ │
│ │ Query Engine │ │
│ │ ANN (SPTAG/PQ ADC) │ │
│ │ BM25 (Thai + EN) │ │
│ └─────────┬───────────┘ │
│ │ │
│ ┌─────────▼───────────┐ │
│ │ Pufferfish Cache │ │
│ │ L1: Worker memory │ │
│ │ L2: KV │ │
│ │ L3: R2 │ │
│ └─────────────────────┘ │
└──────────────────────────┘
│
▼
┌──────────────┐ ┌──────────────┐
│ R2 Storage │ │ KV Store │
│ $0.015/GB │ │ Control + │
│ Vectors/WAL │ │ Cache │
└──────────────┘ └──────────────┘
Crate Structure
BudgetVec is organized as a Rust workspace with 6 crates:
| Crate | Purpose |
|---|---|
sptag-sys | C++ FFI bindings for SPTAG indexing |
sptag | Safe Rust wrapper around SPTAG |
core | Codecs (PQ, RaBitQ), storage, text processing, BM25 |
worker | Cloudflare Worker entry point, routes, platform code |
build-cli | Offline index builder CLI tool |
tests/http-integration | HTTP integration test suite |
Compression Pipeline
Vectors go through a two-stage compression:
1. RaBitQ — 1-bit quantization reduces each float32 dimension to 1 bit, giving 32× compression for distance approximation
2. Product Quantization (PQ) — Subdivides vectors into M subspaces, quantizes each to K centroids, enabling ADC (Asymmetric Distance Computation) for fast approximate search
Multi-Tenant Isolation
Each tenant has:
- Unique API key (FNV-1a hashed for lookup in KV)
- Isolated R2 prefix:
{base_namespace}/{namespace}/... - Per-tenant KV cache entries
- Configurable vector dimensions, plan limits, and default region
Regions
BudgetVec supports 6 deployment regions, each with dedicated R2 buckets and KV namespaces:
| Region | Location |
|---|---|
| WNAM | US West |
| ENAM | US East |
| WEUR | Western Europe |
| EEUR | Eastern Europe |
| APAC | Asia-Pacific |
| OC | Oceania |