-
Notifications
You must be signed in to change notification settings - Fork 107
add checks for a dimensionality of a query for BF, HNSW and IVF #1291
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1212,6 +1212,15 @@ class BaseFaissRegularIndexHNSWNode : public BaseFaissRegularIndexNode { | |
const auto hnsw_cfg = static_cast<const FaissHnswConfig&>(*cfg); | ||
const auto k = hnsw_cfg.k.value(); | ||
|
||
const std::string metric_str = hnsw_cfg.metric_type.value(); | ||
if ((dim != Dim()) && (IsMetricType(metric_str, metric::COSINE) || IsMetricType(metric_str, metric::IP) || | ||
IsMetricType(metric_str, metric::L2))) { | ||
const std::string msg_e = | ||
fmt::format("dimensionalities of the base dataset ({}) and the query ({}) do not match", Dim(), dim); | ||
LOG_KNOWHERE_ERROR_ << msg_e; | ||
return expected<DataSetPtr>::Err(Status::invalid_args, msg_e); | ||
} | ||
|
||
BitsetView bitset(bitset_); | ||
if (!internal_offset_to_most_external_id.empty()) { | ||
bitset.set_out_ids(internal_offset_to_most_external_id.data(), internal_offset_to_most_external_id.size()); | ||
|
@@ -1473,6 +1482,16 @@ class BaseFaissRegularIndexHNSWNode : public BaseFaissRegularIndexNode { | |
const auto* data = dataset->GetTensor(); | ||
|
||
const auto hnsw_cfg = static_cast<const FaissHnswConfig&>(*cfg); | ||
|
||
const std::string metric_str = hnsw_cfg.metric_type.value(); | ||
if ((dim != Dim()) && (IsMetricType(metric_str, metric::COSINE) || IsMetricType(metric_str, metric::IP) || | ||
IsMetricType(metric_str, metric::L2))) { | ||
const std::string msg_e = | ||
fmt::format("dimensionalities of the base dataset ({}) and the query ({}) do not match", Dim(), dim); | ||
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. put these repeated codes into a util function 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. If I remember correctly, this should have already been intercepted in Milvus. What issue are you encountering here? 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. there was a problem in KIOXIA unit test that triggered a problem |
||
LOG_KNOWHERE_ERROR_ << msg_e; | ||
return expected<DataSetPtr>::Err(Status::invalid_args, msg_e); | ||
} | ||
|
||
BitsetView bitset(bitset_); | ||
if (!internal_offset_to_most_external_id.empty()) { | ||
bitset.set_out_ids(internal_offset_to_most_external_id.data(), internal_offset_to_most_external_id.size()); | ||
|
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.
IP metrics could also work with sparse vectors.
Can we skip all the query dimension checks by identifying whether the
base_dataset
andquery_dataset
are sparse?