Skip to content

[LuceneOnFaiss Part-8] Added index.knn.memory_optimized_search index setting. #2616

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

Conversation

0ctopus13prime
Copy link
Collaborator

@0ctopus13prime 0ctopus13prime commented Mar 19, 2025

Description

This PR adds index.knn.memory_optimized_search index settings.
Overall, this brings two major changes listed below along with the new setting definition:

  1. In codec level, it relies on MapperService to retrieve index.knn.memory_optimized_search bool flag. Which then be used to determine whether to initialize partial loading on KNN fields.
    But this is not always working, during recovery MapperService can be null, therefore adding lazy-loading logic in both constructor and search method. For 99%, it will be loaded in the constructor, so it won't affect search p99 latency as by the time the search method is called, MemoryOptimizedSearch should be loaded already.

  2. Branching in KNNQueryBuilder
    This PR will make each knn field type decide whether memory-optimized-search is supported or not.
    Currently only Float HNSW is supported, therefore any binary HNSW graphs will return false to indicate the feature is not supported.
    If target field in search is supported for memory-optimized-search, control will fallback to Lucene query to proceed vector search. In which, Lucene's HNSW graph searcher will perform KNN search + Radius search on FAISS index.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

RFC: #2401

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.

@0ctopus13prime
Copy link
Collaborator Author

Part-7 #2608 was merged.
Will rebase and re-raise a new revision.
In the new revision, it will have unit tests.

@0ctopus13prime 0ctopus13prime force-pushed the lucene-on-faiss-part8 branch 4 times, most recently from fbd6e65 to fcef387 Compare March 20, 2025 02:13
@0ctopus13prime
Copy link
Collaborator Author

Hi @jmazanec15 ,

In this revision, I've included a hybrid approach inspired by @shatejas 's suggestion.

Previously, I added lazy loading in search because accessing the index.knn.memory_optimized_search setting in the constructor seemed tricky. Retrieving this value requires knowing the index name, and more importantly, during recovery, the codec is loaded via Lucene's SPI, where OpenSearch's internal framework isn't available. That was the main reason for switching to lazy loading within search.

However, this scenario is rare. In most cases, OpenSearch's internal framework (e.g., IndexSettings) is available. Additionally, since we're trying to compress long[] on the fly during loading in #2609 , relying solely on lazy loading in search could negatively impact p99, as it might take several seconds for larger datasets.

With this hybrid approach, we attempt to initialize in the constructor. If IndexSettings is available, we fetch the boolean value; otherwise, we do nothing. This way, most searches will find the table already initialized, no need for lazy loading. Only searches on a just-recovered index will require it.

Let me know if you have any major concerns. I think this approach not only mitigates potential p99 issues but also avoids the Lucene SPI limitation.

@0ctopus13prime 0ctopus13prime force-pushed the lucene-on-faiss-part8 branch 2 times, most recently from c0dc961 to 822f918 Compare March 21, 2025 22:48
Copy link
Collaborator

@shatejas shatejas left a comment

Choose a reason for hiding this comment

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

Looks good overall - couple of comments

@0ctopus13prime 0ctopus13prime force-pushed the lucene-on-faiss-part8 branch from 822f918 to 6132ada Compare March 24, 2025 00:25
@0ctopus13prime 0ctopus13prime force-pushed the lucene-on-faiss-part8 branch from 6132ada to 952723d Compare March 24, 2025 17:05
@0ctopus13prime 0ctopus13prime dismissed navneet1v’s stale review March 24, 2025 18:02

Will update in the next PR.
It's being tracked in #2401 (comment)

@0ctopus13prime 0ctopus13prime merged commit 58fcb37 into opensearch-project:lucene-on-faiss Mar 24, 2025
35 checks passed
0ctopus13prime added a commit to 0ctopus13prime/k-NN that referenced this pull request Mar 25, 2025
0ctopus13prime added a commit to 0ctopus13prime/k-NN that referenced this pull request Mar 25, 2025
0ctopus13prime added a commit to 0ctopus13prime/k-NN that referenced this pull request Mar 27, 2025
0ctopus13prime added a commit to 0ctopus13prime/k-NN that referenced this pull request Mar 27, 2025
0ctopus13prime added a commit that referenced this pull request Mar 28, 2025
… FAISS index. (#2630)

* Adding basic building blocks for MemoryOptimizedSearch. At the moment, only FAISS is supporing this. (#2581)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added IxMp section loading logic from FAISS index. (#2590)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FaissHNSW and bridge to Lucene HNSW graph. (#2594)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS float flat index. (#2598)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS byte index deserializer - FaissIndexScalarQuantizedFlat (#2604)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Enable memory optimized searching in VectorReader for FAISS engine. (#2608)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS CAGRA index. (#2621)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added index scope setting 'index.knn.memory_optimized_search' (#2616)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Apply monotonic increasing integer encoding to FAISS HNSW and IdMapIndex. (#2609)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Adding byte index, FP16 index decoding. (#2618)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added integration tests for LuceneOnFaiss (#2630)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

---------

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>
epalaz pushed a commit to epalaz/k-NN that referenced this pull request Mar 28, 2025
… FAISS index. (opensearch-project#2630)

* Adding basic building blocks for MemoryOptimizedSearch. At the moment, only FAISS is supporing this. (opensearch-project#2581)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added IxMp section loading logic from FAISS index. (opensearch-project#2590)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FaissHNSW and bridge to Lucene HNSW graph. (opensearch-project#2594)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS float flat index. (opensearch-project#2598)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS byte index deserializer - FaissIndexScalarQuantizedFlat (opensearch-project#2604)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Enable memory optimized searching in VectorReader for FAISS engine. (opensearch-project#2608)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS CAGRA index. (opensearch-project#2621)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added index scope setting 'index.knn.memory_optimized_search' (opensearch-project#2616)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Apply monotonic increasing integer encoding to FAISS HNSW and IdMapIndex. (opensearch-project#2609)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Adding byte index, FP16 index decoding. (opensearch-project#2618)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added integration tests for LuceneOnFaiss (opensearch-project#2630)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

---------

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>
@0ctopus13prime 0ctopus13prime deleted the lucene-on-faiss-part8 branch April 5, 2025 00:14
luyuncheng pushed a commit to luyuncheng/k-NN-1 that referenced this pull request Jun 18, 2025
… FAISS index. (opensearch-project#2630)

* Adding basic building blocks for MemoryOptimizedSearch. At the moment, only FAISS is supporing this. (opensearch-project#2581)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added IxMp section loading logic from FAISS index. (opensearch-project#2590)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FaissHNSW and bridge to Lucene HNSW graph. (opensearch-project#2594)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS float flat index. (opensearch-project#2598)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS byte index deserializer - FaissIndexScalarQuantizedFlat (opensearch-project#2604)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Enable memory optimized searching in VectorReader for FAISS engine. (opensearch-project#2608)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added FAISS CAGRA index. (opensearch-project#2621)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added index scope setting 'index.knn.memory_optimized_search' (opensearch-project#2616)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Apply monotonic increasing integer encoding to FAISS HNSW and IdMapIndex. (opensearch-project#2609)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Adding byte index, FP16 index decoding. (opensearch-project#2618)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

* Added integration tests for LuceneOnFaiss (opensearch-project#2630)

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>

---------

Signed-off-by: Dooyong Kim <[email protected]>
Co-authored-by: Dooyong Kim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants