What is multithreaded construction?
Multithreaded construction is building an HNSW index by inserting many vectors concurrently across worker threads during a bulk load — a specialized, high-throughput form of parallel insertion aimed at finishing the initial graph as fast as the machine’s CPU and memory allow.
How does multithreaded construction differ from everyday parallel upserts?
Parallel insertion is the general mechanism: several threads run the insert algorithm against one shared graph with synchronized edge commits. Multithreaded construction is that mechanism applied as a dedicated build phase — often offline or with queries drained — where the sole goal is to ingest a large batch from empty (or from a checkpoint) to a finished index. Workers typically pull vectors from a shared work queue, run efConstruction searches, and commit edges under per-node locks until N is reached. There is less emphasis on read-mostly query latency during the run and more on wall-clock build time, peak build memory, and acceptable nondeterminism in the final edge set. Live upsert pipelines reuse the same primitives but must also protect concurrent searchers; pure construction can sometimes use simpler writer-only protocols.
Build time is dominated by construction searches, which is why adding threads helps until contention or RAM intervenes.
What actually runs in parallel during an HNSW multithreaded build?
Each worker’s heavy CPU work is the efConstruction search and distance computations for its current insert — embarrassingly parallel across different new points. The serial choke points are claiming node IDs, updating shared entry-point metadata, and locking nodes when splicing bidirectional edges, especially around hubs. Vector and edge arenas should be pre-sized or grow under a coordinated allocator so threads are not stuck in malloc locks. Distance kernels still benefit from SIMD inside each worker. In-memory systems that support concurrent indexing, including bulk-load paths related to databases like Weaviate, scale construction this way: more workers cut wall time until the graph’s shared writes or the memory controllers saturate.
The finished graph is usually not bit-identical to a single-threaded build of the same data — and that needs to be expected in evaluation.
How should you evaluate quality after a multithreaded build?
Fix efSearch and measure recall against ground truth; compare to a single-threaded baseline built with the same M and efConstruction. Small recall differences are common because insertion order effectively shuffled; large regressions suggest lock bugs, under-sized efConstruction for the concurrency level, or broken neighbor selection under races. Report thread count beside build-time benchmarks so others can reproduce the throughput claim. Do not require identical edge lists across runs unless the implementation documents a deterministic scheduling mode. Seed control for level sampling still matters, but it does not restore order once commits interleave.
Sizing the worker pool is a joint decision about time, peak RAM, and lock scaling.
How do you choose the degree of multithreading for construction?
Sweep thread counts while recording build duration, peak RSS, lock wait, and post-build recall. Stop when duration flattens or peak memory hits the budget — peak build memory grows with per-thread efConstruction heaps. Lower efConstruction if memory-bound after validating recall; shard across processes if one graph’s hubs serialize too hard. Pin workers on NUMA hosts so first-touch pages stay local. Multithreaded construction is the standard way to make large HNSW builds practical on multi-core servers, provided parallel insertion’s synchronization contract is solid.
Multithreaded construction is bulk parallel HNSW insertion optimized for build wall time, with the same locking needs as parallel inserts and the same nondeterministic edge caveat. From here, parallel insertion states the general mechanism, peak build memory sizes the RAM crest, nondeterministic build order covers reproducibility, work queues explain task distribution, and the chapter on concurrent HNSW construction and querying details full build protocols.