diff --git a/internal/proxy/task_search.go b/internal/proxy/task_search.go index 6b469ff544..8dff68401e 100644 --- a/internal/proxy/task_search.go +++ b/internal/proxy/task_search.go @@ -414,6 +414,9 @@ func (t *searchTask) initAdvancedSearchRequest(ctx context.Context) error { if err != nil { return err } + if typeutil.IsFieldSparseFloatVector(t.schema.CollectionSchema, internalSubReq.FieldId) { + metrics.ProxySearchSparseNumNonZeros.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), t.collectionName, metrics.HybridSearchLabel, strconv.FormatInt(internalSubReq.FieldId, 10)).Observe(float64(typeutil.EstimateSparseVectorNNZFromPlaceholderGroup(internalSubReq.PlaceholderGroup, int(internalSubReq.GetNq())))) + } t.SearchRequest.SubReqs[index] = internalSubReq t.queryInfos[index] = queryInfo log.Debug("proxy init search request", @@ -491,7 +494,9 @@ func (t *searchTask) initSearchRequest(ctx context.Context) error { if err != nil { return err } - metrics.ProxySearchSparseNumNonZeros.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), t.collectionName).Observe(float64(typeutil.EstimateSparseVectorNNZFromPlaceholderGroup(t.request.PlaceholderGroup, int(t.request.GetNq())))) + if typeutil.IsFieldSparseFloatVector(t.schema.CollectionSchema, t.SearchRequest.FieldId) { + metrics.ProxySearchSparseNumNonZeros.WithLabelValues(strconv.FormatInt(paramtable.GetNodeID(), 10), t.collectionName, metrics.SearchLabel, strconv.FormatInt(t.SearchRequest.FieldId, 10)).Observe(float64(typeutil.EstimateSparseVectorNNZFromPlaceholderGroup(t.request.PlaceholderGroup, int(t.request.GetNq())))) + } t.SearchRequest.PlaceholderGroup = t.request.PlaceholderGroup t.SearchRequest.Topk = queryInfo.GetTopk() t.SearchRequest.MetricType = queryInfo.GetMetricType() diff --git a/internal/querynodev2/delegator/delegator_data.go b/internal/querynodev2/delegator/delegator_data.go index 43ccde5b9a..89cf5a1b4f 100644 --- a/internal/querynodev2/delegator/delegator_data.go +++ b/internal/querynodev2/delegator/delegator_data.go @@ -1030,7 +1030,7 @@ func (sd *shardDelegator) buildBM25IDF(req *internalpb.SearchRequest) (float64, } for _, idf := range idfSparseVector { - metrics.QueryNodeSearchFTSNumTokens.WithLabelValues(fmt.Sprint(paramtable.GetNodeID()), fmt.Sprint(sd.collectionID)).Observe(float64(typeutil.SparseFloatRowElementCount(idf))) + metrics.QueryNodeSearchFTSNumTokens.WithLabelValues(fmt.Sprint(paramtable.GetNodeID()), fmt.Sprint(sd.collectionID), fmt.Sprint(req.GetFieldId())).Observe(float64(typeutil.SparseFloatRowElementCount(idf))) } err = SetBM25Params(req, avgdl) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 378affb4e2..669f18b9da 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -94,6 +94,7 @@ const ( indexTaskStatusLabelName = "index_task_status" msgTypeLabelName = "msg_type" collectionIDLabelName = "collection_id" + fieldIDLabelName = "field_id" channelNameLabelName = "channel_name" functionLabelName = "function_name" queryTypeLabelName = "query_type" diff --git a/pkg/metrics/proxy_metrics.go b/pkg/metrics/proxy_metrics.go index 2d88fac37d..c420956d4d 100644 --- a/pkg/metrics/proxy_metrics.go +++ b/pkg/metrics/proxy_metrics.go @@ -426,7 +426,7 @@ var ( Name: "search_sparse_num_non_zeros", Help: "the number of non-zeros in each sparse search task", Buckets: buckets, - }, []string{nodeIDLabelName, collectionName}) + }, []string{nodeIDLabelName, collectionName, queryTypeLabelName, fieldIDLabelName}) ProxyParseExpressionLatency = prometheus.NewHistogramVec( prometheus.HistogramOpts{ diff --git a/pkg/metrics/querynode_metrics.go b/pkg/metrics/querynode_metrics.go index b09bd138ce..9f011b5a54 100644 --- a/pkg/metrics/querynode_metrics.go +++ b/pkg/metrics/querynode_metrics.go @@ -360,6 +360,7 @@ var ( }, []string{ nodeIDLabelName, collectionIDLabelName, + fieldIDLabelName, }) QueryNodeSearchGroupSize = prometheus.NewHistogramVec( diff --git a/pkg/util/typeutil/schema.go b/pkg/util/typeutil/schema.go index bb9d6b6e59..321a6b8d41 100644 --- a/pkg/util/typeutil/schema.go +++ b/pkg/util/typeutil/schema.go @@ -1183,6 +1183,11 @@ func GetPrimaryFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSc return nil, errors.New("primary field is not found") } +func IsFieldSparseFloatVector(schema *schemapb.CollectionSchema, fieldID int64) bool { + fieldSchema := GetField(schema, fieldID) + return fieldSchema != nil && IsSparseFloatVectorType(fieldSchema.DataType) +} + // GetPartitionKeyFieldSchema get partition field schema from collection schema func GetPartitionKeyFieldSchema(schema *schemapb.CollectionSchema) (*schemapb.FieldSchema, error) { for _, fieldSchema := range schema.GetFields() {