From 3a770f7dd30f41d7174c852e2dc8c91e895bd287 Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Thu, 29 Sep 2022 09:32:55 +0800 Subject: [PATCH] Suport to create flat index (#19398) Signed-off-by: cai.zhang Signed-off-by: cai.zhang --- internal/indexcoord/const.go | 1 + internal/indexcoord/index_builder.go | 6 +++--- internal/indexcoord/task.go | 2 +- internal/indexcoord/util.go | 2 +- internal/proxy/task.go | 1 + 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/indexcoord/const.go b/internal/indexcoord/const.go index 5def064b8e..d6c37abed3 100644 --- a/internal/indexcoord/const.go +++ b/internal/indexcoord/const.go @@ -21,6 +21,7 @@ const ( IndexAddTaskName = "IndexAddTask" CreateIndexTaskName = "CreateIndexTask" + flatIndex = "FLAT" diskAnnIndex = "DISKANN" invalidIndex = "invalid" ) diff --git a/internal/indexcoord/index_builder.go b/internal/indexcoord/index_builder.go index 503ad95b8c..1eb3aa5477 100644 --- a/internal/indexcoord/index_builder.go +++ b/internal/indexcoord/index_builder.go @@ -212,8 +212,9 @@ func (ib *indexBuilder) process(buildID UniqueID) bool { deleteFunc(buildID) return true } - if meta.NumRows < Params.IndexCoordCfg.MinSegmentNumRowsToEnableIndex { - log.Ctx(ib.ctx).Debug("segment num rows is too few, no need to build index", zap.Int64("buildID", buildID), + indexParams := ib.meta.GetIndexParams(meta.CollectionID, meta.IndexID) + if getIndexType(indexParams) == flatIndex || meta.NumRows < Params.IndexCoordCfg.MinSegmentNumRowsToEnableIndex { + log.Ctx(ib.ctx).Debug("segment does not need index really", zap.Int64("buildID", buildID), zap.Int64("segID", meta.SegmentID), zap.Int64("num rows", meta.NumRows)) if err := ib.meta.FinishTask(&indexpb.IndexTaskInfo{ BuildID: buildID, @@ -271,7 +272,6 @@ func (ib *indexBuilder) process(buildID UniqueID) bool { } typeParams := ib.meta.GetTypeParams(meta.CollectionID, meta.IndexID) - indexParams := ib.meta.GetIndexParams(meta.CollectionID, meta.IndexID) var storageConfig *indexpb.StorageConfig if Params.CommonCfg.StorageType == "local" { diff --git a/internal/indexcoord/task.go b/internal/indexcoord/task.go index 04dc381ac1..5ee2b0d013 100644 --- a/internal/indexcoord/task.go +++ b/internal/indexcoord/task.go @@ -127,7 +127,7 @@ func (cit *CreateIndexTask) PreExecute(ctx context.Context) error { log.Info("IndexCoord CreateIndexTask PreExecute", zap.Int64("collectionID", cit.req.CollectionID), zap.Int64("fieldID", cit.req.FieldID), zap.String("indexName", cit.req.IndexName)) // TODO: check index type is disk index. - if GetIndexType(cit.req.GetIndexParams()) == diskAnnIndex && !cit.indexCoordClient.nodeManager.ClientSupportDisk() { + if getIndexType(cit.req.GetIndexParams()) == diskAnnIndex && !cit.indexCoordClient.nodeManager.ClientSupportDisk() { return errors.New("all IndexNodes do not support disk indexes, please verify") } return nil diff --git a/internal/indexcoord/util.go b/internal/indexcoord/util.go index ac6a07ea1c..3ccffabe1a 100644 --- a/internal/indexcoord/util.go +++ b/internal/indexcoord/util.go @@ -74,7 +74,7 @@ func buildHandoffKey(collID, partID, segID UniqueID) string { return fmt.Sprintf("%s/%d/%d/%d", util.HandoffSegmentPrefix, collID, partID, segID) } -func GetIndexType(indexParams []*commonpb.KeyValuePair) string { +func getIndexType(indexParams []*commonpb.KeyValuePair) string { for _, param := range indexParams { if param.Key == "index_type" { return param.Value diff --git a/internal/proxy/task.go b/internal/proxy/task.go index c46990d57e..6d6e575b09 100644 --- a/internal/proxy/task.go +++ b/internal/proxy/task.go @@ -1191,6 +1191,7 @@ func parseIndexParams(m []*commonpb.KeyValuePair) (map[string]string, error) { } _, exist := indexParams["index_type"] // TODO(dragondriver): change `index_type` to const variable if !exist { + //return nil, errors.New("there is no index_type in index params") indexParams["index_type"] = indexparamcheck.IndexFaissIvfPQ // IVF_PQ is the default index type } return indexParams, nil