Skip to content

Commit

Permalink
fix: metric type error when the collection has two vec field (#36473)
Browse files Browse the repository at this point in the history
- issue: #36395

Signed-off-by: SimFG <[email protected]>
  • Loading branch information
SimFG authored Sep 24, 2024
1 parent fa6354f commit a00523f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions internal/querynodev2/segments/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@ func NewCollection(collectionID int64, schema *schemapb.CollectionSchema, indexM
}

func GetMetricType(schema *schemapb.CollectionSchema, indexMeta *segcorepb.CollectionIndexMeta) string {
vecField, err := typeutil.GetVectorFieldSchema(schema)
if err != nil {
log.Warn("get vector field failed", zap.String("collection", schema.GetName()), zap.Error(err))
vecFields := typeutil.GetVectorFieldSchemas(schema)
// if vector field is not found or more than one, return empty string
// because we don't need the metric type for more than one vector fields
if len(vecFields) == 0 || len(vecFields) > 1 {
return ""
}
vecField := vecFields[0]
vecIndexMeta, ok := lo.Find(indexMeta.GetIndexMetas(), func(fieldIndexMeta *segcorepb.FieldIndexMeta) bool {
return fieldIndexMeta.GetFieldID() == vecField.GetFieldID()
})
Expand Down
2 changes: 1 addition & 1 deletion internal/querynodev2/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ func (node *QueryNode) Search(ctx context.Context, req *querypb.SearchRequest) (
resp.Status = merr.Status(merr.WrapErrCollectionNotFound(req.GetReq().GetCollectionID()))
return resp, nil
}
if req.Req.MetricType == "" {
if req.Req.MetricType == "" && !req.GetReq().GetIsAdvanced() {
req.Req.MetricType = collection.GetMetricType()
}

Expand Down

0 comments on commit a00523f

Please sign in to comment.