> SpecStream is the live web data engine for teams and agents. This is the Markdown copy of https://specstream.ai/blog/millisecond-semantic-retrieval-47m-wikipedia-6gb-ram. Every page, with what SpecStream does and costs: https://specstream.ai/llms.txt

# Millisecond semantic retrieval over 47 million Wikipedia paragraphs in 6 GB of RAM

Tarek, Founder & CEO

[Engineering](https://specstream.ai/blog.md) · Dec 1, 2026 · 7 min read

Serving 47 million 1,024-dimensional embeddings in standard `float32` requires 192.6 GB of raw vector memory before adding any HNSW graph edges or metadata. With an HNSW graph (`M=32`), a single corpus of 47 million paragraphs routinely demands 250 to 320 GB of RAM and dedicated high-memory clusters costing thousands of dollars per month.

We serve semantic retrieval over all 47,018,430 paragraphs of English Wikipedia (6,614,230 articles, 1,024-dimensional `BAAI/bge-m3` embeddings from the public `Upstash/wikipedia-2024-06-bge-m3` corpus) inside a single 14 GB memory cgroup with swap disabled, pinning the entire searchable vector index in **5.605 GiB (6.018 GB) of `mlock`\-pinned RAM**. On live production traffic measured December 1, 2026, query encoding runs in **0.23 ms** at median, the full 47.02-million-vector exact Hamming scan completes in **171.77 ms** at median, and NVMe `mmap` `int8` rescoring plus paragraph text retrieval finishes in **2.87 ms** at median.

## The exact memory math: 32x RAM compression

Dense 1,024-dimensional unit vectors do not need 32 bits per coordinate to narrow 47 million paragraphs down to the top few thousand candidates. They only need sign bits for the first pass and 8-bit scalar quantization for final cosine rescoring.

| Representation | Bytes per vector | Total size (47,018,430 paragraphs) | Storage tier | Read pattern per query |
| --- | --- | --- | --- | --- |
| Uncompressed `float32` | 4,096 B | 192.59 GB (179.36 GiB) | Not stored | None |
| `float32` + HNSW (`M=32`) | ~5,400 B | ~254 GB | Not stored | Random pointer chasing |
| **Stage 1: Binary sign bits (`bin.dat`)** | **128 B** | **6.018 GB (5.605 GiB)** | **`mlock()` pinned RAM** | **100% sequential SIMD scan** |
| **Stage 2: Scalar `int8` (`i8.dat`)** | **1,024 B** | **48.147 GB (44.840 GiB)** | **Local NVMe (`mmap`)** | **Top 3,000 candidates (~3.07 MB)** |

Each 1,024-dimensional unit vector is stored twice in flat, aligned binary files indexed by paragraph row ID:

1.  **Binary sign file (`bin.dat`):** Bit `d` is `1` if `vec[d] > 0`, packed little-endian into 128 bytes (`16 x uint64_t` words) per paragraph. Across 47,018,430 paragraphs, the file is exactly `6,018,359,040` bytes (`5.605 GiB`). At startup, the service prewarms and locks `bin.dat` in physical RAM with `mlock()` so random page faults on the 48 GB `int8` file can never evict the hot binary scan buffer.
2.  **Scalar `int8` rescore file (`i8.dat`):** Each unit-normalized dimension is quantized as `clip(round(v * 127), -127, 127)`, requiring 1,024 bytes per paragraph (`48,146,872,320` bytes total, `44.840 GiB`). It lives memory-mapped on direct-attached local NVMe.
3.  **Zero-copy paragraph store (`texts.dat` + `text_ends.dat` + `article_ids.dat` + `articles.tsv`):** UTF-8 paragraph texts sit back to back with a `uint64` end-offset array and a `uint32` article ID table, so returning full matched paragraphs and article URLs requires one O(1) offset lookup per winning hit.

Because Stage 1 scans flat contiguous arrays in RAM with zero graph pointers, there is no index build overhead, no HNSW graph corruption on updates, no recall cliff on filtered queries, and zero pointer-chasing stalls.

## Two-stage retrieval pipeline

Every incoming query passes through three deterministic stages:

```
Query text
   |
   v
[1] Quantized ONNX encoder (p50: 0.23 ms)
   |---> 1024-dim float32 query vector
   |---> pack_binary(q) -> 16 x uint64_t (128 bytes)
   |
   v
[2] OpenMP + AVX-512 VPOPCNTDQ Hamming scan over 47,018,430 x 128 B in RAM (p50: 171.77 ms)
   |---> exact top-3,000 candidates via (distance << 32) | row min-heap
   |
   v
[3] Local NVMe mmap int8 dot-product rescore + text fetch (p50: 2.87 ms)
   |---> 3,000 candidates x 1,024 B = 3.07 MB read
   |---> exact float-to-int8 cosine ranking + article deduplication
   v
Top-k paragraphs with URL, title, score, and matched text
```

### Stage 1: AVX-512 VPOPCNTDQ and micro-batched memory bandwidth

An exact scan over 6.018 GB of RAM is memory-bandwidth bound, not compute bound. On modern x86 CPUs supporting `AVX-512F` and `AVX-512VPOPCNTDQ`, each 128-byte binary vector fits cleanly in two 512-bit ZMM registers (`_mm512_xor_si512` followed by `_mm512_popcnt_epi64` and `_mm512_reduce_add_epi64`). On hosts without AVX-512, the same kernel compiles cleanly to 16 unrolled 64-bit XOR plus `__builtin_popcountll` instructions via `-O3 -march=native -fopenmp`.

Two engineering details make the scan predictable and scalable under load:

-   **Deterministic tie-breaking in one 64-bit integer.** Each thread keeps a local fixed-size max-heap of `cand` entries keyed by `((uint64_t)distance << 32) | row_id`. Ties break identically by paragraph row ID regardless of OpenMP thread scheduling order, making retrieval results 100% reproducible across runs.
-   **4-way query micro-batching.** Because single-query Hamming scans saturate memory bandwidth across 12 OpenMP threads, serving concurrent requests independently causes threads to thrash DRAM channels. Micro-batching up to 4 concurrent queries in registers computes `XOR + POPCNT` against all 4 query vectors per cache line fetched from `bin.dat`, amortizing the 6.018 GB DRAM sweep across multiple callers simultaneously.

### Stage 2: Sub-3-millisecond NVMe `int8` rescoring

Once the binary pass selects the top 3,000 candidates (0.0064% of the 47M corpus), Stage 2 touches `i8.dat` on local direct-attached NVMe. Reading 3,000 rows of 1,024 bytes pulls just 3.07 MB total. Computing the `float32` query dot product against 3,000 `int8` vectors recovers high-precision cosine ordering in **2.87 ms at median** (4.41 ms p95) on local NVMe, including fetching the final UTF-8 paragraph texts for the returned hits.

## Live production benchmark results (December 1, 2026)

We benchmarked the live production service running inside a 12-thread cgroup (`OMP_NUM_THREADS=12`, `MemoryMax=14G`, `MemorySwapMax=0`) on one Frankfurt local-NVMe node across 47,018,430 Wikipedia paragraphs.

### Stage breakdown (sequential factual queries, `k=10`, `n=20`)

| Pipeline stage | Median (p50) | p95 | Share of server time |
| --- | --- | --- | --- |
| Query encoding (quantized ONNX) | **0.23 ms** | 0.32 ms | 0.1% |
| Exact 47.02M binary Hamming scan (RAM) | **171.77 ms** | 261.49 ms | 98.0% |
| NVMe `mmap` `int8` rescore + text lookup | **2.87 ms** | 4.41 ms | 1.6% |
| **Total server latency** | **175.21 ms** |  | **100%** |

### End-to-end throughput: sequential vs 8-way concurrent micro-batching (`n=60`)

| Workload | Requests OK | Total wall time | Throughput | Server p50 | Server p95 | Client p50 | Client p95 |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Sequential (1 caller) | 60 / 60 | 16.02 s | **3.75 QPS** | 248.05 ms | 336.59 ms | 258.65 ms | 347.26 ms |
| 8-way concurrent (micro-batched) | 60 / 60 | 7.49 s | **8.01 QPS** | 836.87 ms | 1,016.30 ms | 885.52 ms | 1,191.44 ms |

Micro-batching delivers a **2.14x throughput increase** (3.75 QPS to 8.01 QPS) on the exact same 12 threads and 6.02 GB RAM budget because multiple queries share each DRAM sweep of `bin.dat`, while `int8` rescore median rises only from 2.87 ms to 6.16 ms under 8x concurrency.

## Why exact binary scan + NVMe `int8` beats managed vector databases for web search

For a web-scale search engine that answers multi-hop factual questions (where SpecStream ranks #1 across 15 public benchmarks including 90.78% on FRAMES and 99 on SimpleQA Verified), this architecture offers three operational advantages over HNSW-based vector services:

1.  **Zero memory blowup.** 47 million paragraphs fit in 6.02 GB of pinned RAM on a shared EUR 83.22/month node alongside hundreds of millions of other records, rather than requiring a dedicated 256 GB vector cluster.
2.  **Exact recall over the binary space.** There is no approximate graph navigation failure when a query lies near a sparse region of the embedding manifold, and no `efSearch` tuning cliffs.
3.  **Crash-safe, resumable flat-file builds.** Building the index streams the 471 shards of `Upstash/wikipedia-2024-06-bge-m3` directly into append-only binary files with atomic shard checkpoints, requiring under 2 GB of scratch disk.

## Reproducible open benchmark

To let any systems engineer verify the memory layout, binary-to-int8 recall curve, and SIMD scan throughput on their own hardware, we published a clean standalone C + Python reproduction suite ([Specstreamai/wiki-binary-int8-bench](https://github.com/Specstreamai/wiki-binary-int8-bench)) alongside this post. It implements the exact 1024-bit sign packing, AVX-512 / portable POPCNT scan, `int8` rescoring, and latency/recall script on synthetic unit-sphere corpora or real `BAAI/bge-m3` Parquet shards.

Explore SpecStream's Search API and Extract API with $2 of free credit (no card required) at [specstream.ai/workspace](https://specstream.ai/workspace), or inspect all 15 public benchmark runs at [specstream.ai/benchmarks](https://specstream.ai/benchmarks.md).

## More from the blog

[Every post](https://specstream.ai/blog.md)

[### How we run a 6.7-billion-page, EU-sovereign web index on 12 local-NVMe nodes Architecture, storage layout, bounded-time search mechanics, and monthly economics of SpecStream's 6.76-billion-page web index running on 12 local-NVMe nodes in Frankfurt for EUR 862.86 per month Dec 1, 2026 · Tarek · 9 min read](https://specstream.ai/blog/eu-sovereign-6-7b-web-index-12-nvme-nodes.md)[### BuiltWith and TheirStack alternative 2026: companies using any software, as a CSV from $15 Compare BuiltWith ($295 to $995/mo) and TheirStack ($199 to $999/mo) with SpecStream: 374,916 companies across 265 technologies, 16.58M commercial tech stacks and 6,812 trust centers, from $15 per list or $49/mo Dec 1, 2026 · SpecStream · 5 min read](https://specstream.ai/blog/builtwith-theirstack-alternative-2026.md)[### Claygent alternative 2026: web enrichment in Clay at $1 per 1,000 rows, 50x cheaper Run live web search and page extraction inside Clay through the HTTP API column: $1 per 1,000 searches and $0.80 per 1,000 pages on the engine ranked #1 across 15 public web search and extraction benchmarks Dec 1, 2026 · SpecStream · 4 min read](https://specstream.ai/blog/claygent-alternative-50x-cheaper-web-enrichment-2026.md)
