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

Optimize Faiss Query With Filters: Reduce iteration and memory for id filter #1402

Merged
merged 22 commits into from
Mar 4, 2024

Conversation

luyuncheng
Copy link
Collaborator

#1387 it discussed some optimization ideas about filters in ann search.

Problem Statement

we have met in some scenarios which match docids is high cardinality cause process OOM.

i think it is the original docid filters using an array object(jintArray filterIdsJ) to store all matched docids and transfer to jni, and then using an other bitmap/ to create IDSelectorBitmap/IDSelectorBatch do filter search.

these method cause many

  • memory copy(like KNNWeight#createBitSet to create a bitmap and then copy it to array )

  • iteration scan (like KNNWeight#bitSetToIntArray to iteration bitmap to a array; faiss_wrapper#bitSetToIntArray to iteration array to bitmap)

// If we already have a BitSet and no deletions, reuse the BitSet
return ((BitSetIterator) filteredDocIdsIterator).getBitSet();
}
// Create a new BitSet from matching and live docs
FilteredDocIdSetIterator filterIterator = new FilteredDocIdSetIterator(filteredDocIdsIterator) {
@Override
protected boolean match(int doc) {
return liveDocs == null || liveDocs.get(doc);
}
};
return BitSet.of(filterIterator, maxDoc);
}
private int[] getFilterIdsArray(final LeafReaderContext context) throws IOException {
if (filterWeight == null) {
return new int[0];
}
return bitSetToIntArray(getFilteredDocsBitSet(context, this.filterWeight));
}
private int[] getParentIdsArray(final LeafReaderContext context) throws IOException {
if (knnQuery.getParentsFilter() == null) {
return null;
}
return bitSetToIntArray(knnQuery.getParentsFilter().getBitSet(context));
}
private int[] bitSetToIntArray(final BitSet bitSet) {
final int cardinality = bitSet.cardinality();
final int[] intArray = new int[cardinality];
final BitSetIterator bitSetIterator = new BitSetIterator(bitSet, cardinality);
int index = 0;
int docId = bitSetIterator.nextDoc();
while (docId != DocIdSetIterator.NO_MORE_DOCS) {

  • memory oom(like KNNWeight#getFilterIdsArray when bitmap is a high cardinality, it would OOM, because bitset iterator in JAVA, int array in JAVA, bitmap in JNI, array in JNI)

Proposal

in this pr i propose an idea to reduce these situations occurs.

  • i use SparseFixedBitSet/FixedBitSet to do doExactSearch reduce one iteration/copy from bitset docid to array docid
  • i use FixedBitSet long[] array pass direct to JNI, reduce memory copy and iteration translation. it can reduce iteration/copy from jni#filterIdsJ ->IDSelectorBitmap / IDSelectorBatch
  • i move verify IDSelectorBitmap/IDSelectorBatch logic into JAVA.

…t iterator.

Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>
jni/src/faiss_wrapper.cpp Outdated Show resolved Hide resolved
jni/src/faiss_wrapper.cpp Show resolved Hide resolved
@heemin32
Copy link
Collaborator

@luyuncheng Thanks for the contribution. Please rebase and resolve conflict.

@navneet1v Please take a look.

jni/src/faiss_wrapper.cpp Outdated Show resolved Hide resolved
@navneet1v
Copy link
Collaborator

navneet1v commented Jan 29, 2024

@luyuncheng I will look into the PR today. On a high level it seems like you have moved the code for using array or bitmaps based approach from C++ code to Java code to avoid OOM exceptions.

@heemin32 thanks for taking first pass.

@navneet1v
Copy link
Collaborator

we have met in some scenarios which match docids is high cardinality cause process OOM.

Can you add more details what are those cases? At what level of high cardinality we are facing the OOM issue?

Signed-off-by: luyuncheng <[email protected]>
@luyuncheng
Copy link
Collaborator Author

luyuncheng commented Jan 29, 2024

@luyuncheng I will look into the PR today. On a high level it seems like you have moved the code for using array or bitmaps based approach from C++ code to Java code to avoid OOM exceptions.

@navneet1v correct

Can you add more details what are those cases? At what level of high cardinality we are facing the OOM issue?

@navneet1v when in some scenario, we filter with some field like status, age, etc. the result docid array is very large. and shard merge into less segment, the docid number is 1<<30 and one docid is a long size(8 byte), so the memory in one thread are:

  1. fixedbitset: 16MB,
  2. the java transfer array is 8gb,
  3. the jni array is 8gb (need copy from jvm to jni)
  4. and also need to create another bitmap or array IDSelector. 16MB or 8gb

@navneet1v
Copy link
Collaborator

@luyuncheng I will look into the PR today. On a high level it seems like you have moved the code for using array or bitmaps based approach from C++ code to Java code to avoid OOM exceptions.

@navneet1v correct

Can you add more details what are those cases? At what level of high cardinality we are facing the OOM issue?

@navneet1v when in some scenario, we filter with some field like status, age, etc. the result docid array is very large. and shard merge into less segment, the docid number is 1<<30 and one docid is a long size(8 byte), so the memory in one thread are:

  1. fixedbitset: 16MB,
  2. the java transfer array is 8gb,
  3. the jni array is 8gb (need copy from jvm to jni)
  4. and also need to create another bitmap or array IDSelector. 16MB or 8gb

FYI lucene doc ids are ints and not longs. ref: https://lucene.apache.org/core/8_0_0/core/org/apache/lucene/search/DocIdSetIterator.html

Given than lucene per segment the max doc value can be INT_MAX - 1, the worst case a segment can have (2,147,483,647 - 1) documents which results to 8gb of array size. So are you saying that you are hitting cases when the segments have documents close to 2 Billion documents?

jni/src/faiss_wrapper.cpp Outdated Show resolved Hide resolved
jni/src/faiss_wrapper.cpp Outdated Show resolved Hide resolved
@luyuncheng
Copy link
Collaborator Author

luyuncheng commented Jan 29, 2024

Given than lucene per segment the max doc value can be INT_MAX - 1, the worst case a segment can have (2,147,483,647 - 1) documents which results to 8gb of array size. So are you saying that you are hitting cases when the segments have documents close to 2 Billion documents?

@navneet1v We hit some scenarios with 4gb segments (which is 1 << 30), but with concurrent search also with many indices this memory usage would be 4gb * thread number. AND 4gb is also in jvm and in jni memory

@navneet1v
Copy link
Collaborator

@luyuncheng can we get this last comment resolved. I am quite excited to see the impact of this change on the performance of filters in large cases.

@luyuncheng
Copy link
Collaborator Author

luyuncheng commented Feb 27, 2024

@luyuncheng can we get this last comment resolved.

DONE.

I am quite excited to see the impact of this change on the performance of filters in large cases.

@navneet1v Do you have any nightly benchmarks and datasets for the large filter case?

@navneet1v
Copy link
Collaborator

@luyuncheng can we get this last comment resolved.
DONE.

I am quite excited to see the impact of this change on the performance of filters in large cases.

@navneet1v Do you have any nightly benchmarks and datasets for the large filter case?

I have a dataset for testing with filters but it has only 1M documents in it. We can use that dataset with 1 shard and 1 segment to see what is impact before and after your change. That should provide us good insight on how much we are saving here.

@luyuncheng
Copy link
Collaborator Author

I have a dataset for testing with filters but it has only 1M documents in it. We can use that dataset with 1 shard and 1 segment to see what is impact before and after your change. That should provide us good insight on how much we are saving here.

LGTM, Thanks for the review !

@luyuncheng
Copy link
Collaborator Author

@navneet1v Let's try to close this PR quickly by providing prompt review to avoid another rebase.

@heemin32 @navneet1v can we make this PR finish? i think all comments are resolved

@navneet1v
Copy link
Collaborator

@navneet1v Let's try to close this PR quickly by providing prompt review to avoid another rebase.

@heemin32 @navneet1v can we make this PR finish? i think all comments are resolved

@luyuncheng this comment is marked as resolved but no changes are added, neither the resolution. Please fix this so that we can forward in PR

https://github.com/opensearch-project/k-NN/pull/1402/files#r1502838834

@luyuncheng
Copy link
Collaborator Author

@navneet1v Let's try to close this PR quickly by providing prompt review to avoid another rebase.

@heemin32 @navneet1v can we make this PR finish? i think all comments are resolved

@luyuncheng this comment is marked as resolved but no changes are added, neither the resolution. Please fix this so that we can forward in PR

https://github.com/opensearch-project/k-NN/pull/1402/files#r1502838834

will this really be cardinality * Long.BYTES * Long.BYTES

shouldn't this be cardinality * Integer.BYTES * Byte.SIZE

As Integer.BYTES : Provide the number of bytes in a int. And as lucene doc Ids are always int we should use Int here. Byte.SIZE : Represent the number of bits in a byte.

@navneet1v we use jlong array pass to jni#faiss_wrapper represent docid when selectorType is BATCH mode.

AND faiss#IDSelectorBatch using std::unordered_set<idx_t> set; filtered the docids which faiss::idx_t is int64_t in faiss#MetricType

So
Batch Memory = faiss::idx_t array in faiss = Cardinality * Long.BYTES

BitMap Memory = MaxId / 64 * Long.BYTES means using how many longs represent the words like FixedBitSet#bits2words and then multiple Long.Bytes for memory estimate

So the condition trans to Batch Memory < BitMap Memory ==> Cardinality * Long.BYTES / Long.BYTES * 64 < MaxId ==> Cardinality * Long.BYTES * Long.BYTES < MaxId (which Long.BYTES is 8 we can simplify 64)

@navneet1v i think there is no need to change because the explain are shows as comments deduction

@navneet1v
Copy link
Collaborator

navneet1v commented Mar 4, 2024

@navneet1v Let's try to close this PR quickly by providing prompt review to avoid another rebase.

@heemin32 @navneet1v can we make this PR finish? i think all comments are resolved

@luyuncheng this comment is marked as resolved but no changes are added, neither the resolution. Please fix this so that we can forward in PR
https://github.com/opensearch-project/k-NN/pull/1402/files#r1502838834

will this really be cardinality * Long.BYTES * Long.BYTES
shouldn't this be cardinality * Integer.BYTES * Byte.SIZE
As Integer.BYTES : Provide the number of bytes in a int. And as lucene doc Ids are always int we should use Int here. Byte.SIZE : Represent the number of bits in a byte.

@navneet1v we use jlong array pass to jni#faiss_wrapper represent docid when selectorType is BATCH mode.
AND faiss#IDSelectorBatch using std::unordered_set<idx_t> set; filtered the docids which faiss::idx_t is int64_t in faiss#MetricType
So
Batch Memory = faiss::idx_t array in faiss = Cardinality * Long.BYTES
BitMap Memory = MaxId / 64 * Long.BYTES means using how many longs represent the words like FixedBitSet#bits2words and then multiple Long.Bytes for memory estimate
So the condition trans to Batch Memory < BitMap Memory ==> Cardinality * Long.BYTES / Long.BYTES * 64 < MaxId ==> Cardinality * Long.BYTES * Long.BYTES < MaxId (which Long.BYTES is 8 we can simplify 64)

@navneet1v i think there is no need to change because the explain are shows as comments deduction

@luyuncheng I think I got what you are saying. But we are using Long.Bytes to represent how many bits there in 1 byte. Can we atleast move towards this:

(cardinality * Long.BYTES * Byte.SIZE) <= filterIdsBitSet.length()
cardinality => number of docIds
Long.BYTES => number of bytes in long as Faiss uses Long to represent docIds.
Byte.SIZE => number of bits in a byte.

filterIdsBitSet.length() => number of bits in the filterIdsBitset.

This will ensure that logic is easy to understand for future readers.

@navneet1v navneet1v requested review from navneet1v and heemin32 March 4, 2024 16:48
@luyuncheng
Copy link
Collaborator Author

luyuncheng commented Mar 4, 2024

(cardinality * Long.BYTES * Byte.SIZE) <= filterIdsBitSet.length()
cardinality => number of docIds
Long.BYTES => number of bytes in long as Faiss uses Long to represent docIds.
Byte.SIZE => number of bits in a byte.

filterIdsBitSet.length() => number of bits in the filterIdsBitset.

This will ensure that logic is easy to understand for future readers.

@navneet1v LGTM, Update at f747ec7

@navneet1v
Copy link
Collaborator

@luyuncheng @heemin32 is on leave I have requested 1 more maintainer for approval.

@vamshin
Copy link
Member

vamshin commented Mar 4, 2024

LGTM! Thanks

@navneet1v navneet1v added backport 2.x Enhancements Increases software capabilities beyond original client specifications labels Mar 4, 2024
@navneet1v navneet1v merged commit 3eeb855 into opensearch-project:main Mar 4, 2024
50 of 55 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Mar 4, 2024
… filter (#1402)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
(cherry picked from commit 3eeb855)
navneet1v pushed a commit that referenced this pull request Mar 4, 2024
… filter (#1402) (#1504)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
(cherry picked from commit 3eeb855)

Co-authored-by: luyuncheng <[email protected]>
junqiu-lei added a commit that referenced this pull request Mar 6, 2024
* Optimize Faiss Query With Filters: Reduce iteration and memory for id filter (#1402)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>

* Increment 2.12.0-SNAPSHOT to 2.13.0-SNAPSHOT in BWC workflow (#1505)

Signed-off-by: Varun Jain <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
Signed-off-by: Varun Jain <[email protected]>
Co-authored-by: luyuncheng <[email protected]>
Co-authored-by: Varun Jain <[email protected]>
junqiu-lei added a commit that referenced this pull request Mar 12, 2024
* Optimize Faiss Query With Filters: Reduce iteration and memory for id filter (#1402)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>

* Increment 2.12.0-SNAPSHOT to 2.13.0-SNAPSHOT in BWC workflow (#1505)

Signed-off-by: Varun Jain <[email protected]>

* Manually install zlib for win CI (#1513)

Signed-off-by: John Mazanec <[email protected]>

* Upgrade faiss to 12b92e9 (#1509)

Upgrades faiss to facebookresearch/faiss@12b92e9. Cleanup outdated patches.

Signed-off-by: John Mazanec <[email protected]>

* Disable sdc table for HNSWPQ read-only indices (#1518)

Passes flag to disable sdc table for the HNSWPQ indices. This table is
only used by HNSWPQ during graph creation to compare nodes already
present in graph. When we call load index, the graph is read only.
Hence, we wont be doing any ingestion and so the table can be disabled
to save some memory.

Along with this, added a unit test and a couple test helper methods for
generating random data.

Signed-off-by: John Mazanec <[email protected]>

* Support distance type radius search for Lucene engine

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve comments

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve comments

Signed-off-by: Junqiu Lei <[email protected]>

* Add RNNQueryFactory class

Signed-off-by: Junqiu Lei <[email protected]>

* Add javadoc

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
Signed-off-by: Varun Jain <[email protected]>
Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Co-authored-by: luyuncheng <[email protected]>
Co-authored-by: Varun Jain <[email protected]>
Co-authored-by: John Mazanec <[email protected]>
junqiu-lei added a commit to junqiu-lei/k-NN that referenced this pull request Mar 15, 2024
…ject#1498)

* Optimize Faiss Query With Filters: Reduce iteration and memory for id filter (opensearch-project#1402)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>

* Increment 2.12.0-SNAPSHOT to 2.13.0-SNAPSHOT in BWC workflow (opensearch-project#1505)

Signed-off-by: Varun Jain <[email protected]>

* Manually install zlib for win CI (opensearch-project#1513)

Signed-off-by: John Mazanec <[email protected]>

* Upgrade faiss to 12b92e9 (opensearch-project#1509)

Upgrades faiss to facebookresearch/faiss@12b92e9. Cleanup outdated patches.

Signed-off-by: John Mazanec <[email protected]>

* Disable sdc table for HNSWPQ read-only indices (opensearch-project#1518)

Passes flag to disable sdc table for the HNSWPQ indices. This table is
only used by HNSWPQ during graph creation to compare nodes already
present in graph. When we call load index, the graph is read only.
Hence, we wont be doing any ingestion and so the table can be disabled
to save some memory.

Along with this, added a unit test and a couple test helper methods for
generating random data.

Signed-off-by: John Mazanec <[email protected]>

* Support distance type radius search for Lucene engine

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve comments

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve comments

Signed-off-by: Junqiu Lei <[email protected]>

* Add RNNQueryFactory class

Signed-off-by: Junqiu Lei <[email protected]>

* Add javadoc

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
Signed-off-by: Varun Jain <[email protected]>
Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Co-authored-by: luyuncheng <[email protected]>
Co-authored-by: Varun Jain <[email protected]>
Co-authored-by: John Mazanec <[email protected]>
junqiu-lei added a commit to junqiu-lei/k-NN that referenced this pull request Mar 19, 2024
* Optimize Faiss Query With Filters: Reduce iteration and memory for id filter (opensearch-project#1402)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>

* Increment 2.12.0-SNAPSHOT to 2.13.0-SNAPSHOT in BWC workflow (opensearch-project#1505)

Signed-off-by: Varun Jain <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
Signed-off-by: Varun Jain <[email protected]>
Co-authored-by: luyuncheng <[email protected]>
Co-authored-by: Varun Jain <[email protected]>
junqiu-lei added a commit to junqiu-lei/k-NN that referenced this pull request Mar 19, 2024
…ject#1498)

* Optimize Faiss Query With Filters: Reduce iteration and memory for id filter (opensearch-project#1402)

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator

Signed-off-by: luyuncheng <[email protected]>

* Optimize Faiss Query With Filters. Reduce iteration copy for docid set iterator.
Use Bitmap And Batch to do id filter. and you sparse or fixed bitset do exact ANN search

Signed-off-by: luyuncheng <[email protected]>

* Using int64_t instead of long type for GetLongArrayElements

Signed-off-by: luyuncheng <[email protected]>

* Add IDSelectorJlongBitmap

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class

Signed-off-by: luyuncheng <[email protected]>

* 1. Add IDSelectorJlongBitmap and UT for it
2. Move FilterIdsSelectorType to a util class
3. Spotless apply

Signed-off-by: luyuncheng <[email protected]>

* Rebase remote-tracking branch 'origin/main' into Filter

Signed-off-by: luyuncheng <[email protected]>

* tidy

Signed-off-by: luyuncheng <[email protected]>

* Add Changelog

Signed-off-by: luyuncheng <[email protected]>

* fix javadoc tasks

Signed-off-by: luyuncheng <[email protected]>

* fix bwc javadoc

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector

Signed-off-by: luyuncheng <[email protected]>

* Rebase faiss_wrapper.cpp

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For description Select different FilterIdsSelectorType

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector as Byte.SIZE

Signed-off-by: luyuncheng <[email protected]>

* UpdatedFilterIdsSelector For comments

Signed-off-by: luyuncheng <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>

* Increment 2.12.0-SNAPSHOT to 2.13.0-SNAPSHOT in BWC workflow (opensearch-project#1505)

Signed-off-by: Varun Jain <[email protected]>

* Manually install zlib for win CI (opensearch-project#1513)

Signed-off-by: John Mazanec <[email protected]>

* Upgrade faiss to 12b92e9 (opensearch-project#1509)

Upgrades faiss to facebookresearch/faiss@12b92e9. Cleanup outdated patches.

Signed-off-by: John Mazanec <[email protected]>

* Disable sdc table for HNSWPQ read-only indices (opensearch-project#1518)

Passes flag to disable sdc table for the HNSWPQ indices. This table is
only used by HNSWPQ during graph creation to compare nodes already
present in graph. When we call load index, the graph is read only.
Hence, we wont be doing any ingestion and so the table can be disabled
to save some memory.

Along with this, added a unit test and a couple test helper methods for
generating random data.

Signed-off-by: John Mazanec <[email protected]>

* Support distance type radius search for Lucene engine

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve comments

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve comments

Signed-off-by: Junqiu Lei <[email protected]>

* Add RNNQueryFactory class

Signed-off-by: Junqiu Lei <[email protected]>

* Add javadoc

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

* Resolve feedback

Signed-off-by: Junqiu Lei <[email protected]>

---------

Signed-off-by: luyuncheng <[email protected]>
Signed-off-by: Varun Jain <[email protected]>
Signed-off-by: John Mazanec <[email protected]>
Signed-off-by: Junqiu Lei <[email protected]>
Co-authored-by: luyuncheng <[email protected]>
Co-authored-by: Varun Jain <[email protected]>
Co-authored-by: John Mazanec <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Enhancements Increases software capabilities beyond original client specifications
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants