Skip to content

fix: disallow brute force on index unless explicitly requested#6105

Open
westonpace wants to merge 1 commit intolance-format:mainfrom
westonpace:fix/no-silent-brute-force
Open

fix: disallow brute force on index unless explicitly requested#6105
westonpace wants to merge 1 commit intolance-format:mainfrom
westonpace:fix/no-silent-brute-force

Conversation

@westonpace
Copy link
Member

Currently an attempt to search an index with a distance type that does not match the trained distance type will result in a brute force search (with a warning logged). However, this should be an error. An implicit brute force search can be a very costly thing. We already have a way to request a brute force search (use_index=False) and that should be used if this is truly the behavior that is desired.

@github-actions github-actions bot added the bug Something isn't working label Mar 5, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Review of PR #6105

The behavioral change (error instead of silent brute force) is well-motivated and the test coverage is good. Two minor issues:

P1: Dead code after early return

After the change, the else branch at the metric mismatch now does return Err(...), which means use_this_index is always true when execution continues. This makes the if use_this_index { Some(...) } else { None } block (and the variable itself) dead code — the else { None } path is unreachable. Consider simplifying: remove the use_this_index variable entirely and just set matching_index directly, since the only two outcomes are now "metrics match → use index" or "metrics don't match → return error".

P1: Test name is stale

test_knn_metric_mismatch_falls_back_to_flat_search no longer describes the test behavior — it now tests that a metric mismatch returns an error. Consider renaming to something like test_knn_metric_mismatch_returns_error.

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance/src/dataset/scanner.rs 90.90% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@wkalt
Copy link
Contributor

wkalt commented Mar 5, 2026

this seems like a significant behavior change, since any clients previously doing the "wrong" thing but still getting results will now get errors

Copy link
Contributor

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is reasonable, but it should definitely be labelled as a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants