Build an Index
This topic describes how to build an index for vectors in Milvus.
Vector indexes are an organizational unit of metadata used to accelerate vector similarity search. Without index built on vectors, Milvus will perform a brute-force search by default.
See Vector Index and Index Selection for more information about mechanism and varieties of vector indexes.
- Current release of Milvus only supports index on vector field. Future releases will support index on scalar field.
- By default, Milvus does not index a segment with less than 1,024 rows. To change this parameter, configure
minSegmentSizeToEnableIndex
inmilvus.yaml
.
The following example builds a 1024-cluster IVF_FLAT index with Euclidean distance (L2) as the similarity metrics. You can choose the index and metrics that suit your scenario. See Similarity Metrics for more information.
Prepare index parameter
Prepare the index parameters.
index_params = {
"metric_type":"L2",
"index_type":"IVF_FLAT",
"params":{"nlist":1024}
}
const index_params = {
metric_type: "L2",
index_type: "IVF_FLAT",
params: JSON.stringify({ nlist: 1024 }),
};
create index
Collection name (book): book
The name of the field to create an index for (book_intro): book_intro
Index type (FLAT, IVF_FLAT, IVF_SQ8, IVF_PQ, RNSG, HNSW, ANNOY): IVF_FLAT
Index metric type (L2, IP, HAMMING, TANIMOTO): L2
Index params nlist: 1024
Timeout []:
Parameter | Description | Options |
---|---|---|
metric_type |
Type of metrics used to measure similarity of vectors. | For floating point vectors:
|
index_type |
Type of index used to accelerate the vector search. | For floating point vectors:
|
params |
Building parameter(s) specific to the index. See Index Selection for more information. | See Index Selection for more information. |
Parameter | Description | Option |
---|---|---|
metric_type |
Type of metrics used to measure similarity of vectors. | For floating point vectors:
|
index_type |
Type of index used to accelerate the vector search. | For floating point vectors:
|
params |
Building parameter(s) specific to the index. See Index Selection for more information. | See Index Selection for more information. |
Option | Description |
---|---|
--help | Displays help for using the command. |
Build index
Build the index by specifying the vector field name and index parameters.
from pymilvus import Collection
collection = Collection("book") # Get an existing collection.
collection.create_index(
field_name="book_intro",
index_params=index_params
)
Status(code=0, message='')
await milvusClient.indexManager.createIndex({
collection_name: "book",
field_name: "book_intro",
extra_params: index_params,
});
# Follow the previous step.
Parameter | Description |
---|---|
field_name |
Name of the vector field to build index on. |
index_params |
Parameters of the index to build. |
Parameter | Description |
---|---|
collection_name |
Name of the collection to build index in. |
field_name |
Name of the vector field to build index on. |
extra_params |
Parameters of the index to build. |
What's next
- Learn more basic operations of Milvus:
- Explore API references for Milvus SDKs: