k-NN Index

knn_vector data type

The k-NN plugin introduces a custom data type, the knn_vector, that allows users to ingest their k-NN vectors into an OpenSearch index.

  1. "my_vector": {
  2. "type": "knn_vector",
  3. "dimension": 4,
  4. "method": {
  5. "name": "hnsw",
  6. "space_type": "l2",
  7. "engine": "nmslib",
  8. "parameters": {
  9. "ef_construction": 128,
  10. "m": 24
  11. }
  12. }
  13. }
Mapping PararameterRequiredDefaultUpdateableDescription
typetruen/afalseThe type of the field
dimensiontruen/afalseThe vector dimension for the field
methodfalsenullfalseThe configuration for the Approximate nearest neighbor method
method.nametrue, if method is specifiedn/afalseThe identifier for the nearest neighbor method. Currently, “hnsw” is the only valid method.
method.space_typefalse“l2”falseThe vector space used to calculate the distance between vectors. Refer to here) to see available spaces.
method.enginefalse“nmslib”falseThe approximate k-NN library to use for indexing and search. Currently, “nmslib” is the only valid engine.
method.parametersfalsenullfalseThe parameters used for the nearest neighbor method.
method.parameters.ef_constructionfalse512falseThe size of the dynamic list used during k-NN graph creation. Higher values lead to a more accurate graph, but slower indexing speed. Only valid for “hnsw” method.
method.parameters.mfalse16falseThe number of bidirectional links that the plugin creates for each new element. Increasing and decreasing this value can have a large impact on memory consumption. Keep this value between 2-100. Only valid for “hnsw” method

Index settings

Additionally, the k-NN plugin introduces several index settings that can be used to configure the k-NN structure as well.

At the moment, several parameters defined in the settings are in the deprecation process. Those parameters should be set in the mapping instead of the index settings. Parameters set in the mapping will override the parameters set in the index settings. Setting the parameters in the mapping allows an index to have multiple knn_vector fields with different parameters.

SettingDefaultUpdateableDescription
index.knnfalsefalseWhether the index should build hnsw graphs for the knn_vector fields. If set to false, the knn_vector fields will be stored in doc values, but Approximate k-NN search functionality will be disabled.
index.knn.algo_param.ef_search512trueThe size of the dynamic list used during k-NN searches. Higher values lead to more accurate but slower searches.
index.knn.algo_param.ef_construction512false(Deprecated in 1.0.0. Use the mapping parameters to set this value instead.) Refer to mapping definition.
index.knn.algo_param.m16false(Deprecated in 1.0.0. Use the mapping parameters to set this value instead.) Refer to mapping definition.
index.knn.space_type“l2”false(Deprecated in 1.0.0. Use the mapping parameters to set this value instead.) Refer to mapping definition.