fix(search): validate filters and reset stale filter state (#663)

This commit is contained in:
ZeFeng Yin 2026-08-07 16:14:44 +08:00 committed by GitHub
parent f4aa7845f2
commit e1f11e29fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 7 deletions

View File

@ -57,8 +57,10 @@ int FlatIndex::_prepare_for_search(
context->set_topk(flat_search_param->topk);
context->set_fetch_vector(flat_search_param->fetch_vector);
if (flat_search_param->filter) {
if (flat_search_param->filter && flat_search_param->filter->is_valid()) {
context->set_filter(std::move(*flat_search_param->filter));
} else {
context->reset_filter();
}
if (flat_search_param->radius > 0.0f) {
context->set_threshold(flat_search_param->radius);
@ -69,4 +71,4 @@ int FlatIndex::_prepare_for_search(
}
} // namespace zvec::core_interface
} // namespace zvec::core_interface

View File

@ -154,8 +154,10 @@ int HNSWIndex::_prepare_for_search(
context->set_topk(hnsw_search_param->topk);
context->set_fetch_vector(hnsw_search_param->fetch_vector);
if (hnsw_search_param->filter) {
if (hnsw_search_param->filter && hnsw_search_param->filter->is_valid()) {
context->set_filter(std::move(*hnsw_search_param->filter));
} else {
context->reset_filter();
}
if (hnsw_search_param->radius > 0.0f) {
context->set_threshold(hnsw_search_param->radius);

View File

@ -113,8 +113,10 @@ int HNSWRabitqIndex::_prepare_for_search(
context->set_topk(hnsw_search_param->topk);
context->set_fetch_vector(hnsw_search_param->fetch_vector);
if (hnsw_search_param->filter) {
if (hnsw_search_param->filter && hnsw_search_param->filter->is_valid()) {
context->set_filter(std::move(*hnsw_search_param->filter));
} else {
context->reset_filter();
}
if (hnsw_search_param->radius > 0.0f) {
context->set_threshold(hnsw_search_param->radius);

View File

@ -221,8 +221,10 @@ int IVFIndex::_prepare_for_search(
context->set_topk(ivf_search_param->topk);
context->set_fetch_vector(ivf_search_param->fetch_vector);
if (ivf_search_param->filter) {
if (ivf_search_param->filter && ivf_search_param->filter->is_valid()) {
context->set_filter(std::move(*ivf_search_param->filter));
} else {
context->reset_filter();
}
if (ivf_search_param->radius > 0.0f) {
context->set_threshold(ivf_search_param->radius);
@ -270,4 +272,4 @@ int IVFIndex::Merge(const std::vector<Index::Pointer> &indexes,
is_trained_ = true;
return 0;
}
} // namespace zvec::core_interface
} // namespace zvec::core_interface

View File

@ -86,8 +86,10 @@ int VamanaIndex::_prepare_for_search(
context->set_topk(vamana_search_param->topk);
context->set_fetch_vector(vamana_search_param->fetch_vector);
if (vamana_search_param->filter) {
if (vamana_search_param->filter && vamana_search_param->filter->is_valid()) {
context->set_filter(std::move(*vamana_search_param->filter));
} else {
context->reset_filter();
}
if (vamana_search_param->radius > 0.0f) {
context->set_threshold(vamana_search_param->radius);