Skip to content
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

fix: BitsetViewSelectorHelper miss id_offset #948

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/ut/test_bruteforce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ TEST_CASE("Test Brute Force", "[binary vector]") {
TEST_CASE("Test Brute Force with input ids", "[float vector]") {
using Catch::Approx;
const int64_t nb = 1000;
const int64_t nq = 1;
const int64_t nq = 10;
const int64_t dim = 128;
const int64_t k = 10;
const knowhere::Json conf = {
{knowhere::meta::DIM, dim},
{knowhere::meta::METRIC_TYPE, "L2"},
{knowhere::meta::TOPK, k},
};
std::vector<int64_t> block_prefix = {0, 333, 500, 555, 1000};
std::vector<int64_t> block_prefix = {0, 111, 333, 500, 555, 666, 888, 1000};

// generate filter id and data
auto filter_bits = GenerateBitsetWithRandomTbitsSet(nb, 100);
Expand Down
12 changes: 8 additions & 4 deletions thirdparty/faiss/faiss/utils/distances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ struct IDSelectorHelper {
struct BitsetViewSelectorHelper {
// todo aguzhva: use avx gather instruction
const knowhere::BitsetView bitset;
const size_t id_offset = 0;

inline bool is_member(const size_t idx) const {
return !bitset.test(idx);
return !bitset.test(idx + id_offset);
}
};

Expand Down Expand Up @@ -254,8 +255,9 @@ void exhaustive_inner_product_seq(
if (const auto* bitsetview_sel = dynamic_cast<const knowhere::BitsetViewIDSelector*>(sel)) {
// A specialized case for Knowhere
auto bitset = bitsetview_sel->bitset_view;
auto id_offset = bitsetview_sel->id_offset;
if (!bitset.empty()) {
BitsetViewSelectorHelper bitset_helper{bitset};
BitsetViewSelectorHelper bitset_helper{bitset, id_offset};
exhaustive_inner_product_seq_impl<BlockResultHandler, BitsetViewSelectorHelper>(
x, y, d, nx, ny, res, bitset_helper);
return;
Expand Down Expand Up @@ -368,8 +370,9 @@ void exhaustive_L2sqr_seq(
if (const auto* bitsetview_sel = dynamic_cast<const knowhere::BitsetViewIDSelector*>(sel)) {
// A specialized case for Knowhere
auto bitset = bitsetview_sel->bitset_view;
auto id_offset = bitsetview_sel->id_offset;
if (!bitset.empty()) {
BitsetViewSelectorHelper bitset_helper{bitset};
BitsetViewSelectorHelper bitset_helper{bitset, id_offset};
exhaustive_L2sqr_seq_impl<BlockResultHandler, BitsetViewSelectorHelper>(
x, y, d, nx, ny, res, bitset_helper);
return;
Expand Down Expand Up @@ -494,8 +497,9 @@ void exhaustive_cosine_seq(
if (const auto* bitsetview_sel = dynamic_cast<const knowhere::BitsetViewIDSelector*>(sel)) {
// A specialized case for Knowhere
auto bitset = bitsetview_sel->bitset_view;
auto id_offset = bitsetview_sel->id_offset;
if (!bitset.empty()) {
BitsetViewSelectorHelper bitset_helper{bitset};
BitsetViewSelectorHelper bitset_helper{bitset, id_offset};
exhaustive_cosine_seq_impl<BlockResultHandler, BitsetViewSelectorHelper>(
x, y, y_norms, d, nx, ny, res, bitset_helper);
return;
Expand Down
Loading