GPU_IVF_PQ
The GPU_IVF_PQ index builds on the IVF_PQ concept by combining inverted file clustering with Product Quantization (PQ), which breaks down high-dimensional vectors into smaller subspaces and quantizes them for efficient similarity searches. Exclusively designed for GPU environments, GPU_IVF_PQ leverages parallel processing to accelerate computations and handle large-scale vector data effectively. For more information on foundational concepts, refer to IVF_PQ.
Build index
To build a GPU_IVF_PQ
index on a vector field in Milvus, use the add_index()
method, specifying the index_type
, metric_type
, and additional parameters for the index.
from pymilvus import MilvusClient
# Prepare index building params
index_params = MilvusClient.prepare_index_params()
index_params.add_index(
field_name="your_vector_field_name", # Name of the vector field to be indexed
index_type="GPU_IVF_PQ", # Type of the index to create
index_name="vector_index", # Name of the index to create
metric_type="L2", # Metric type used to measure similarity
params={
"m": 4, # Number of sub-vectors to split eahc vector into
} # Index building params
)
In this configuration:
index_type
: The type of index to be built. In this example, set the value toGPU_IVF_PQ
.metric_type
: The method used to calculate the distance between vectors. Supported values includeCOSINE
,L2
, andIP
. For details, refer to Metric Types.params
: Additional configuration options for building the index.m
: Number of sub-vectors to split the vector into.
To learn more building parameters available for the
GPU_IVF_PQ
index, refer to Index building params.
Once the index parameters are configured, you can create the index by using the create_index()
method directly or passing the index params in the create_collection
method. For details, refer to Create Collection.
Search on index
Once the index is built and entities are inserted, you can perform similarity searches on the index.
search_params = {
"params": {
"nprobe": 10, # Number of clusters to search
}
}
res = MilvusClient.search(
collection_name="your_collection_name", # Collection name
anns_field="vector_field", # Vector field name
data=[[0.1, 0.2, 0.3, 0.4, 0.5]], # Query vector
limit=3, # TopK results to return
search_params=search_params
)
In this configuration:
params
: Additional configuration options for searching on the index.nprobe
: Number of clusters to search for.
To learn more search parameters available for the
GPU_IVF_PQ
index, refer to Index-specific search params.
Index params
This section provides an overview of the parameters used for building an index and performing searches on the index.
Index building params
The following table lists the parameters that can be configured in params
when building an index.
Parameter |
Description |
Value Range |
Tuning Suggestion |
|
---|---|---|---|---|
IVF |
|
The number of clusters to create using the k-means algorithm during index building. |
Type: Integer Range: [1, 65536] Default value: |
Larger |
PQ |
|
The number of sub-vectors (used for quantization) to divide each high-dimensional vector into during the quantization process. |
Type: Integer Range: [1, 65536] Default value: None |
A higher In most cases, we recommend you set a value within this range: [D/8, D]. |
|
The number of bits used to represent each sub-vector's centroid index in the compressed form. It directly determines the size of each codebook.
Each codebook will contain $2^{\textit{nbits}}$ centroids. For example, if |
Type: Integer Range: [1, 64] Default value: |
A higher |
|
|
Decides whether to cache the original dataset in GPU memory. Possible values:
|
Type: String
Range: [ Default value: |
Setting it to |
Index-specific search params
The following table lists the parameters that can be configured in search_params.params
when searching on the index.
Parameter |
Description |
Value Range |
Tuning Suggestion |
|
---|---|---|---|---|
IVF |
|
The number of clusters to search for candidates. |
Type: Integer Range: [1, nlist] Default value: |
Higher values allow more clusters to be searched, improving recall by expanding the search scope but at the cost of increased query latency.
Set In most cases, we recommend you set a value within this range: [1, nlist]. |