Vector optimization
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
Go to the application details page.
Log on to the Elasticsearch Serverless console and switch to the desired region in the top navigation bar.
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.
-
In the left-side navigation pane, on the 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.
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.
-
If you manually specify the
excludesfield, your configuration takes precedence. For example, if you specify to exclude themy_textfield inexcludes, query results will only exclude themy_textfield, not the vector field. -
Because a
knnsearch relies on a separate data structure, a vector field excluded from_sourcecan still be used inknnsearches. -
Operations such as Reindex, Update, and Update By Query typically require the
_sourcefield. Excluding a vector field from_sourcemay cause data loss or exceptions during these operations. For example, during reindexing, the new index might not contain thedense_vectorfield.
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.-
Create an index named
my_vector_index.PUT /my_vector_index { "mappings": { "properties": { "my_vector": { "type": "dense_vector", "dims": 3 }, "my_text" : { "type" : "keyword" } } } } -
View the created index.
GET /my_vector_indexThe command returns the following result. The system automatically excludes the dense vector field by adding
my_vectortomapping._source.excludes.
-
-
Scenario 2: Enabling Intelligently filter vector fields and specifying
excludes.-
Create an index named
my_vector_indexand useexcludesto exclude themy_textfield.PUT /my_vector_index { "mappings": { "_source": { "excludes":["my_text"] }, "properties": { "my_vector": { "type": "dense_vector", "dims": 3 }, "my_text" : { "type" : "keyword" } } } } -
View the created index.
GET /my_vector_indexThe command returns the following result. Instead of the dense vector field, the system excludes the specified
my_textfield. Themy_vectorfield does not appear inmapping._source.excludes; onlymy_textdoes.
-
-
Scenario 3: Disabling Intelligently filter vector fields.
-
Create an index named
my_vector_index.PUT /my_vector_index { "mappings": { "properties": { "my_vector": { "type": "dense_vector", "dims": 3 }, "my_text" : { "type" : "keyword" } } } } -
View the created index.
GET /my_vector_indexThe command returns the following result. The system does not exclude any fields, and the response does not contain the
mapping._source.excludesfield.
-
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 occupies1byte, reducing the vector memory footprint by a factor of4. -
int4: Each value occupies half a byte, reducing the vector memory footprint by a factor of8. -
BBQ: Each value occupies1bit.8values use1byte in total. This reduces the vector memory footprint by a factor of32.
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.-
Create an index named
my_vector_index.PUT /my_vector_index { "mappings": { "properties": { "my_vector": { "type": "dense_vector", "dims": 3 }, "my_text" : { "type" : "keyword" } } } } -
View the created index.
GET /my_vector_indexThe command returns the following result. The quantization type for the
my_vectorfield is set toint8_hnsw.
-
-
Scenario 2: The application's default quantization policy is set to
int8, but a different quantization type is specified during index creation.-
Create an index named
my_vector_indexand specify the quantization type for themy_vectorfield asint4_hnsw.PUT /my_vector_index { "mappings": { "properties": { "my_vector": { "type": "dense_vector", "dims": 4, "index_options": { "type": "int4_hnsw" } }, "my_text" : { "type" : "keyword" } } } } -
View the created index.
GET /my_vector_indexThe command returns the following result. The quantization type for the
my_vectorfield is set toint4_hnsw.
-
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.