SOLR-18267: Add flat vector index with no HNSW#4492
Open
adamjq wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://issues.apache.org/jira/browse/SOLR-18267
Description
There are certain use cases, such as highly selective filters on large datasets, where it can be more efficient to perform a brute-force KNN search as a post-filter, instead of during ANN search.
Solr currently supports this use case with the vectorSimilarity Function and an
fq, but still requires an HNSW graph to be built during indexing when using DenseVectorField, even if it's not used during search. The goal of this feature is to avoid paying the cost of HNSW graph construction and rebuilding ingestion when ANN search isn't used.Solution
This PR introduces a new
knnAlgorithm=flatoption to DenseVectorField that uses Lucene99FlatVectorsFormat. This stores vectors in the index (.vec/.vemf files) without building the HNSW graph (.vex/.vem files).Lucene99FlatVectorsFormatis not registered in Lucene's SPI, so this PR includes a wrapper class SolrFlatVectorFormat that delegates to Lucene99FlatVectorsFormat as a workaround. There are examples in other Lucene-based engines using a similar pattern to provide a flat vector format for exact KNN search that wraps Lucene99FlatVectorsFormat.Limitations
This PR currently doesn't support:
knnAlgorithm=flatfor quantized variantsknnquery parser. Only vectorSimilarity is initially supported.Both features could be shipped as follow-ups.
AI Disclosure: Claude was used to assist with this PR. All code has been reviewed and tested by me.
Tests
Unit tests for Dense Vector Fields and quantized variants.
Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.