mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-06 17:18:35 +08:00
Ref https://github.com/milvus-io/milvus/issues/42148 This PR supports create index for vector array (now, only for `DataType.FLOAT_VECTOR`) and search on it. The index type supported in this PR is `EMB_LIST_HNSW` and the metric type is `MAX_SIM` only. The way to use it: ```python milvus_client = MilvusClient("xxx:19530") schema = milvus_client.create_schema(enable_dynamic_field=True, auto_id=True) ... struct_schema = milvus_client.create_struct_array_field_schema("struct_array_field") ... struct_schema.add_field("struct_float_vec", DataType.ARRAY_OF_VECTOR, element_type=DataType.FLOAT_VECTOR, dim=128, max_capacity=1000) ... schema.add_struct_array_field(struct_schema) index_params = milvus_client.prepare_index_params() index_params.add_index(field_name="struct_float_vec", index_type="EMB_LIST_HNSW", metric_type="MAX_SIM", index_params={"nlist": 128}) ... milvus_client.create_index(COLLECTION_NAME, schema=schema, index_params=index_params) ``` Note: This PR uses `Lims` to convey offsets of the vector array to knowhere where vectors of multiple vector arrays are concatenated and we need offsets to specify which vectors belong to which vector array. --------- Signed-off-by: SpadeA <tangchenjie1210@gmail.com> Signed-off-by: SpadeA-Tang <tangchenjie1210@gmail.com>
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package indexparamcheck
|
|
|
|
import (
|
|
"github.com/cockroachdb/errors"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
|
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
|
|
)
|
|
|
|
type BITMAPChecker struct {
|
|
scalarIndexChecker
|
|
}
|
|
|
|
func (c *BITMAPChecker) CheckTrain(dataType schemapb.DataType, elementType schemapb.DataType, params map[string]string) error {
|
|
return c.scalarIndexChecker.CheckTrain(dataType, elementType, params)
|
|
}
|
|
|
|
func (c *BITMAPChecker) CheckValidDataType(indexType IndexType, field *schemapb.FieldSchema) error {
|
|
if field.IsPrimaryKey {
|
|
return errors.New("create bitmap index on primary key not supported")
|
|
}
|
|
mainType := field.GetDataType()
|
|
elemType := field.GetElementType()
|
|
if !typeutil.IsBoolType(mainType) && !typeutil.IsIntegerType(mainType) &&
|
|
!typeutil.IsStringType(mainType) && !typeutil.IsArrayType(mainType) {
|
|
return errors.New("bitmap index are only supported on bool, int, string and array field")
|
|
}
|
|
if typeutil.IsArrayType(mainType) {
|
|
if !typeutil.IsBoolType(elemType) && !typeutil.IsIntegerType(elemType) &&
|
|
!typeutil.IsStringType(elemType) {
|
|
return errors.New("bitmap index are only supported on bool, int, string for array field")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func newBITMAPChecker() *BITMAPChecker {
|
|
return &BITMAPChecker{}
|
|
}
|