What HNSW is

HNSW is an approximate nearest neighbour search method used because finding exact k-nearest neighbours is computationally expensive for large datasets. It supports vector search in machine learning and data science pipelines, including retrieval-augmented generation (RAG), where relevant content is retrieved from a large document collection to improve large language model responses. Within OpenSearch, HNSW graphs are built during indexing as the core structure that powers ANN search across vector data.

  • Approximate nearest neighbour (ANN) search method
  • Alternative to computationally expensive exact k-NN search
  • Graph structure built at index time
  • Used in vector search and RAG pipelines

Sources: A practical guide to selecting HNSW hyperparameters - OpenSearch, Do more with less: Save up to 3x on storage with derived vector source - OpenSearch

Key hyperparameters

The structure of the HNSW graph is controlled by its hyperparameters, which determine how densely vectors are connected. Three parameters are identified as the most important: M, efSearch and efConstruction. In OpenSearch indexes these correspond to the index settings index.knn.algo_param.m, index.knn.algo_param.ef_search and index.knn.algo_param.ef_construction, or to the m, ef_search and ef_construction method parameters on a knn_vector field.

  • M – maximum number of graph edges per vector; higher values increase memory usage but may improve search quality
  • efSearch – size of the candidate queue during search; larger values may improve search quality but increase latency
  • efConstruction – equivalent queue size used during index construction; higher values improve search quality but increase build time

Sources: A practical guide to selecting HNSW hyperparameters - OpenSearch, Recipes to vectors: Building a hybrid search app with OpenSearch - OpenSearch

Recall and throughput trade-off

Configuring HNSW is a multi-objective problem balancing search quality, measured by recall@k, against search speed, measured by query throughput. A denser graph generally improves recall but reduces query throughput, while a sparser graph has the opposite effect. OpenSearch's guidance notes that finding the right balance requires testing multiple configurations, and that index build time and index size are further considerations.

  • Search quality measured as recall@k
  • Search speed measured as queries per second
  • Denser graphs favour recall; sparser graphs favour throughput

Source: A practical guide to selecting HNSW hyperparameters - OpenSearch

Selecting configurations

Hyperparameter optimisation is one automated route to tuning, but it can be computationally expensive with limited benefit where the underlying algorithm is well understood. An alternative is transfer learning, applying knowledge gained from optimising one dataset to another. OpenSearch publishes five precomputed configurations of progressively increasing graph density, derived from a portfolio-learning method and intended to be evaluated in sequence until recall meets requirements. The method normalises recall and throughput by min-max scaling, combines them using assigned weights, averages the weighted metric across datasets and selects the best configuration.

  • Five precomputed configurations of increasing graph density
  • Evaluate configurations sequentially and stop when recall is sufficient
  • Portfolio learning method with leave-one-out and deployment evaluation
  • Worked end-to-end example using the Python client

Source: A practical guide to selecting HNSW hyperparameters - OpenSearch

Use in OpenSearch indexes

HNSW is specified as the method name on a knn_vector field when creating a k-NN index, alongside an engine such as Faiss and a space type such as l2 or innerproduct. The k-NN plugin is enabled per index with the index.knn setting, and index.knn.space_type defines the default vector space used for distance calculations. HNSW fields are used in keyword, semantic and hybrid search applications, and in RAG setups where embeddings are generated by a sentence-transformer or similar model.

  • index.knn: true enables the k-NN plugin for an index
  • method name "hnsw" set on a knn_vector field
  • Engine options include Faiss
  • Space types include l2 and innerproduct

Sources: Recipes to vectors: Building a hybrid search app with OpenSearch - OpenSearch, Zero to RAG: A quick OpenSearch vector database and DeepSeek integration guide - OpenSearch, Introducing byte vector support for Faiss in the OpenSearch vector engine - OpenSearch

Quantisation and compact vector formats

HNSW indexes in OpenSearch can be combined with reduced-precision vector representations to cut memory use. Faiss scalar quantisation (SQfp16) converts each vector dimension from 32-bit to 16-bit floating point and is configured through the encoder parameters of an HNSW method definition, alongside ef_construction and m. Faiss byte vectors store each dimension as a signed 8-bit integer and are enabled with the data_type parameter on an HNSW field. Binary vectors, packed into an int8 byte format, are also supported for HNSW indexes where vector dimensions are a multiple of eight.

  • Faiss SQfp16 scalar quantisation with HNSW
  • Faiss byte vectors via the data_type parameter
  • Binary vectors packed into int8 byte format

Sources: Optimizing OpenSearch with Faiss FP16 scalar quantization: Enhancing memory efficiency and cost-effectiveness - OpenSearch, Introducing byte vector support for Faiss in the OpenSearch vector engine - OpenSearch, Optimize your OpenSearch costs using binary vectors - OpenSearch

Storage and index building

Vector data associated with HNSW is typically stored in several places in OpenSearch: the HNSW graph itself, raw vector values in a columnar format, and the _source field holding the original ingested JSON document. Derived source for vectors addresses the storage overhead of retaining vectors in _source. For large-scale workloads, OpenSearch also describes GPU-accelerated index building using NVIDIA cuVS, with a decoupled architecture comprising a Vector Index Build Service, the OpenSearch Vector Engine and an object store.

  • HNSW graph, columnar vector values and _source as storage components
  • Derived source for vectors reduces storage overhead
  • GPU-accelerated index builds using NVIDIA cuVS

Sources: Do more with less: Save up to 3x on storage with derived vector source - OpenSearch, GPU-accelerated vector search in OpenSearch: A new frontier - OpenSearch

Related search types

Before OpenSearch 2.14, the k-NN plugin provided only top K queries for approximate vector similarity search. OpenSearch 2.14 introduced radial search, which retrieves all points within a specified maximum distance or above a minimum score threshold from a query point, and is supported in both k-NN search and neural search. Radial search is suited to proximity-based filtering, threshold-specific queries and cases where the acceptable similarity range varies.

  • Top K approximate search
  • Radial search by maximum distance
  • Radial search by minimum score

Source: Understanding vector radial search in OpenSearch - OpenSearch

Sources

  1. Do more with less: Save up to 3x on storage with derived vector source - OpenSearch https://opensearch.org/blog/do-more-with-less-save-up-to-3x-on-storage-with-derived-vector-source/ Verified 01 Nov 2026
  2. Recipes to vectors: Building a hybrid search app with OpenSearch - OpenSearch https://opensearch.org/blog/recipes-to-vectors-building-a-hybrid-search-app-with-opensearch/ Verified 01 Nov 2026
  3. A practical guide to selecting HNSW hyperparameters - OpenSearch https://opensearch.org/blog/a-practical-guide-to-selecting-hnsw-hyperparameters/ Verified 01 Nov 2026
  4. GPU-accelerated vector search in OpenSearch: A new frontier - OpenSearch https://opensearch.org/blog/gpu-accelerated-vector-search-opensearch-new-frontier/ Verified 01 Nov 2026
  5. Zero to RAG: A quick OpenSearch vector database and DeepSeek integration guide - OpenSearch https://opensearch.org/blog/deepseek-integration-rag/ Verified 01 Nov 2026
  6. Introducing byte vector support for Faiss in the OpenSearch vector engine - OpenSearch https://opensearch.org/blog/faiss-byte-vector/ Verified 01 Nov 2026
  7. Optimize your OpenSearch costs using binary vectors - OpenSearch https://opensearch.org/blog/lower-your-cost-on-opensearch-using-binary-vectors/ Verified 01 Nov 2026
  8. Optimizing OpenSearch with Faiss FP16 scalar quantization: Enhancing memory efficiency and cost-effectiveness - OpenSearch https://opensearch.org/blog/optimizing-opensearch-with-fp16-quantization/ Verified 01 Nov 2026
  9. Understanding vector radial search in OpenSearch - OpenSearch https://opensearch.org/blog/vector-radial-search/ Verified 01 Nov 2026

Last verified 01 Nov 2026. This entry is compiled from the public web pages listed above. Nothing here is stated that those pages do not, and each of them was read on the date shown.