Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix478
Browse files Browse the repository at this point in the history
  • Loading branch information
JinHai-CN committed Mar 9, 2025
2 parents 79cde6d + 88a5a56 commit 76fe7d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/test_pysdk/test_knn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ def test_sparse_knn_with_index(self, check_data, suffix):
index.IndexType.BMP,
{"block_size": "8", "compress_type": "compress"}), ConflictType.Error)

table_obj.optimize("idx1", {"topk": "3"})
table_obj.optimize("idx1", {"topk": "3", "bp_reorder": ""})

res, extra_result = (table_obj
.output(["*", "_row_id", "_similarity"])
Expand Down
6 changes: 5 additions & 1 deletion src/storage/knn_index/sparse/bmp_alg.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,13 @@ public:
void Optimize(const BMPOptimizeOptions &options) {
std::unique_lock lock(mtx_);

if (options.bp_reorder_) {
while (options.bp_reorder_) {
SizeT block_size = this->block_fwd_.block_size();
SizeT term_num = this->bm_ivt_.term_num();
SizeT doc_num = this->doc_ids_.size() - this->doc_ids_.size() % block_size;
if (doc_num == 0) {
break;
}

this->bm_ivt_ = BMPIvt<DataType, CompressType, BMPOwnMem::kTrue>(term_num);
Vector<Pair<Vector<IdxType>, Vector<DataType>>> fwd = this->block_fwd_.GetFwd(doc_num, term_num);
Expand All @@ -293,6 +296,7 @@ public:
SparseVecRef<DataType, IdxType> doc((i32)indices.size(), indices.data(), data.data());
this->AddDoc(doc, doc_ids[i], false);
}
break;
}
if (options.topk_ != 0) {
SizeT term_num = this->bm_ivt_.term_num();
Expand Down
3 changes: 3 additions & 0 deletions src/storage/knn_index/sparse/bmp_fwd.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ public:
const auto &[term_id, block_size, block_offsets, scores] = iter.Value();
for (SizeT i = 0; i < block_size; ++i) {
BMPDocID doc_id = block_offsets[i] + block_id * block_size_;
if (doc_id >= doc_num) {
break;
}
DataType score = scores[i];
fwd[doc_id].first.push_back(term_id);
fwd[doc_id].second.push_back(score);
Expand Down

0 comments on commit 76fe7d2

Please sign in to comment.