-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance: simplify the structure of search_params #38251
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,39 @@ | |
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb" | ||
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" | ||
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb" | ||
"github.com/milvus-io/milvus/internal/json" | ||
"github.com/milvus-io/milvus/internal/proto/planpb" | ||
"github.com/milvus-io/milvus/pkg/common" | ||
"github.com/milvus-io/milvus/pkg/util/funcutil" | ||
"github.com/milvus-io/milvus/pkg/util/merr" | ||
"github.com/milvus-io/milvus/pkg/util/typeutil" | ||
) | ||
|
||
const ( | ||
// float64 | ||
nlistKey = "nlist" | ||
nprobeKey = "nprobe" | ||
maxEmptyResultBuckets = "max_empty_result_buckets" | ||
reorderKKey = "reorder_k" | ||
searchListKey = "search_list" | ||
itopkSizeKey = "itopk_size" | ||
searchWidthKey = "search_width" | ||
minIterationsKey = "min_iterations" | ||
maxIterationsKey = "max_iterations" | ||
teamSizeKey = "team_size" | ||
radiusKey = "radius" | ||
rangeFilterKey = "range_filter" | ||
levelKey = "level" | ||
// bool | ||
pageRetainOrderKey = "page_retain_order" | ||
) | ||
|
||
var ParamsKeyList = []string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary? |
||
nlistKey, nprobeKey, maxEmptyResultBuckets, reorderKKey, searchListKey, | ||
itopkSizeKey, searchWidthKey, minIterationsKey, maxIterationsKey, | ||
teamSizeKey, radiusKey, rangeFilterKey, levelKey, pageRetainOrderKey, | ||
} | ||
|
||
type rankParams struct { | ||
limit int64 | ||
offset int64 | ||
|
@@ -163,9 +189,37 @@ | |
} | ||
|
||
// 4. parse search param str | ||
searchParamStr, err := funcutil.GetAttrByKeyFromRepeatedKV(SearchParamsKey, searchParamsPair) | ||
searchParamStr, err := funcutil.GetAttrByKeyFromRepeatedKV(ParamsKey, searchParamsPair) | ||
var searchParamMap map[string]any | ||
if err != nil { | ||
searchParamStr = "" | ||
} else { | ||
err = json.Unmarshal([]byte(searchParamStr), &searchParamMap) | ||
if err != nil { | ||
return &SearchInfo{planInfo: nil, offset: 0, isIterator: false, parseError: err} | ||
} | ||
} | ||
|
||
// related with https://github.com/milvus-io/milvus/issues/37972 | ||
// before 2.5.1, all key in ParamsKeyList will be write in search_params.params | ||
// after 2.5.1, allow user to write all this key in search_params | ||
// SearchParams in planpb.QueryInfo is the params set passed to segcore | ||
// so if you want to use the params in segcore/knowhere, remember to add the new params into ParamsKeyList after 2.5.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need add the index parameter here? This doesn't seem reasonable. It will introduce new compatibility logic. Can we just write all of params without adding a whitelist? |
||
for _, key := range ParamsKeyList { | ||
stringValue, err := funcutil.GetAttrByKeyFromRepeatedKV(key, searchParamsPair) | ||
if err == nil { | ||
err := checkParams(searchParamMap, key, stringValue) | ||
if err != nil { | ||
return &SearchInfo{planInfo: nil, offset: 0, isIterator: false, parseError: err} | ||
} | ||
} | ||
} | ||
if len(searchParamMap) > 0 { | ||
jsonStrBytes, err := json.Marshal(searchParamMap) | ||
if err != nil { | ||
return &SearchInfo{planInfo: nil, offset: 0, isIterator: false, parseError: err} | ||
} | ||
searchParamStr = string(jsonStrBytes) | ||
} | ||
|
||
// 5. parse group by field and group by size | ||
|
@@ -494,3 +548,40 @@ | |
} | ||
return ret | ||
} | ||
|
||
func checkParams(m map[string]any, key string, stringValue string) error { | ||
switch key { | ||
case pageRetainOrderKey: | ||
value, err := strconv.ParseBool(stringValue) | ||
if err != nil { | ||
return err | ||
} | ||
if v, ok := m[key]; ok { | ||
v, ok := v.(bool) | ||
if !ok { | ||
return merr.WrapErrParameterInvalidMsg(fmt.Sprintf("parameter(%s) has the wrong type, expect bool type", key)) | ||
} | ||
if v != value { | ||
return merr.WrapErrParameterInvalidMsg(fmt.Sprintf("inconsistent parameter(%s), search_param(%t),search_param.params(%t)", key, v, value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ambiguous |
||
} | ||
} | ||
m[key] = value | ||
default: | ||
// all number will be convert to float64 in json | ||
value, err := strconv.ParseFloat(stringValue, 64) | ||
if err != nil { | ||
return err | ||
} | ||
if v, ok := m[key]; ok { | ||
v, ok := v.(float64) | ||
if !ok { | ||
return merr.WrapErrParameterInvalidMsg(fmt.Sprintf("parameter(%s) has the wrong type, expect bool type", key)) | ||
} | ||
if v != value { | ||
return merr.WrapErrParameterInvalidMsg(fmt.Sprintf("inconsistent parameter(%s), search_param(%f),search_param.params(%f)", key, v, value)) | ||
} | ||
} | ||
m[key] = value | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Knowhere’s param need to be transparent to MIlvus @foxspy Plz take a look