Lesson 4 of 4 Embeddings and Vector Stores

Scaling Vector Search Performance

This lesson covers index algorithms, sharding, multi-index and hierarchical designs that keep semantic search fast and affordable at millions or billions of vectors and high query rates.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose an approximate nearest neighbor algorithm.
  • Size OpenSearch shards and replicas.
  • Use multi-index and hierarchical designs.

Approximate nearest neighbour algorithms

Exact nearest neighbour search compares the query with every vector, which does not scale. Approximate nearest neighbour (ANN) algorithms trade a little recall for large speed gains. HNSW (hierarchical navigable small world) builds a layered graph of vectors and navigates it from coarse to fine; it gives high recall and low latency but keeps the graph in memory. Its parameters are m (links per node), ef_construction (build-time search breadth) and ef_search (query-time breadth): higher values raise recall and cost. IVF (inverted file) clusters vectors and searches only the nearest clusters, using less memory but needing training on the data.

Quantization compresses vectors, for example from 32-bit floats to 16-bit, 8-bit or binary representations, reducing memory by two to thirty-two times, with rescoring to recover accuracy. OpenSearch supports byte and binary vectors, Faiss product quantisation and disk-based vector search modes that keep compressed vectors in memory and full vectors on disk.

The following diagram shows a search moving through the layers of an HNSW graph.

How HNSW search navigates a layered graph. A search enters at the sparse top layer, moves greedily toward the query, then drops to denser layers and refines until it reaches the nearest neighbours in the bottom layer. The parameters m, ef_construction and ef_search trade recall against memory and time.
The graph is schematic; real layers hold far more vectors.
Match the pairs

ANN techniques

Exam skills 1.4.3

Match each vector search technique with its description.

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

OpenSearch sharding and replicas

An OpenSearch index is split into primary shards spread across data nodes, each with replica shards. Queries run on all shards in parallel. Too few large shards limit parallelism and slow recovery; too many small shards waste memory and coordination overhead. A common guideline is shard sizes of about 10 to 50 GB, enough memory on data nodes to hold the vector graphs, and replicas to increase read throughput and availability. In OpenSearch Serverless, capacity scales in OCUs, and maximum OCU limits cap cost.

The following diagram compares a 400-million-vector OpenSearch index before and after changes that fix its latency.

Fixing latency in a 400-million-vector OpenSearch index. Two 900 GB shards were far larger than the 10 to 50 GB guideline and the vector graphs barely fit in memory. Re-indexing into more, smaller shards on more data nodes, adding replicas, enabling vector quantisation and splitting the index by business domain address both latency and memory.
Each change addresses memory, latency or both.

10–50GB

Guideline size of an OpenSearch shard

Scenario questions

Shards and replicas

Exam skills 1.4.3 · 4.2.2

Practise sizing an OpenSearch vector index.

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

Multi-index and hierarchical designs

A multi-index design keeps a separate index per domain, language, tenant or document type. A query searches only the relevant index (chosen by a router or metadata), which is faster and more precise, and each index can use its own embedding model, chunking and settings. Index aliases let applications query a stable name while indexes are rebuilt behind it.

Hierarchical indexing organises content in levels: document or section summaries are embedded and searched first, then only the chunks inside the best-matching documents are searched. Bedrock Knowledge Bases' hierarchical chunking applies a related idea at chunk level: small child chunks are matched and their parent chunks returned. The following table summarises the techniques.

TechniqueImprovesTrade-off
Tune HNSW m, ef_construction, ef_searchRecall versus latency balanceMemory and build time
Vector quantisationMemory and costSmall accuracy loss; rescoring helps
Right-sized shards and replicasParallelism, throughput, availabilityMore nodes
Multi-index per domain or tenantSpeed, precision, isolationRouting logic
Hierarchical (summary then chunk)Precision on large corporaExtra ingestion step
Worked example

Latency at scale

A RAG application's OpenSearch index has grown to 400 million vectors in two 900 GB shards. Latency is high, and data nodes are near their memory limit.

The shards are far too large and the graphs barely fit in memory. Re-indexing into more, smaller shards on additional data nodes, adding replicas for read throughput, enabling vector quantisation to reduce memory, and splitting the index by business domain so most queries search a fraction of the data, together address latency and memory.

Check yourself

What is the effect of raising the HNSW m and ef values?

Show answer

Recall improves, but memory, indexing time and query latency increase.

Exam Tips

Remember for the exam

  • HNSW: higher m and ef values raise recall and cost.
  • Quantization reduces vector memory with a small accuracy loss.
  • Keep OpenSearch shards around 10 to 50 GB; add replicas for reads.
  • Separate indexes per domain or tenant; search only the relevant one.