Skip to content

Commit

Permalink
Fix: paramter check in match sparse expression. (#1695)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

1. Check if topk == 0 in sparse expression construction.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
small-turtle-1 authored Aug 21, 2024
1 parent bd49ae6 commit 2a29610
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/planner/expression_binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@ SharedPtr<BaseExpression> ExpressionBinder::BuildMatchSparseExpr(const MatchSpar

SharedPtr<BaseExpression> query_expr = BuildExpression(*expr.query_sparse_expr_, bind_context_ptr, depth, root);

if (expr.topn_ == 0) {
RecoverableError(Status::InvalidParameterValue("topk", std::to_string(expr.topn_), "100"));
}
auto bound_match_sparse_expr = MakeShared<MatchSparseExpression>(std::move(arguments),
query_expr,
expr.metric_type_,
Expand Down
3 changes: 3 additions & 0 deletions src/storage/knn_index/sparse/bmp_alg.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ Pair<Vector<BMPDocID>, Vector<DataType>> BMPAlg<DataType, IdxType, CompressType>
i32 topk,
const BmpSearchOptions &options,
const Filter &filter) const {
if (topk == 0) {
return {{}, {}};
}
std::shared_lock lock(mtx_, std::defer_lock);
if (options.use_lock_) {
lock.lock();
Expand Down
7 changes: 7 additions & 0 deletions src/unit_test/storage/knnindex/knn_sparse/test_bmp_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class BMPIndexTest : public BaseTest {
LocalFileSystem fs;

auto test_query = [&](const BMPAlg &index) {
{
SparseMatrixIter iter(query_set);
SparseVecRef vec = iter.val();
auto [indices, scores] = index.SearchKnn(vec, 0/*topk*/, options);
EXPECT_EQ(indices.size(), 0);
EXPECT_EQ(scores.size(), 0);
}
u32 hit_all = 0;
u32 total_all = 0;
for (SparseMatrixIter iter(query_set); iter.HasNext(); iter.Next()) {
Expand Down

0 comments on commit 2a29610

Please sign in to comment.