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

Add check to directly use ANN Search when filters match all docs. #2320

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

weiwang118
Copy link

Description

This change aims to resolve this github issue: #1387
by adding a simple check in searchLeaf method so that if the filters match all doc IDs in the segment (Max Doc == size of FilterBitSet), then we directly do ANN search and avoid other unnecessary steps. This will help improve the search performance.

Related Issues

Resolves #1387

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

* If filters match all docs in this segment, then there is no need to do any extra step
* and should directly do ANN Search*/
if (filterWeight != null && cardinality == maxDoc) {
return new PerLeafResult(new FixedBitSet(0), doANNSearch(context, new FixedBitSet(0), 0, k));
Copy link
Contributor

Choose a reason for hiding this comment

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

I see lots of new FixedBitSet(0) in KNNWeight.
Could you factor it out with a meaningful name as a static variable then pass it down to the downstream?

private static final FixedBitSet ... = new FixedBitSet(0);

@@ -145,6 +146,12 @@ public PerLeafResult searchLeaf(LeafReaderContext context, int k) throws IOExcep
Map<Integer, Float> result = doExactSearch(context, new BitSetIterator(filterBitSet, cardinality), cardinality, k);
return new PerLeafResult(filterWeight == null ? null : filterBitSet, result);
}
/*
* If filters match all docs in this segment, then there is no need to do any extra step
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you give more context to the comment?? Would like to see why there's no need for extra steps for all doc matches case, and what passing new FixedBitSet(0) means. Basically, we want to save a bitset look up cost when it's not required as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants