Navigation
๐Ÿ’พ Data & Storageยท 8 min read

Performance Tuning

Latency vs recall tradeoff, batch query optimization, metadata predicate filtering, and quantization for vectors.

vector-performancerecalllatencyquantizationpqtuning

Vector search performance is defined by the recall-latency-memory triangle โ€” you can optimize any two at the expense of the third.


1. The Recall-Latency Tradeoff

ConfigurationRecallLatency (1M vectors)Memory
Flat (exact)100%10 ms100%
HNSW (ef=64)98%0.5 ms120% (graph overhead)
HNSW (ef=16)92%0.2 ms120%
IVF (nprobe=32)96%0.8 ms100%
IVF + PQ90%0.3 ms10% (compressed!)

Product Quantization (PQ): Compress vectors from 768 floats (3 KB) to 96 bytes โ€” 32ร— memory reduction. Enables billion-scale in-memory search.


2. Key Tuning Parameters

ParameterHigher value โ†’Lower value โ†’
HNSW ef_searchBetter recall, slower searchFaster search, lower recall
HNSW M (connections per node)Better recall, more memoryLess memory, lower recall
IVF nprobeBetter recall, slower searchFaster search, lower recall
IVF nlist (partitions)Faster per-partition, need more nprobeFewer partitions, each larger
PQ num_subvectorsBetter compression, lower recallMore precise, more memory

Tuning Protocol

# Sweep ef_search to find optimal recall-latency point
for ef in [16, 32, 64, 128, 256]:
    index.set_ef(ef)
    recall = measure_recall(index, queries, ground_truth)
    latency = measure_latency(index, queries)
    print(f"ef={ef}: recall={recall:.3f}, latency={latency:.2f}ms")
    
# Target: minimum ef that achieves recall > 0.95

3. Batch Query Optimization

For RAG with many concurrent queries:

# Single query: 0.5ms ร— 100 queries = 50ms total (sequential)
# Batch query: 100 queries in one call = 5ms total (parallel!)

results = index.search(query_batch, k=10)  # batch of 100 queries
# 10ร— speedup from batching

4. Production Performance Targets

Use caseLatency targetRecall targetScale
RAG (real-time)< 10 ms P99> 95%1M-100M
Search (web)< 50 ms P99> 90%100M-1B
Recommendation< 20 ms P99> 85%10M-100M
Deduplication (batch)Throughput-focused> 99%1B+

For operational concerns (index build, updates), see Operational Concerns.


Self-Check

  • Explain the recall-latency-memory triangle
  • Tune HNSW ef_search for a target recall of 95%
  • Explain Product Quantization and its 32ร— memory reduction
  • Calculate batch query speedup for a given query count

References