-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add tooling back on 9.10.x branch to generate int7_hnsw.9.10.zip bwc index #13879
Open
mikemccand
wants to merge
1
commit into
apache:branch_9_10
Choose a base branch
from
mikemccand:branch_9_10
base: branch_9_10
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
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 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 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 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
150 changes: 150 additions & 0 deletions
150
...-codecs/src/test/org/apache/lucene/backward_index/TestInt7HnswBackwardsCompatibility.java
This file contains 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,150 @@ | ||
/* | ||
* 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.lucene.backward_index; | ||
|
||
import static org.apache.lucene.backward_index.TestBasicBackwardsCompatibility.assertKNNSearch; | ||
|
||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; | ||
import java.io.IOException; | ||
import org.apache.lucene.codecs.Codec; | ||
import org.apache.lucene.codecs.KnnVectorsFormat; | ||
import org.apache.lucene.codecs.lucene99.Lucene99Codec; | ||
import org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat; | ||
import org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat; | ||
import org.apache.lucene.document.Document; | ||
import org.apache.lucene.document.Field; | ||
import org.apache.lucene.document.FieldType; | ||
import org.apache.lucene.document.KnnFloatVectorField; | ||
import org.apache.lucene.document.StringField; | ||
import org.apache.lucene.index.DirectoryReader; | ||
import org.apache.lucene.index.IndexReader; | ||
import org.apache.lucene.index.IndexWriter; | ||
import org.apache.lucene.index.IndexWriterConfig; | ||
import org.apache.lucene.index.NoMergePolicy; | ||
import org.apache.lucene.index.VectorSimilarityFunction; | ||
import org.apache.lucene.search.IndexSearcher; | ||
import org.apache.lucene.store.Directory; | ||
import org.apache.lucene.tests.analysis.MockAnalyzer; | ||
import org.apache.lucene.tests.util.TestUtil; | ||
import org.apache.lucene.util.Version; | ||
|
||
public class TestInt7HnswBackwardsCompatibility extends BackwardsCompatibilityTestBase { | ||
|
||
static final String INDEX_NAME = "int7_hnsw"; | ||
static final String SUFFIX = ""; | ||
private static final Version FIRST_INT7_HNSW_VERSION = Version.LUCENE_9_10_0; | ||
private static final String KNN_VECTOR_FIELD = "knn_field"; | ||
private static final int DOC_COUNT = 30; | ||
private static final FieldType KNN_VECTOR_FIELD_TYPE = | ||
KnnFloatVectorField.createFieldType(3, VectorSimilarityFunction.COSINE); | ||
private static final float[] KNN_VECTOR = {0.2f, -0.1f, 0.1f}; | ||
|
||
public TestInt7HnswBackwardsCompatibility(Version version, String pattern) { | ||
super(version, pattern); | ||
} | ||
|
||
/** Provides all sorted versions to the test-framework */ | ||
@ParametersFactory(argumentFormatting = "Lucene-Version:%1$s; Pattern: %2$s") | ||
public static Iterable<Object[]> testVersionsFactory() throws IllegalAccessException { | ||
return allVersion(INDEX_NAME, SUFFIX); | ||
} | ||
|
||
protected Codec getCodec() { | ||
return new Lucene99Codec() { | ||
@Override | ||
public KnnVectorsFormat getKnnVectorsFormatForField(String field) { | ||
return new Lucene99HnswScalarQuantizedVectorsFormat( | ||
Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN, | ||
Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected boolean supportsVersion(Version version) { | ||
return version.onOrAfter(FIRST_INT7_HNSW_VERSION); | ||
} | ||
|
||
@Override | ||
void verifyUsesDefaultCodec(Directory dir, String name) throws IOException { | ||
// We don't use the default codec | ||
} | ||
|
||
public void testInt7HnswIndexAndSearch() throws Exception { | ||
IndexWriterConfig indexWriterConfig = | ||
newIndexWriterConfig(new MockAnalyzer(random())) | ||
.setOpenMode(IndexWriterConfig.OpenMode.APPEND) | ||
.setCodec(getCodec()) | ||
.setMergePolicy(newLogMergePolicy()); | ||
try (IndexWriter writer = new IndexWriter(directory, indexWriterConfig)) { | ||
// add 10 docs | ||
for (int i = 0; i < 10; i++) { | ||
writer.addDocument(knnDocument(i + DOC_COUNT)); | ||
if (random().nextBoolean()) { | ||
writer.flush(); | ||
} | ||
} | ||
if (random().nextBoolean()) { | ||
writer.forceMerge(1); | ||
} | ||
writer.commit(); | ||
try (IndexReader reader = DirectoryReader.open(directory)) { | ||
IndexSearcher searcher = new IndexSearcher(reader); | ||
assertKNNSearch(searcher, KNN_VECTOR, 1000, DOC_COUNT + 10, "0"); | ||
assertKNNSearch(searcher, KNN_VECTOR, 10, 10, "0"); | ||
} | ||
} | ||
// This will confirm the docs are really sorted | ||
TestUtil.checkIndex(directory); | ||
} | ||
|
||
@Override | ||
protected void createIndex(Directory dir) throws IOException { | ||
IndexWriterConfig conf = | ||
new IndexWriterConfig(new MockAnalyzer(random())) | ||
.setMaxBufferedDocs(10) | ||
.setCodec(getCodec()) | ||
.setMergePolicy(NoMergePolicy.INSTANCE); | ||
try (IndexWriter writer = new IndexWriter(dir, conf)) { | ||
for (int i = 0; i < DOC_COUNT; i++) { | ||
writer.addDocument(knnDocument(i)); | ||
} | ||
writer.forceMerge(1); | ||
} | ||
try (DirectoryReader reader = DirectoryReader.open(dir)) { | ||
IndexSearcher searcher = new IndexSearcher(reader); | ||
assertKNNSearch(searcher, KNN_VECTOR, 1000, DOC_COUNT, "0"); | ||
assertKNNSearch(searcher, KNN_VECTOR, 10, 10, "0"); | ||
} | ||
} | ||
|
||
private static Document knnDocument(int id) { | ||
Document doc = new Document(); | ||
float[] vector = {KNN_VECTOR[0], KNN_VECTOR[1], KNN_VECTOR[2] + 0.1f * id}; | ||
doc.add(new KnnFloatVectorField(KNN_VECTOR_FIELD, vector, KNN_VECTOR_FIELD_TYPE)); | ||
doc.add(new StringField("id", Integer.toString(id), Field.Store.YES)); | ||
return doc; | ||
} | ||
|
||
public void testReadOldIndices() throws Exception { | ||
try (DirectoryReader reader = DirectoryReader.open(directory)) { | ||
IndexSearcher searcher = new IndexSearcher(reader); | ||
assertKNNSearch(searcher, KNN_VECTOR, 1000, DOC_COUNT, "0"); | ||
assertKNNSearch(searcher, KNN_VECTOR, 10, 10, "0"); | ||
} | ||
} | ||
} |
Binary file added
BIN
+5.72 KB
lucene/backward-codecs/src/test/org/apache/lucene/backward_index/int7_hnsw.9.10.0.zip
Binary file not shown.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we add this to the back compat script? And if so then there could be a collision with future versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I think we can just rename
int8_hnsw
->int7_hnsw
inaddBackCompatIndexes.py
? But I would do that change on our latest branches (9.12.x, 10.x, 10.0.x) as a separate follow-on PR? This PR is just targetting 9.10.x branch in case we ever need to regen 9.10.x bwc indices again (hope not!).