Index Operations
Index APIs create, inspect, and update vector or scalar indexes. Create indexes after collection creation and before loading/searching when you need explicit index configuration.
import { IndexType, MetricType } from '@zilliz/milvus2-sdk-node';createIndex
Section titled “createIndex”Create one or more indexes.
createIndex(data: CreateIndexesReq): Promise<ResStatus>
type CreateIndexesReq = CreateIndexRequest[] | CreateIndexRequest;type CreateIndexRequest = CreateIndexReq | CreateIndexSimpleReq;Simple request shape:
interface CreateIndexSimpleReq { collection_name: string; field_name: string; index_type: string; metric_type?: string; index_name?: string; params?: Record<string, number | string | boolean>; db_name?: string; timeout?: number;}Legacy request shape:
interface CreateIndexReq { collection_name: string; field_name: string; index_name?: string; extra_params?: { index_type?: string; metric_type: string; params?: string; }; db_name?: string; timeout?: number;}Example:
await client.createIndex({ collection_name: 'books', field_name: 'embedding', index_name: 'embedding_index', index_type: IndexType.HNSW, metric_type: MetricType.COSINE, params: { M: 16, efConstruction: 200 },});Create multiple indexes:
await client.createIndex([ { collection_name: 'books', field_name: 'embedding', index_type: IndexType.AUTOINDEX, metric_type: MetricType.COSINE, }, { collection_name: 'books', field_name: 'title', index_name: 'title_inverted', index_type: IndexType.INVERTED, },]);describeIndex
Section titled “describeIndex”Describe indexes on a collection. Filter by field or index name when needed.
describeIndex(data: DescribeIndexReq): Promise<DescribeIndexResponse>Parameters:
collection_name: Collection name.field_name?: Field name.index_name?: Index name.db_name?: Database name.timeout?: Request timeout in milliseconds.
Response:
interface DescribeIndexResponse { status: ResStatus; index_descriptions: IndexDescription[];}
interface IndexDescription { index_name: string; indexID: number; params: KeyValuePair[]; field_name: string; indexed_rows: string; total_rows: string; state: string; index_state_fail_reason: string; pending_index_rows: string;}Example:
const res = await client.describeIndex({ collection_name: 'books', index_name: 'embedding_index',});listIndexes
Section titled “listIndexes”List index names for a collection.
listIndexes(data: DescribeIndexReq): Promise<ListIndexResponse>Response:
status: Response status.indexes: Index names.
Example:
const { indexes } = await client.listIndexes({ collection_name: 'books' });getIndexState
Section titled “getIndexState”Get index build state.
getIndexState(data: GetIndexStateReq): Promise<GetIndexStateResponse>Parameters are the same as DescribeIndexReq.
Response:
status: Response status.state:IndexState.
This API is deprecated in some Milvus versions. Prefer
describeIndexorgetIndexStatisticswhen available.
getIndexBuildProgress
Section titled “getIndexBuildProgress”Get indexed row count and total row count while an index is building.
getIndexBuildProgress(data: GetIndexBuildProgressReq): Promise<GetIndexBuildProgressResponse>Parameters:
collection_name: Collection name.field_name?: Field name.index_name?: Index name.db_name?: Database name.timeout?: Request timeout in milliseconds.
Response:
indexed_rows: Number of indexed rows.total_rows: Total row count.
getIndexStatistics
Section titled “getIndexStatistics”Get index statistics including index state and row counts.
getIndexStatistics(data: DescribeIndexReq): Promise<DescribeIndexResponse>Use this when you need the full IndexDescription[] structure.
alterIndexProperties
Section titled “alterIndexProperties”Modify mutable index properties.
alterIndexProperties(data: AlterIndexReq): Promise<ResStatus>alterIndex(data: AlterIndexReq): Promise<ResStatus> // deprecated aliasParameters:
collection_name: Collection name.index_name: Index name.params: Properties to update.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.alterIndexProperties({ collection_name: 'books', index_name: 'embedding_index', params: { 'mmap.enabled': true },});dropIndexProperties
Section titled “dropIndexProperties”Remove index properties.
dropIndexProperties(data: DropIndexPropertiesReq): Promise<ResStatus>Parameters:
collection_name: Collection name.index_name: Index name.properties: Property keys to remove.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.dropIndexProperties({ collection_name: 'books', index_name: 'embedding_index', properties: ['mmap.enabled'],});dropIndex
Section titled “dropIndex”Drop an index.
dropIndex(data: DropIndexReq): Promise<ResStatus>Parameters:
collection_name: Collection name.field_name?: Field name.index_name?: Index name.db_name?: Database name.timeout?: Request timeout in milliseconds.
Example:
await client.dropIndex({ collection_name: 'books', index_name: 'embedding_index',});Common index and metric enums
Section titled “Common index and metric enums”enum IndexType { FLAT = 'FLAT', IVF_FLAT = 'IVF_FLAT', IVF_SQ8 = 'IVF_SQ8', IVF_PQ = 'IVF_PQ', HNSW = 'HNSW', DISKANN = 'DISKANN', AUTOINDEX = 'AUTOINDEX', SPARSE_INVERTED_INDEX = 'SPARSE_INVERTED_INDEX', SPARSE_WAND = 'SPARSE_WAND', INVERTED = 'INVERTED', BITMAP = 'BITMAP', MINHASH_LSH = 'MINHASH_LSH', RTREE = 'RTREE',}
enum MetricType { L2 = 'L2', IP = 'IP', COSINE = 'COSINE', HAMMING = 'HAMMING', JACCARD = 'JACCARD', BM25 = 'BM25', MAX_SIM = 'MAX_SIM',}