vector-databasemilvus

Understanding "a vector field only supports one index type" constraint


Per https://milvus.io/docs/disk_index.md: "Currently, a vector field only supports one index type. Milvus automatically deletes the old index when switching the index type"

(1) Does this mean if I enable In memory index, the Disk Index (which is default enabled per this page) will be deleted? If so, how do I enable it back?

(2) Also, if I enable GPU index, does the CPU In memory index get deleted?

(3) If the GPU indexing failed (e.g. OOM), is the CPU In memory index still valid? or the DB will enter a broken state?


Solution

  • If an index is already applied on a vector field, you must call collection.drop_index() before you assign a new index. Otherwise, you will get this error: "CreateIndex failed: at most one distinct index is allowed per field"

    If the collection is already loaded in memory, you must call collection.release() before you drop the index. Otherwise, you will get this error: "index cannot be dropped, collection is loaded, please release it first"

    No matter GPU index, in-memory index, or disk index, the workflow is the same.

    Example of changing index:

    collection.release()
    collection.drop_index(index_name="vector")
    
    index_params = {
        'metric_type': "L2",
        'index_type': "GPU_IVF_FLAT",
        'params': {'nlist': 100},
    }
    collection.create_index(field_name="vector", index_params=index_params)
    

    Index is deleted when you call collection.drop_index(). When you want to change another index, the old index is deleted by drop_index(). So, at any time, only one index exists on one vector field.