Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

HNSW Stress Tests

Stress tests for the Hierarchical Navigable Small World (HNSW) index, targeting 1M vector scale.

Test Suite

TestScaleDescription
stress_hnsw_1m_vectors1M 128d vectorsBuild 1M vector index
stress_hnsw_100k_concurrent_build100K vectors, 16 threadsConcurrent index construction
stress_hnsw_search_during_insert50K vectors, 4+4 threadsConcurrent search during insert
stress_hnsw_recall_under_load10K vectorsVerify recall@10 under load

Results

TestKey MetricResult
1M vectorsInsert throughput3,372 vectors/sec
1M vectorsSearch latency (p50)0.11ms
100K concurrentInsert throughput1,155 vectors/sec
Recall@10Average recall99.8% (min 90%)

Running

# Run all HNSW stress tests
cargo test --release -p stress_tests --test hnsw_stress -- --ignored --nocapture

# Run specific test
cargo test --release -p stress_tests stress_hnsw_1m_vectors -- --ignored --nocapture

1M Vector Index Build

Tests building an HNSW index with 1 million 128-dimensional vectors.

What it validates:

  • Memory efficiency at scale
  • Index build time scalability
  • Search accuracy after large insertions

Expected behavior:

  • Linear memory growth with vector count
  • Sub-linear search time (O(log n))
  • Recall@10 > 95%

Concurrent Index Build

Tests building an HNSW index with 16 concurrent writer threads.

What it validates:

  • Thread-safety of HNSW insert operations
  • Performance under contention
  • Correctness with concurrent modifications

Expected behavior:

  • All inserted vectors are findable
  • No panics or data races
  • Throughput scales with thread count (with diminishing returns)

Search During Insert

Tests searching the index while new vectors are being inserted concurrently.

What it validates:

  • Read/write concurrency safety
  • Search accuracy with ongoing modifications
  • Latency stability under load

Expected behavior:

  • Searches return valid results
  • No stale or corrupted results
  • Latency remains bounded

Recall Under Load

Tests search recall accuracy under sustained concurrent load.

What it validates:

  • HNSW recall guarantees under stress
  • Accuracy with high query volume
  • Configuration impact on recall

Expected behavior:

  • Average recall@10 > 95%
  • Minimum recall@10 > 90%
  • High_recall config > default config recall

Performance Tuning

HNSW Configuration Impact

ConfigInsert SpeedSearch SpeedRecallMemory
high_speedFastestFastestLowerLower
defaultMediumMediumGoodMedium
high_recallSlowestSlowestHighestHigher

Scaling Recommendations

ScaleRecommendation
< 100KUse default config
100K - 1MConsider high_speed if latency-critical
> 1MShard across multiple indexes