Why OpenSearch vector search performance tuning starts with segments and shards
Teams whose k-NN queries are slow or inconsistent after moving to self-hosted OpenSearch usually have a segment problem before they have a hardware problem. In OpenSearch, a knn_vector index is built per field and per Lucene segment, and queries run sequentially across a shard's segments. The coordinating node then selects the final neighbors from the per-shard results. Latency therefore depends on how many segments each shard holds and how large each per-segment graph is, not only on the total number of vectors in the index. Recall depends on those same graphs, so a layout that is slow is often also one that returns uneven results.
Plan this tuning before go-live, after the dataset grows significantly, and whenever recall drops for queries that used to return good neighbors. Before go-live, decide the shard count and the refresh and merge behavior that will shape segment counts, because changing them later means reindexing. After growth, check whether segment counts have climbed as bulk loads and refreshes added small segments. When recall falls, compare results against an exact search on a sample before changing engine or method settings. Confirm the exact behavior of your OpenSearch version in the vector search performance tuning docs before you commit to a layout.
This tuning does not replace memory sizing. A shard layout that spreads vectors evenly can still fail if the graphs do not fit in the memory the nodes can give them, and a well-sized node can still be slow if a shard holds too many small segments. Start by estimating vector memory for your dimension count, data type and engine, then tune segments and shards within that budget. Ask your team to record the current shard count, segment count per shard, and p95 latency and recall on a fixed query set, so each later change can be measured against a known baseline.
How a k-NN query flows through shards and segments
The request starts at a client and reaches a coordinating node, which fans the query out to every shard that holds part of the index. Inside each shard, the query runs sequentially across the Lucene segments, and each segment has its own knn_vector graph, so the cost of a query grows with the number of segments it must visit. The coordinating node then merges the per-shard candidates and selects the final neighbors. Check segment counts per shard first, because that is where latency accumulates, and check the index-time settings that shape each graph before tuning query parameters.
Query fan-out across shards, with the per-segment search where latency accumulates.
How per-segment graphs and segment counts change query latency
Segment count directly sets how much work each k-NN query does. For every knn_vector field, OpenSearch builds a separate approximate graph for each Lucene segment. Queries do not search those graphs in parallel within a shard. They run one after another across the shard's segments, and the coordinating node then merges the per-shard results into the final neighbors. A shard with 3 segments therefore performs roughly three graph searches per query, and a shard with 30 performs thirty, each with its own entry point and traversal cost. Latency tracks that count, so a shard that looks healthy on document count can still be slow because it is fragmented into many small segments.
Segment count is shaped by three timing decisions. Refresh creates a new searchable segment on a fixed interval, so a short refresh interval on a busy index produces many small segments and many small graphs. Background merges combine segments over time, which reduces the count but also rebuilds graphs, so heavy merging competes with indexing for CPU and memory. Force-merge reduces a shard to a target number of segments on demand, which is useful for a read-mostly index after bulk loading but expensive to run on an active index. Plan these settings together: a bulk load followed by a controlled force-merge, then a longer refresh interval for steady-state ingest, is a common pattern to test against your own data. Confirm the current merge and force-merge guidance for your OpenSearch version in the vector search performance tuning docs before you set a target segment count.
Which tuning levers fit which workload
This table compares the main levers for approximate k-NN in OpenSearch and what each one trades: latency, recall, indexing throughput and memory. Read each row as a starting point for a benchmark, not a fixed setting, and change one lever at a time against your own vectors and query mix. The main takeaway is that most levers move several outcomes at once, so the right choice depends on which outcome your workload cannot give up.
| Lever | What it trades | When it fits |
|---|---|---|
| Shard count and primary shard size | Query fan-out and merge cost against per-shard graph size and recovery time | Fit shard count to your data volume and node count first; many small shards add coordination overhead on every k-NN query |
| Segment count and force-merge policy | Query latency (fewer segments are searched) against merge I/O during and after indexing | Force-merge after bulk loads on read-heavy indexes; avoid merging continuously on indexes that still receive heavy writes |
| Refresh interval during bulk loads | Indexing throughput against data visibility and the number of small segments created | Lengthen or disable refresh during initial loads, then restore it before serving queries; keep it short for near-real-time data |
| Engine choice (Faiss, Lucene) | Build speed, memory use, filtering behavior and supported quantization against dataset size and operating model | Confirm the engine supports your method, filters and compression before you build; Faiss suits large, throughput-heavy datasets and Lucene suits smaller ones with filters |
| NMSLIB (legacy) | Compatibility with older indexes against maintenance and feature direction | Use only to read or maintain existing indexes; plan a migration path for new work |
| HNSW m (graph connectivity) | Recall and memory per vector against graph build cost and index size | Raise m when recall is short and memory allows; lower it to reduce index size on large, recall-tolerant datasets |
| HNSW ef_construction (build quality) | Index recall and build time against indexing throughput | Raise it when the graph must be high quality from the start; lower it when rebuild speed matters more than peak recall |
| Query-time ef_search | Recall and latency per query, with no rebuild required | Tune first when recall is short at query time; raise it until recall flattens, then stop, because latency keeps climbing |
Choosing an engine by dataset size and filtering needs
When the index is modest in size and most queries combine vector similarity with metadata filters such as tenant, language, date range or access group, the Lucene engine is usually the first option to evaluate. Lucene integrates closely with the rest of the search stack, so filtered queries follow the same code path as keyword queries, and the planner has fewer moving parts to tune. Filtering is often where teams get surprised by recall or latency, so measure filtered queries specifically rather than only unfiltered ones.
- Filter selectivity: Narrow filters can change how many candidates the graph search must visit, so test the most selective filters your users actually apply.
- Operational simplicity: Fewer engine-specific settings usually means less tuning work for a team that does not run vector workloads full time.
- Segment behavior: Many small segments are searched one after another on each shard, so check how your refresh and merge settings affect query time.
- Metadata design: Keep filter fields in mappings that match the query pattern, since poorly chosen field types make filtered search slower.
- Dimension and count checks: Confirm vector dimension and document count against the engine documentation before committing to a design.
Before you settle on this tab, run a benchmark with your own embeddings, your real filters and your expected query concurrency, and compare recall against an exact baseline. The engine decision is the k-NN engine comparison topic that covers Faiss, Lucene and JVector in depth.
When the collection is large and the workload is driven by query throughput or heavy indexing, the Faiss engine is commonly evaluated because it offers HNSW graphs with compression options and a mature set of tuning parameters. The trade-off is more configuration: graph parameters, quantization choices and search-time settings all affect the balance between recall, latency and memory, and they need to be tested together rather than one at a time.
- Graph parameters: Construction settings control index build cost and graph quality, and they shape the recall ceiling you can reach later.
- Search-time settings: Query-time parameters trade latency for recall, so set them against a target recall you have measured.
- Indexing throughput: Bulk size, refresh interval and concurrency determine how quickly segments form, which affects both build time and query performance.
- Compression effects: Quantized vectors reduce memory but can lower recall, so validate recall after each compression choice.
- Shard and segment counts: Sizing shards so each node handles the segments it needs is a major lever on latency at high volume.
Ask your engineering team and benchmark partner to document the exact settings used in every test run, so results can be reproduced when the dataset grows. Confirm current engine options and supported methods in the official OpenSearch documentation for your version, because available options change between releases.
When nodes have limited RAM and the full vector set does not fit comfortably in memory, the engine decision is closely tied to memory strategy. Disk-based and compressed approaches reduce the working set, but they add a cost in latency or require a rescoring step with full-precision vectors. The right choice depends on how much latency your application can tolerate and how much recall loss is acceptable for the use case.
- Memory headroom: Measure heap and off-heap usage under realistic load, not only at idle, since vector search can spike memory during merges and queries.
- Rescoring cost: Two-phase approaches fetch full-precision vectors for final ranking, which adds I/O and latency that must be benchmarked.
- Storage performance: Disk-based search depends on the speed and latency of the storage underneath, so test on the hardware you will run in production.
- Node sizing: Adding nodes can be simpler than tuning aggressively, but it changes the cost and operations model, so compare both options.
- Recall targets: Set a minimum acceptable recall with the business owner before testing, so trade-offs are judged against a fixed goal.
For memory-constrained designs, the engine choice, quantization and disk-based search should be decided together. Review the sibling topics on reducing vector memory with quantization and on-disk search, and confirm which options your OpenSearch version supports before you plan capacity.
How to run a tuning cycle on your own data
This sequence turns vague tuning advice into a repeatable test on your own vectors and queries, so each change to engine, graph settings, segment layout or indexing behavior is judged by measured latency and recall. The output is a documented configuration you can defend in a review.
Capture a representative dataset and query set
Your team exports a sample of the real vectors, their metadata and the filters your application applies, along with a set of production-like queries. Include the largest collection you expect to serve, or a scaled sample that you can justify. Record the embedding model and dimension so the test can be repeated. The step is done when you have a frozen dataset, a frozen query set, and a written note of how the sample was drawn, so later runs compare like with like.
Compute exact baseline results
Before building any approximate index, run brute-force exact search over the same vectors for every test query and store the top results as ground truth. This baseline is the reference for recall in every later run. Confirm that the exact results are computed against the same vector values and distance metric the index will use, because a mismatch here invalidates every recall number that follows. The step is done when the ground truth file is versioned alongside the dataset.
Create the index with a chosen engine and HNSW settings
Create a test index with a knn_vector mapping, choosing the engine and method your dataset size and filtering needs point toward, along with the HNSW graph parameters you plan to start from. Keep the settings in version-controlled index templates so each run is traceable. Confirm the exact parameter names and supported combinations for your OpenSearch version in the vector search documentation before you rely on them. The step is done when the index exists with the intended mapping and you have recorded every setting in the run log.
Load with bulk indexing and controlled refresh
Load the dataset with the bulk API, using batch sizes your cluster handles without rejections, and set the refresh interval to a long value or disable it for the duration of the load. Keep the load client and the cluster on the same test topology you plan to run in production. After loading, restore the refresh interval and wait for indexing to finish. The step is done when document counts match the source, no bulk items failed, and indexing throughput is recorded for the run.
Check segment counts and merge deliberately
Inspect the segment count per shard after loading, since each segment holds its own vector graph and queries visit segments sequentially. If segment counts are high, decide whether to force merge down to a small number of segments, and do it as a planned action because merging is expensive and must not run on a live index that is still receiving writes. Record the segment count before and after, and the time the merge took. The step is done when the segment layout matches the plan for this run and the choice to merge or not is written down.
Warm caches with representative queries
Run a warmup pass using a sample of the production query set before any measurement, so that graph and file caches reflect realistic access. Use the same filters and result sizes your application uses. Discard warmup results from the report. The step is done when the warmup has completed without errors and the node memory and cache behavior is steady across two consecutive short windows, which you confirm from cluster stats rather than assumption.
Measure latency percentiles and recall against exact search
Run the full query set at the concurrency your application expects, and record latency at the percentiles your service levels use, not only averages. Compute recall at k by comparing each approximate result list with the stored exact results. Repeat the run with one setting changed at a time so the effect of each change is visible. The step is done when you have a results table with latency percentiles, recall, and the exact configuration for each run, and you can state which configuration meets both your latency target and your recall target.
Record the chosen configuration and plan the retest
Write down the winning configuration, the measured numbers, the dataset sample, and the known limits of the test, including any gap between the test cluster and production. Define the checks you will repeat after data growth, version upgrades, or changes to the embedding model, such as segment counts and recall against the same ground truth. The step is done when the record is stored with the index templates and a named owner is responsible for rerunning the cycle.
Indexing throughput and warmup settings that affect first queries
During a bulk load, three settings decide how fast vectors land in the index: bulk request size, the index refresh_interval, and number_of_replicas. Each knn_vector field builds its own graph per Lucene segment, so every refresh that flushes a small segment creates more graph work and more segments to search later. For a large initial load, teams commonly raise the refresh interval or disable refresh until the load finishes, then restore it and let the cluster catch up. Set the replica count to zero during the bulk load and restore it afterward, since each replica repeats indexing work. Bulk size is a tuning exercise: test batch sizes against your node heap and the indexing threads on each node, and confirm the current guidance in the OpenSearch docs for your version.
Vector graphs take time to load into memory, so the first query against a shard after a restart, a relocation, or a segment merge can be slower than steady-state queries. Native graphs are loaded on demand, and a merge creates new segments whose graphs must be read before they answer queries. Plan for this in your rollout: after a node restart or a large merge, send a set of representative queries before routing live traffic to the index. Use real query vectors sampled from production or a realistic synthetic set, include filtered queries if your application uses them, and run enough requests to touch every shard. This warmup is an operational step you own, so script it and include it in your runbook.
Before you rely on warmup, confirm how your chosen version loads and caches vector data, including which graphs stay resident, how circuit breakers and native memory limits behave, and whether any cache settings are exposed. Behavior differs between the Faiss, Lucene, and JVector engines, so read the vector search pages for the version you run rather than assuming behavior carries over between releases. Measure first-query latency after a controlled restart in a test cluster that mirrors production data volume, then compare it with steady-state latency. That gap tells you how long warmup must run and whether your recovery time objective accepts it.
Security and operational risks while tuning
Tuning runs against live data, changes production index settings, and can shift memory and query behavior across the cluster. The cards below cover the access, permission, memory, rollout, monitoring and reproducibility risks to plan for before changing anything in a production cluster.
Benchmark data with sensitive content
Recall and latency tests need realistic vectors, and the source documents behind them often contain personal, financial or health data. Copies of that corpus in a benchmark cluster, or in test scripts and logs, widen the exposure. Confirm who can read the sample data, whether embeddings can be inverted to recover text, and whether the benchmark cluster sits under the same access and retention rules as production. Prefer synthetic or de-identified samples where the workload allows it.
OpenSearch security docsRoles needed to change production settings
Changing index settings, cluster settings and index templates in production usually needs cluster-level privileges that are broader than a search role. Map which people and service accounts need those rights during a tuning window, and remove them afterward. Use the Security plugin's role-based access control so that tuning operators hold named roles rather than shared admin credentials. Confirm that the roles do not also grant document-level read access the tuning work does not need.
Memory pressure from large graphs
HNSW graphs for knn_vector fields are held in native memory, and the JVM also has to serve queries, merges and indexing. A graph that fits in a test node can push a production node into circuit breaker trips or heavy garbage collection. Before raising ef_search, graph size or replica counts, check heap, native memory and breaker statistics on the nodes that hold the data. Confirm the headroom with the actual shard layout, not the average shard size.
Rollout risk when changing engines
Moving a field to a different engine, method or compression setting usually means a new index and a reindex, not an in-place change. The cutover then depends on alias switching, dual reads during validation, and a rollback path that still holds the old index. Plan the sequence and confirm which index receives writes during the overlap. A reindex at production volume also adds load that can slow search for other tenants.
Monitoring latency and recall over time
A benchmark run shows performance on one day with one data mix. Latency percentiles, query volume, segment counts and recall against a fixed judgment set change as data grows and merges run. Set up dashboards and alerts for p95 and p99 latency, heap and native memory use, and a recurring recall check that uses the same queries each time. Confirm where those metrics are stored and who receives the alerts.
Keeping benchmark results reproducible
A tuning result is only useful if someone can rerun it. Record the OpenSearch version, plugin set, engine and method parameters, shard and segment counts, hardware, data sample version, query set and client settings for each run. Store the index settings and mappings as code so that a change can be reverted and compared. Without that record, a team cannot tell whether a gain came from a setting or from a different dataset or warm cache.
Questions teams ask before tuning OpenSearch vector search
How long does OpenSearch vector search tuning take, and what drives that time?
Duration depends on how many indexes and fields carry vectors, how large the corpus is, how many query patterns must meet latency targets, and how many tuning cycles the team needs to reach an acceptable recall and latency balance. Each cycle means rebuilding or reindexing with new method settings, running the same query set, and comparing results. Clusters with one vector field and a stable dataset usually need fewer cycles than clusters with filtered queries, several embedding models or frequent writes. Ask any partner to base its estimate on a written scope that lists these inputs, and confirm the duration against your own environment before committing.
What does the work need from our team before tuning starts?
Tuning needs three things from your side: a representative benchmark dataset with the embeddings your application really uses, a query set with expected results or relevance judgments, and a test environment that matches production node sizes, OpenSearch version and plugin set. Access to cluster settings, index templates, monitoring metrics and slow-query logs is also needed so changes can be measured. Without realistic data, recall numbers mean little, so ask for a sample that covers your largest index and your heaviest filters.
Can an internal team tune OpenSearch vector search without outside help?
Yes, a team with OpenSearch operations experience and a clear benchmark can do it alone, provided it has time to run repeated tests and someone who owns the recall measurement. The harder parts are interpreting the trade-off between recall, latency, memory and indexing throughput, and knowing which setting caused a change. Teams new to k-NN usually spend most of their effort on building a trustworthy test harness. Outside help is most useful when the workload is large, production risk is high, or the team needs a documented baseline for review.
What should a quote for vector search tuning include?
A useful quote lists the scope in writing: which indexes, fields and query types are covered, which OpenSearch version and deployment model apply, and what environment will be used for testing. It should name the deliverables, such as a benchmark report, recommended index mappings and settings, a rollback plan and a warmup procedure. It should also state what the client must provide, what is one-time work and what recurs, such as retesting after data growth or a version upgrade, and what the client receives at handover. Compare quotes on this written scope rather than on headline effort.
How does tuning change as our vector data grows?
Growth changes the balance between graph quality, segment count and memory use, so settings that met latency targets on a small index can fall short later. More documents mean more segments, more graph work per query and more memory pressure, and filtered queries may return fewer results per shard. Plan to repeat the benchmark at defined growth points, track latency and recall over time, and check shard and segment counts during bulk loads. The exact thresholds depend on your hardware and method choice, so confirm them through testing on your own data.
Does vector search tuning replace hardware sizing?
No. Tuning improves how efficiently the existing nodes use memory, CPU and disk, but it cannot create capacity that the hardware lacks. Sizing still determines whether the vector graphs fit in memory, how many replicas and shards the cluster can hold, and how much headroom remains for indexing and queries. Treat tuning and sizing as connected steps: size the nodes for the expected vector count and dimensions, then tune within that envelope and confirm that the final configuration leaves capacity for failover and growth.
Which tuning settings matter most for latency and recall?
The main levers are the k-NN engine and method parameters, the number of shards and segments per index, the indexing refresh and merge behavior during bulk loads, and warmup of graphs after restarts. Engine choice depends on dataset size and filtering needs, and per-segment graphs mean that segment count directly affects query fan-out. Check the settings in the official tuning guide for your OpenSearch version, such as the documented performance tuning section, and test each change against the same query set before deciding.
Official OpenSearch documentation for vector search tuning
The primary source for how approximate k-NN behaves at the segment level is the OpenSearch vector search performance tuning documentation, OpenSearch vector search performance tuning docs. Read it before you set shard counts or merge policies, because it explains the query flow that drives latency. Vector indexes are built per knn_vector field and per Lucene segment, queries run sequentially across the segments of a shard, and the coordinating node merges the candidate neighbors returned by each shard into the final result. That means every extra segment adds search work on the same shard, and a planning decision that looks harmless on paper can add latency at query time.
Use that flow to frame your own test plan. Ask your team to confirm, against the version you intend to run, how segments are created during bulk loads, when refreshes produce new segments, and what force-merge or merge settings are available. Record the segment count per shard before and after each indexing run, and measure p95 and p99 latency at the same concurrency you expect in production. Treat the documentation as the reference for behavior and the release notes for the exact version as the reference for settings, since k-NN parameters and defaults can change between minor releases.
For node and shard layout, the companion guide in the OpenSearch cluster tuning documentation, OpenSearch cluster tuning guide, covers sizing choices that interact with vector search, including how many primary shards you create and how replicas are placed across nodes. Vector graphs consume native memory on the data nodes that hold them, so shard placement determines whether a node can hold its graphs in memory. Confirm the memory and circuit breaker guidance for your chosen engine with the same documentation before you finalize the cluster layout.
How DeployOpen scopes and delivers OpenSearch vector tuning
DeployOpen plans, implements, tests, documents and supports self-hosted open-source platforms inside your own infrastructure, including cloud accounts, data centers and air-gapped networks. For OpenSearch vector search performance tuning, that means agreeing the latency and recall targets, the cluster and index layout, and the test method in writing before any tuning changes are made.
How we scope
- Engagements are fixed-scope, with the tuning goals, datasets and deliverables agreed in writing before work starts.
- The written scope should name the latency and recall targets, the query mix and the current shard and segment layout.
- Ask for the scope to state which engine, method and settings are in and out of the tuning work.
- Ask for the scope to list which environments are tested and whether production changes are included.
How we build
- We measure the current cluster first, covering per-segment graph behavior, shard and segment counts and indexing throughput.
- Tuning changes are made one at a time in a test environment, with recall and latency recorded for each change.
- Warmup and load tests are run against representative query traffic before any settings are promoted.
- Findings and fixes are recorded so the chosen configuration can be reproduced and reviewed later.
How we hand over
- You receive the final index mappings, engine and method settings, and cluster settings used in the tuned configuration.
- Documentation covers the test method, benchmark results and the reasons each setting was chosen.
- Operators get a runbook for reindexing, warmup, shard and segment monitoring and rollback of settings.
- Handover sessions walk your platform team through the configuration and the tests used to verify it.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers once the tuned configuration is live.
- Retainers can cover re-running recall and latency tests after data growth, OpenSearch upgrades or changed query patterns.
- Ask for the retainer scope to state response expectations, the environments covered and who approves changes.
- Your team keeps ownership of the cluster, and DeployOpen works within the access and change controls you set.

