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.

ANN techniques
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.

10–50GB
Guideline size of an OpenSearch shard
Shards and replicas
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.
| Technique | Improves | Trade-off |
|---|---|---|
| Tune HNSW m, ef_construction, ef_search | Recall versus latency balance | Memory and build time |
| Vector quantisation | Memory and cost | Small accuracy loss; rescoring helps |
| Right-sized shards and replicas | Parallelism, throughput, availability | More nodes |
| Multi-index per domain or tenant | Speed, precision, isolation | Routing logic |
| Hierarchical (summary then chunk) | Precision on large corpora | Extra ingestion step |
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.
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.