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

Support MV only for HNSW #1020

Merged
merged 1 commit into from
Jan 14, 2025
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
32 changes: 32 additions & 0 deletions include/knowhere/bitsetview.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,38 @@ class BitsetView {
return ret;
}

size_t
get_first_valid_index() const {
size_t ret = 0;
auto len_uint8 = byte_size();
auto len_uint64 = len_uint8 >> 3;

uint64_t* p_uint64 = (uint64_t*)bits_;
for (size_t i = 0; i < len_uint64; i++) {
uint64_t value = (~(*p_uint64));
if (value == 0) {
p_uint64++;
continue;
}
ret = __builtin_ctzll(value);
return i * 64 + ret;
}

// calculate remainder
uint8_t* p_uint8 = (uint8_t*)bits_ + (len_uint64 << 3);
for (size_t i = 0; i < len_uint8 - (len_uint64 << 3); i++) {
uint8_t value = (~(*p_uint8));
if (value == 0) {
p_uint8++;
continue;
}
ret = __builtin_ctz(value);
return len_uint64 * 64 + i * 8 + ret;
}

return num_bits_;
}

std::string
to_string(size_t from, size_t to) const {
if (empty()) {
Expand Down
17 changes: 17 additions & 0 deletions include/knowhere/bitsetview_idselector.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,21 @@ struct BitsetViewIDSelector final : faiss::IDSelector {
}
};

struct BitsetViewWithMappingIDSelector final : faiss::IDSelector {
const BitsetView bitset_view;
const uint32_t* out_id_mapping;
const size_t id_offset;

inline BitsetViewWithMappingIDSelector(BitsetView bitset_view, const uint32_t* out_id_mapping,
const size_t offset = 0)
: bitset_view{bitset_view}, out_id_mapping(out_id_mapping), id_offset(offset) {
}

inline bool
is_member(faiss::idx_t id) const override final {
// it is by design that out_id_mapping == nullptr is not tested here
return (!bitset_view.test(out_id_mapping[id + id_offset]));
}
};

} // namespace knowhere
1 change: 1 addition & 0 deletions include/knowhere/comp/index_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ constexpr const char* JSON_ID_SET = "json_id_set";
constexpr const char* TRACE_ID = "trace_id";
constexpr const char* SPAN_ID = "span_id";
constexpr const char* TRACE_FLAGS = "trace_flags";
constexpr const char* SCALAR_INFO = "scalar_info";
constexpr const char* MATERIALIZED_VIEW_SEARCH_INFO = "materialized_view_search_info";
constexpr const char* MATERIALIZED_VIEW_OPT_FIELDS_PATH = "opt_fields_path";
constexpr const char* MAX_EMPTY_RESULT_BUCKETS = "max_empty_result_buckets";
Expand Down
Loading