Configuring Vector Indexes for Recall, Latency and Cost
This lesson explains the index settings that decide recall, latency, memory and cost, so a vector database answers queries quickly at the required data size, accuracy target and query rate.
Learning outcomes
After completing this lesson, you will be able to:
- Choose between exact and approximate search, including HNSW and IVF.
- Choose the distance metric, dimensions and quantisation.
- Scale throughput and apply filtering.
Exact and approximate search
Exact k-nearest-neighbour search compares the query with every vector, which is accurate but slow for millions of vectors. Approximate nearest neighbour (ANN) indexes trade a small loss of recall (the share of true nearest neighbours returned) for large speed gains. Two index families dominate.
HNSW (Hierarchical Navigable Small World) builds a multi-layer graph of neighbours. It gives high recall and low latency but uses more memory and is slower to build. Its parameters are m (links per node; more improves recall and memory use), ef_construction (build-time candidate list; higher improves index quality) and ef_search (query-time candidate list; higher improves recall at the cost of latency). IVF (inverted file) clusters vectors and searches only the nearest clusters, controlled by the number of lists and probes; it uses less memory and builds faster, with somewhat lower recall.
HNSW parameters
Distance metric, dimensions and quantisation
The distance metric must match how the embedding model was trained: cosine similarity for most text embeddings, or Euclidean (L2) and inner product where recommended. The index dimension must equal the embedding size. Quantization compresses vectors, for example from 32-bit floats to 8-bit integers or binary vectors, cutting memory by four times or more with a modest recall loss; OpenSearch supports byte and binary vectors and disk-based search modes for large indexes.
The following diagram compares the memory needed to store 300 million embeddings under different dimension and quantisation options.

An index that will not fit
Scaling throughput and filtering
In OpenSearch, shards spread data and replicas add query throughput and availability; OpenSearch Serverless scales OpenSearch Compute Units (OCUs) for indexing and search separately. In pgvector, HNSW and IVFFlat indexes are created with SQL, and selective metadata filters may need iterative index scans so filtered queries still return enough results. Plan for metadata filtering by defining filterable fields at index creation. The following table summarises the main settings.
| Setting | Increase it to | Cost of increasing |
|---|---|---|
| HNSW m | Improve recall | More memory, slower build |
| HNSW ef_search | Improve recall per query | Higher latency |
| IVF probes | Improve recall | Higher latency |
| Replicas | Raise query throughput and availability | More nodes |
| Dimensions | Capture more detail | More storage and compute |
| Quantization level (lower precision) | Cut memory and cost | Some recall loss |
Throughput and filters
An index that will not fit
A team plans to index 300 million chunks with 1,024-dimension float vectors in an OpenSearch domain using HNSW.
Raw vectors: 300,000,000 x 1,024 dims x 4 bytes = ~1.23 TB
HNSW graph overhead (m=16): roughly + 300,000,000 x 16 x 2 x 4 bytes = ~38 GB
Option A: Titan V2 at 256 dims -> ~0.31 TB (4x smaller)
Option B: byte quantization (int8) -> ~0.31 TB at 1,024 dims
Option C: disk-based vector search / S3 Vectors for the long tailAn evaluation shows that 512 dimensions with byte quantisation keep recall@10 above 0.95 on the team's test queries while cutting memory by about eight times. The remaining rarely accessed content moves to S3 Vectors. Simply buying larger instances would work but would multiply cost.
How is recall raised in an HNSW index, and at what cost?
Show answer
By raising ef_search, which increases query latency.
Exam Tips
Remember for the exam
- HNSW: high recall and speed, more memory; IVF: less memory, lower recall.
- Raise ef_search or probes for recall, at the cost of latency.
- Replicas add query throughput; shards spread data.
- Quantization and fewer dimensions shrink large indexes.
- Match the distance metric to the embedding model.