Lesson 5 of 5 Text Preparation, Embeddings and Vector Databases

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.

Match the pairs

HNSW parameters

Exam skills 1.1.7 · 2.2.9

Match each vector index parameter with its effect.

Log in to try this activity Interactive activities are free with an account.

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.

Memory for 300 million vectors under each option. Float vectors at 1,024 dimensions need about 1.23 TB, plus the HNSW graph. Using 256 dimensions, or byte quantisation at 1,024, cuts that four times. The chosen 512 dimensions with byte quantisation cuts it about eight times while keeping recall@10 above 0.95 on the team's test queries, and rarely accessed content moves to S3 Vectors.
Bar lengths are proportional to raw vector memory.
Troubleshooting scenario

An index that will not fit

Exam skills 1.1.7 · 4.2.10

Fix the memory and quality problems of a growing vector index, one at a time.

Log in to try this activity Interactive activities are free with an account.

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.

SettingIncrease it toCost of increasing
HNSW mImprove recallMore memory, slower build
HNSW ef_searchImprove recall per queryHigher latency
IVF probesImprove recallHigher latency
ReplicasRaise query throughput and availabilityMore nodes
DimensionsCapture more detailMore storage and compute
Quantization level (lower precision)Cut memory and costSome recall loss
True or false

Throughput and filters

Exam skills 1.1.7

Check how vector indexes scale and how filters affect results.

Log in to try this activity Interactive activities are free with an account.
Worked example

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 tail

An 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.

Check yourself

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.