From d39c6e839fb3afa8376c56148d68d8cf45e61017 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Wed, 18 Dec 2024 23:35:14 +0800 Subject: [PATCH] Fix failed tests and rebase on main branch Signed-off-by: Wei Wang --- CHANGELOG.md | 1 + .../java/org/opensearch/knn/index/query/KNNWeight.java | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a5fda2a2..17b1b55c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Introduced a writing layer in native engines where relies on the writing interface to process IO. (#2241)[https://github.com/opensearch-project/k-NN/pull/2241] - Allow method parameter override for training based indices (#2290) https://github.com/opensearch-project/k-NN/pull/2290] - Optimizes lucene query execution to prevent unnecessary rewrites (#2305)[https://github.com/opensearch-project/k-NN/pull/2305] +- Add check to directly use ANN Search when filters match all docs. (#2320)[https://github.com/opensearch-project/k-NN/pull/2320] ### Bug Fixes * Fixing the bug when a segment has no vector field present for disk based vector search (#2282)[https://github.com/opensearch-project/k-NN/pull/2282] * Allow validation for non knn index only after 2.17.0 (#2315)[https://github.com/opensearch-project/k-NN/pull/2315] diff --git a/src/main/java/org/opensearch/knn/index/query/KNNWeight.java b/src/main/java/org/opensearch/knn/index/query/KNNWeight.java index 497593a00..4bcbfd0d9 100644 --- a/src/main/java/org/opensearch/knn/index/query/KNNWeight.java +++ b/src/main/java/org/opensearch/knn/index/query/KNNWeight.java @@ -131,12 +131,6 @@ public PerLeafResult searchLeaf(LeafReaderContext context, int k) throws IOExcep final BitSet filterBitSet = getFilteredDocsBitSet(context); final int maxDoc = context.reader().maxDoc(); int cardinality = filterBitSet.cardinality(); - /* - * 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 (cardinality == maxDoc){ - return doANNSearch(context, filterBitSet, cardinality, k); - } // We don't need to go to JNI layer if no documents are found which satisfy the filters // We should give this condition a deeper look that where it should be placed. For now I feel this is a good // place, @@ -156,7 +150,7 @@ public PerLeafResult searchLeaf(LeafReaderContext context, int k) throws IOExcep * 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 doANNSearch(context, new FixedBitSet(0), 0, k); + return new PerLeafResult(filterBitSet, doANNSearch(context, filterBitSet, cardinality, k)); } Map docIdsToScoreMap = doANNSearch(context, filterBitSet, cardinality, k); // See whether we have to perform exact search based on approx search results