Vector optimization

Updated at:

The Alibaba Cloud Elasticsearch team analyzes vector field usage across dimensions like indexing and querying. Elasticsearch Serverless provides default optimizations and configuration options for vector fields in an index, such as excluding them from storage or compressing their size, to reduce resource consumption and improve search efficiency.

Access vector optimization

  1. Go to the application details page.

    1. Log on to the Elasticsearch Serverless console and switch to the desired region in the top navigation bar.

    2. In the left-side navigation pane, click Application Management. Then, click the name of the application that you created to go to the application details page.

  2. In the left-side navigation pane, on the Vector Optimization tab under Search Performance Tuning Center, you can tune your application's search performance by configuring optimization items such as Intelligently filter vector fields, Default Vector Quantization Policy, and Adaptive Vector Prewarming.

Intelligently filter vector fields

Overview

This feature excludes vector fields from the stored _source field to save storage space and reduce network overhead, accelerate searches, and prevent unnecessary data exposure.

Background

Elasticsearch stores the original JSON document provided during indexing in the _source field. By default, each hit in a search response includes the full content of this field. When a document contains a high-dimensional dense_vector field, the _source field can become very large. Loading and serializing this vector data introduces significant I/O and network overhead, which can severely impact the performance and latency of knn searches.

Note

Vector fields (for example, "image_vector": [0.1, 0.5, ..., 0.9]) are often long and consume significant space.

How it works

When the Intelligently filter vector fields optimization is enabled, the system uses the excludes mapping parameter to exclude dense vector fields from being stored in _source. This avoids loading and returning large amounts of raw vector data during searches, which reduces network overhead and index size. This optimization is enabled by default but can be disabled.

Important
  • If you manually specify the excludes field, your configuration takes precedence. For example, if you specify to exclude the my_text field in excludes, query results will only exclude the my_text field, not the vector field.

  • Because a knn search relies on a separate data structure, a vector field excluded from _source can still be used in knn searches.

  • Operations such as Reindex, Update, and Update By Query typically require the _source field. Excluding a vector field from _source may cause data loss or exceptions during these operations. For example, during reindexing, the new index might not contain the dense_vector field.

Examples

The following scenarios and sample code demonstrate the effect of enabling or disabling the Intelligently filter vector fields optimization.

  • Scenario 1: Enabling Intelligently filter vector fields without specifying excludes.

    1. Create an index named my_vector_index.

      PUT /my_vector_index
      {
        "mappings": {
          "properties": {
            "my_vector": {
              "type": "dense_vector",
              "dims": 3
            },
            "my_text" : {
              "type" : "keyword"
            }
          }
        }
      }
    2. View the created index.

      GET /my_vector_index

      The command returns the following result. The system automatically excludes the dense vector field by adding my_vector to mapping._source.excludes.

      Example code

      {
        "my_vector_index": {
          "aliases": {},
          "mappings": {
            "_source": {
              "excludes": [
                "my_vector"
              ]
            },
            "properties": {
              "my_text": {
                "type": "keyword"
              },
              "my_vector": {
                "type": "dense_vector",
                "dims": 3,
                "index": true,
                "similarity": "cosine",
                "index_options": {
                  "type": "int8_hnsw",
                  "m": 16,
                  "ef_construction": 100
                }
              }
            }
          },
          "settings": {
            "index": {
              "max_prefix_length": "50",
              "mapping": {
                "nested_objects": {
                  "limit": "100"
                },
                "field_name_length": {
                  "limit": "100"
                }
              },
              "refresh_interval": "1s",
              "number_of_shards": "1",
              "max_wildcard_length": "50",
              "max_refresh_listeners": "20",
              "max_regex_length": "50",
              "max_terms_count": "1024",
              "number_of_replicas": "1"
            }
          }
        }
      }
  • Scenario 2: Enabling Intelligently filter vector fields and specifying excludes.

    1. Create an index named my_vector_index and use excludes to exclude the my_text field.

      PUT /my_vector_index
      {
        "mappings": {
          "_source": {
              "excludes":["my_text"]
          },
          "properties": {
            "my_vector": {
              "type": "dense_vector",
              "dims": 3
            },
            "my_text" : {
              "type" : "keyword"
            }
          }
        }
      }
    2. View the created index.

      GET /my_vector_index

      The command returns the following result. Instead of the dense vector field, the system excludes the specified my_text field. The my_vector field does not appear in mapping._source.excludes; only my_text does.

      Example code

      {
        "my_vector_index": {
          "aliases": {},
          "mappings": {
            "_source": {
              "excludes": [
                "my_text"
              ]
            },
            "properties": {
              "my_text": {
                "type": "keyword"
              },
              "my_vector": {
                "type": "dense_vector",
                "dims": 3,
                "index": true,
                "similarity": "cosine",
                "index_options": {
                  "type": "int8_hnsw",
                  "m": 16,
                  "ef_construction": 100
                }
              }
            }
          },
          "settings": {
            "index": {
              "apack": {
                "metadata": {
                  "index_dense_vector_value_count_limit": "1000000",
                  "index_max_storage": "20.0",
                  "index_dense_vector_mem_limit": "1.0"
                }
              },
              "max_prefix_length": "50",
              "mapping": {
                "nested_objects": {
                  "limit": "100"
                },
                "field_name_length": {
                  "limit": "100"
                }
              },
              "refresh_interval": "1s",
              "number_of_shards": "1",
              "blocks": {
                "read_only_allow_delete": "false"
              },
              "max_wildcard_length": "50",
              "max_refresh_listeners": "20",
              "max_regex_length": "50",
              "max_terms_count": "1024",
              "number_of_replicas": "1"
            }
          }
        }
      }
  • Scenario 3: Disabling Intelligently filter vector fields.

    1. Create an index named my_vector_index.

      PUT /my_vector_index
      {
        "mappings": {
          "properties": {
            "my_vector": {
              "type": "dense_vector",
              "dims": 3
            },
            "my_text" : {
              "type" : "keyword"
            }
          }
        }
      }
    2. View the created index.

      GET /my_vector_index

      The command returns the following result. The system does not exclude any fields, and the response does not contain the mapping._source.excludes field.

      Example code

      {
        "my_vector_index": {
          "aliases": {},
          "mappings": {
            "properties": {
              "my_text": {
                "type": "keyword"
              },
              "my_vector": {
                "type": "dense_vector",
                "dims": 3,
                "index": true,
                "similarity": "cosine",
                "index_options": {
                  "type": "int8_hnsw",
                  "m": 16,
                  "ef_construction": 100
                }
              }
            }
          },
          "settings": {
            "index": {
              "max_prefix_length": "50",
              "mapping": {
                "nested_objects": {
                  "limit": "100"
                },
                "field_name_length": {
                  "limit": "100"
                }
              },
              "refresh_interval": "1s",
              "number_of_shards": "1",
              "max_wildcard_length": "50",
              "max_refresh_listeners": "20",
              "max_regex_length": "50",
              "max_terms_count": "1024",
              "number_of_replicas": "1"
            }
          }
        }
      }

Vector index parameters

index_dense_vector_value_count_limit is an internally reserved redundancy parameter in Elasticsearch Serverless. You cannot modify it, and it is not a limit on the number of vectors in an index or shard. Elasticsearch Serverless currently imposes no limit on the number of vectors. A single index containing 2 million vectors in one shard is not limited by this parameter.

Stress-test your workload before launch. If you encounter an error caused by a quota limit, provide feedback promptly.

Default vector quantization

Overview

This policy converts vectors stored as float32 (4 bytes) into lower-precision formats, such as int8 (1 byte), to compress the vectors. Quantization significantly saves storage and memory, accelerates computations, and maintains high accuracy in most scenarios, balancing efficiency and precision.

Policies

You can select a quantization policy as needed, but you cannot disable this feature. The following policies are supported:

  • int8 (default): Each value occupies 1 byte, reducing the vector memory footprint by a factor of 4.

  • int4: Each value occupies half a byte, reducing the vector memory footprint by a factor of 8.

  • BBQ: Each value occupies 1 bit. 8 values use 1 byte in total. This reduces the vector memory footprint by a factor of 32.

Note

If you specify a quantization type when you create an index, that configuration takes precedence.

Examples

The following scenarios and sample code demonstrate the effects of the Default Vector Quantization Policy optimization.

  • Scenario 1: The application's default quantization policy is set to int8, and no quantization type is specified during index creation.

    1. Create an index named my_vector_index.

      PUT /my_vector_index
      {
        "mappings": {
          "properties": {
            "my_vector": {
              "type": "dense_vector",
              "dims": 3
            },
            "my_text" : {
              "type" : "keyword"
            }
          }
        }
      }
    2. View the created index.

      GET /my_vector_index

      The command returns the following result. The quantization type for the my_vector field is set to int8_hnsw.

      Example code

      {
        "my_vector_index": {
          "aliases": {},
          "mappings": {
            "properties": {
              "my_text": {
                "type": "keyword"
              },
              "my_vector": {
                "type": "dense_vector",
                "dims": 3,
                "index": true,
                "similarity": "cosine",
                "index_options": {
                  "type": "int8_hnsw",
                  "m": 16,
                  "ef_construction": 100
                }
              }
            }
          },
          "settings": {
            "index": {
              "max_prefix_length": "50",
              "mapping": {
                "nested_objects": {
                  "limit": "100"
                },
                "field_name_length": {
                  "limit": "100"
                }
              },
              "refresh_interval": "1s",
              "number_of_shards": "1",
              "max_wildcard_length": "50",
              "max_refresh_listeners": "20",
              "max_regex_length": "50",
              "max_terms_count": "1024",
              "number_of_replicas": "1"
            }
          }
        }
      }
  • Scenario 2: The application's default quantization policy is set to int8, but a different quantization type is specified during index creation.

    1. Create an index named my_vector_index and specify the quantization type for the my_vector field as int4_hnsw.

      PUT /my_vector_index
      {
        "mappings": {
          "properties": {
            "my_vector": {
              "type": "dense_vector",
              "dims": 4,
              "index_options": {
                  "type": "int4_hnsw"
              }
            },
            "my_text" : {
              "type" : "keyword"
            }
          }
        }
      }
    2. View the created index.

      GET /my_vector_index

      The command returns the following result. The quantization type for the my_vector field is set to int4_hnsw.

      Example code

      {
        "my_vector_index": {
          "aliases": {},
          "mappings": {
            "properties": {
              "my_text": {
                "type": "keyword"
              },
              "my_vector": {
                "type": "dense_vector",
                "dims": 4,
                "index": true,
                "similarity": "cosine",
                "index_options": {
                  "type": "int4_hnsw",
                  "m": 16,
                  "ef_construction": 100,
                  "confidence_interval": 0
                }
              }
            }
          },
          "settings": {
            "index": {
              "apack": {
                "metadata": {
                  "index_dense_vector_value_count_limit": "1000000",
                  "index_max_storage": "20.0",
                  "index_dense_vector_mem_limit": "1.0"
                }
              },
              "max_prefix_length": "50",
              "mapping": {
                "nested_objects": {
                  "limit": "100"
                },
                "field_name_length": {
                  "limit": "100"
                }
              },
              "refresh_interval": "1s",
              "number_of_shards": "1",
              "blocks": {
                "read_only_allow_delete": "false"
              },
              "max_wildcard_length": "50",
              "max_refresh_listeners": "20",
              "max_regex_length": "50",
              "max_terms_count": "1024",
              "number_of_replicas": "1"
            }
          }
        }
      }

Adaptive vector prewarming

After the service starts or an index is loaded, this feature automatically preloads vector indexes into memory. This reduces the high first-search latency caused by a cold start and improves stability and throughput in high-concurrency scenarios. This optimization is enabled by default and cannot be disabled or edited.