-
Notifications
You must be signed in to change notification settings - Fork 839
SOLR-18267: Add flat vector index with no HNSW #4492
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
Open
adamjq
wants to merge
8
commits into
apache:main
Choose a base branch
from
adamjq:SOLR-18267-add-flat-vector-index
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c58cd3b
SOLR-18267: Add flat vector index with no HNSW
adamjq 80f894b
Add changelog entry
adamjq f46d944
Address PR comments
adamjq bf63de6
Improve comment about Lucene99FlatVectorsFormat SPI limitation
adamjq be37b1c
Format with gradlew tidy
adamjq 5e285b2
Update test and docs
adamjq ac2afb7
Add fq case to vectorSimilarity test case
adamjq d1cd307
Rename wrapper class to Solr101FlatVectorFormat to include version name
adamjq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| title: Add knnAlgorithm="flat" option to DenseVectorField to skip HNSW graph construction for exact vector search | ||
| type: added | ||
| authors: | ||
| - name: Adam Quigley | ||
| links: | ||
| - name: SOLR-18267 | ||
| url: https://issues.apache.org/jira/browse/SOLR-18267 |
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
66 changes: 66 additions & 0 deletions
66
solr/core/src/java/org/apache/solr/core/Solr101FlatVectorFormat.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.solr.core; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.lucene.codecs.KnnVectorsFormat; | ||
| import org.apache.lucene.codecs.KnnVectorsReader; | ||
| import org.apache.lucene.codecs.KnnVectorsWriter; | ||
| import org.apache.lucene.codecs.hnsw.FlatVectorScorerUtil; | ||
| import org.apache.lucene.codecs.lucene99.Lucene99FlatVectorsFormat; | ||
| import org.apache.lucene.index.SegmentReadState; | ||
| import org.apache.lucene.index.SegmentWriteState; | ||
|
|
||
| /** | ||
| * SPI-registered wrapper for {@link Lucene99FlatVectorsFormat}, which Lucene does not register as a | ||
| * {@link KnnVectorsFormat} in SPI. | ||
| * | ||
| * @lucene.spi {@value #NAME} | ||
| * @since 10.1 | ||
| */ | ||
| public final class Solr101FlatVectorFormat extends KnnVectorsFormat { | ||
|
|
||
| static final String NAME = "Solr101FlatVectorFormat"; | ||
|
|
||
| private final Lucene99FlatVectorsFormat delegate; | ||
|
|
||
| public Solr101FlatVectorFormat() { | ||
| super(NAME); | ||
| this.delegate = | ||
| new Lucene99FlatVectorsFormat(FlatVectorScorerUtil.getLucene99FlatVectorsScorer()); | ||
| } | ||
|
|
||
| @Override | ||
| public KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException { | ||
| return delegate.fieldsWriter(state); | ||
| } | ||
|
|
||
| @Override | ||
| public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException { | ||
| return delegate.fieldsReader(state); | ||
| } | ||
|
|
||
| @Override | ||
| public int getMaxDimensions(String fieldName) { | ||
| return delegate.getMaxDimensions(fieldName); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return NAME; | ||
| } | ||
| } |
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
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
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
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
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
16 changes: 16 additions & 0 deletions
16
solr/core/src/resources/META-INF/services/org.apache.lucene.codecs.KnnVectorsFormat
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| org.apache.solr.core.Solr101FlatVectorFormat |
29 changes: 29 additions & 0 deletions
29
...core/src/test-files/solr/collection1/conf/bad-schema-densevector-flat-binaryQuantized.xml
|
adamjq marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?xml version="1.0" ?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| <!-- Test schema file for DenseVectorField --> | ||
|
|
||
| <schema name="bad-schema-densevector-flat-bq" version="1.7"> | ||
| <fieldType name="string" class="solr.StrField" multiValued="true"/> | ||
| <fieldType name="knn_vector_flat_bq" class="solr.BinaryQuantizedDenseVectorField" vectorDimension="4" similarityFunction="cosine" knnAlgorithm="flat"/> | ||
|
|
||
| <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/> | ||
| <field name="vector" type="knn_vector_flat_bq" indexed="true" stored="true"/> | ||
|
|
||
| <uniqueKey>id</uniqueKey> | ||
| </schema> |
29 changes: 29 additions & 0 deletions
29
...core/src/test-files/solr/collection1/conf/bad-schema-densevector-flat-scalarQuantized.xml
|
adamjq marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?xml version="1.0" ?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| <!-- Test schema file for DenseVectorField --> | ||
|
|
||
| <schema name="bad-schema-densevector-flat-quantized" version="1.7"> | ||
| <fieldType name="string" class="solr.StrField" multiValued="true"/> | ||
| <fieldType name="knn_vector_flat_sq" class="solr.ScalarQuantizedDenseVectorField" vectorDimension="4" similarityFunction="cosine" knnAlgorithm="flat"/> | ||
|
|
||
| <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/> | ||
| <field name="vector" type="knn_vector_flat_sq" indexed="true" stored="true"/> | ||
|
|
||
| <uniqueKey>id</uniqueKey> | ||
| </schema> |
31 changes: 31 additions & 0 deletions
31
solr/core/src/test-files/solr/collection1/conf/schema-densevector-flat.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" ?> | ||
| <!-- | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| <!-- Test schema file for DenseVectorField with flat (non-HNSW) algorithm --> | ||
|
|
||
| <schema name="schema-densevector-flat" version="1.7"> | ||
| <fieldType name="string" class="solr.StrField" multiValued="true"/> | ||
| <fieldType name="knn_vector_flat" class="solr.DenseVectorField" vectorDimension="4" similarityFunction="cosine" knnAlgorithm="flat"/> | ||
| <fieldType name="knn_vector_flat_byte" class="solr.DenseVectorField" vectorDimension="4" similarityFunction="cosine" knnAlgorithm="flat" vectorEncoding="BYTE"/> | ||
|
|
||
| <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/> | ||
| <field name="vector_flat" type="knn_vector_flat" indexed="true" stored="true"/> | ||
| <field name="vector_flat_byte" type="knn_vector_flat_byte" indexed="true" stored="true"/> | ||
|
|
||
| <uniqueKey>id</uniqueKey> | ||
| </schema> |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.