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

sparse: add block-max wand and block-max maxscore algorithm #1026

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions include/knowhere/comp/index_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ constexpr const char* PRQ_NUM = "nrq"; // for PRQ, number of redisual quant
constexpr const char* INVERTED_INDEX_ALGO = "inverted_index_algo";
constexpr const char* DROP_RATIO_BUILD = "drop_ratio_build";
constexpr const char* DROP_RATIO_SEARCH = "drop_ratio_search";
constexpr const char* BLOCKMAX_BLOCK_SIZE = "blockmax_block_size";
} // namespace indexparam

using MetricType = std::string;
Expand Down
10 changes: 10 additions & 0 deletions include/knowhere/sparse_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ class GrowableVectorView {
return reinterpret_cast<const T*>(mmap_data_)[i];
}

T&
back() {
return reinterpret_cast<T*>(mmap_data_)[size() - 1];
}

const T&
back() const {
return reinterpret_cast<const T*>(mmap_data_)[size() - 1];
}

class iterator : public boost::iterator_facade<iterator, T, boost::random_access_traversal_tag, T&> {
public:
iterator() = default;
Expand Down
22 changes: 22 additions & 0 deletions src/index/sparse/sparse_index_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ class SparseInvertedIndexNode : public IndexNode {
new sparse::InvertedIndex<T, uint16_t, sparse::InvertedIndexAlgo::DAAT_WAND, true, mmapped>();
index->SetBM25Params(k1, b, avgdl, max_score_ratio);
return index;
} else if (cfg.inverted_index_algo.value() == "DAAT_BLOCKMAX_WAND") {
auto index = new sparse::InvertedIndex<T, uint16_t, sparse::InvertedIndexAlgo::DAAT_BLOCKMAX_WAND, true,
mmapped>();
index->SetBM25Params(k1, b, avgdl, max_score_ratio);
index->SetBlockmaxBlockSize(cfg.blockmax_block_size.value());
return index;
} else if (cfg.inverted_index_algo.value() == "DAAT_BLOCKMAX_MAXSCORE") {
auto index = new sparse::InvertedIndex<T, uint16_t, sparse::InvertedIndexAlgo::DAAT_BLOCKMAX_MAXSCORE,
true, mmapped>();
index->SetBM25Params(k1, b, avgdl, max_score_ratio);
index->SetBlockmaxBlockSize(cfg.blockmax_block_size.value());
return index;
} else if (cfg.inverted_index_algo.value() == "DAAT_MAXSCORE") {
auto index =
new sparse::InvertedIndex<T, uint16_t, sparse::InvertedIndexAlgo::DAAT_MAXSCORE, true, mmapped>();
Expand All @@ -386,6 +398,16 @@ class SparseInvertedIndexNode : public IndexNode {
auto index =
new sparse::InvertedIndex<T, T, sparse::InvertedIndexAlgo::DAAT_MAXSCORE, false, mmapped>();
return index;
} else if (cfg.inverted_index_algo.value() == "DAAT_BLOCKMAX_WAND") {
auto index =
new sparse::InvertedIndex<T, T, sparse::InvertedIndexAlgo::DAAT_BLOCKMAX_WAND, false, mmapped>();
index->SetBlockmaxBlockSize(cfg.blockmax_block_size.value());
return index;
} else if (cfg.inverted_index_algo.value() == "DAAT_BLOCKMAX_MAXSCORE") {
auto index = new sparse::InvertedIndex<T, T, sparse::InvertedIndexAlgo::DAAT_BLOCKMAX_MAXSCORE, false,
mmapped>();
index->SetBlockmaxBlockSize(cfg.blockmax_block_size.value());
return index;
} else if (cfg.inverted_index_algo.value() == "TAAT_NAIVE") {
auto index = new sparse::InvertedIndex<T, T, sparse::InvertedIndexAlgo::TAAT_NAIVE, false, mmapped>();
return index;
Expand Down
Loading
Loading