Skip to content

Apache Lucene open-source search software

Remove KnnVectorsFormat#currentVersion (#1077)

Julie Tibshirani653d2ebf7117
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java
index ef9c4623daf..f3b411cee09 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene90/TestLucene90HnswVectorsFormat.java
@@ -22,6 +22,7 @@ import static org.apache.lucene.backward_codecs.lucene90.Lucene90HnswVectorsForm
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.KnnVectorsFormat;
+import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
public class TestLucene90HnswVectorsFormat extends BaseKnnVectorsFormatTestCase {
@@ -30,6 +31,12 @@ public class TestLucene90HnswVectorsFormat extends BaseKnnVectorsFormatTestCase
return new Lucene90RWCodec();
}
+ @Override
+ protected VectorEncoding randomVectorEncoding() {
+ // Older formats only support float vectors
+ return VectorEncoding.FLOAT32;
+ }
+
public void testToString() {
int maxConn = randomIntBetween(DEFAULT_MAX_CONN - 10, DEFAULT_MAX_CONN + 10);
int beamWidth = randomIntBetween(DEFAULT_BEAM_WIDTH - 50, DEFAULT_BEAM_WIDTH + 50);
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene91/TestLucene91HnswVectorsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene91/TestLucene91HnswVectorsFormat.java
index 967e0bfe63d..b8cae733722 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene91/TestLucene91HnswVectorsFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene91/TestLucene91HnswVectorsFormat.java
@@ -22,6 +22,7 @@ import static org.apache.lucene.backward_codecs.lucene91.Lucene91HnswVectorsForm
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.KnnVectorsFormat;
+import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
public class TestLucene91HnswVectorsFormat extends BaseKnnVectorsFormatTestCase {
@@ -30,6 +31,12 @@ public class TestLucene91HnswVectorsFormat extends BaseKnnVectorsFormatTestCase
return new Lucene91RWCodec();
}
+ @Override
+ protected VectorEncoding randomVectorEncoding() {
+ // Older formats only support float vectors
+ return VectorEncoding.FLOAT32;
+ }
+
public void testToString() {
int maxConn = randomIntBetween(DEFAULT_MAX_CONN - 10, DEFAULT_MAX_CONN + 10);
int beamWidth = randomIntBetween(DEFAULT_BEAM_WIDTH - 50, DEFAULT_BEAM_WIDTH + 50);
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene92/TestLucene92HnswVectorsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene92/TestLucene92HnswVectorsFormat.java
index 958da572da4..976191e2484 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene92/TestLucene92HnswVectorsFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene92/TestLucene92HnswVectorsFormat.java
@@ -18,6 +18,7 @@ package org.apache.lucene.backward_codecs.lucene92;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.KnnVectorsFormat;
+import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.tests.index.BaseKnnVectorsFormatTestCase;
public class TestLucene92HnswVectorsFormat extends BaseKnnVectorsFormatTestCase {
@@ -26,6 +27,12 @@ public class TestLucene92HnswVectorsFormat extends BaseKnnVectorsFormatTestCase
return new Lucene92RWCodec();
}
+ @Override
+ protected VectorEncoding randomVectorEncoding() {
+ // Older formats only support float vectors
+ return VectorEncoding.FLOAT32;
+ }
+
public void testToString() {
Codec customCodec =
new Lucene92RWCodec() {
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java
index f775d02acf6..68100b88d15 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/KnnVectorsFormat.java
@@ -18,7 +18,6 @@
package org.apache.lucene.codecs;
import java.io.IOException;
-import org.apache.lucene.codecs.lucene94.Lucene94HnswVectorsFormat;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.index.VectorValues;
@@ -78,15 +77,6 @@ public abstract class KnnVectorsFormat implements NamedSPILoader.NamedSPI {
/** Returns a {@link KnnVectorsReader} to read the vectors from the index. */
public abstract KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException;
- /**
- * Returns the current KnnVectorsFormat version number. Indexes written using the format will be
- * "stamped" with this version.
- */
- public int currentVersion() {
- // return the version supported by older codecs that did not override this method
- return Lucene94HnswVectorsFormat.VERSION_START;
- }
-
/**
* EMPTY throws an exception when written. It acts as a sentinel indicating a Codec that does not
* support vectors.
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94Codec.java
index bae77b50e4b..db8be826d78 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94Codec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94Codec.java
@@ -99,11 +99,6 @@ public class Lucene94Codec extends Codec {
public KnnVectorsFormat getKnnVectorsFormatForField(String field) {
return Lucene94Codec.this.getKnnVectorsFormatForField(field);
}
-
- @Override
- public int currentVersion() {
- return Lucene94HnswVectorsFormat.VERSION_CURRENT;
- }
};
private final StoredFieldsFormat storedFieldsFormat;
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsFormat.java
index b3cf13ca685..d263e8122a9 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene94/Lucene94HnswVectorsFormat.java
@@ -157,11 +157,6 @@ public final class Lucene94HnswVectorsFormat extends KnnVectorsFormat {
return new Lucene94HnswVectorsReader(state);
}
- @Override
- public int currentVersion() {
- return VERSION_CURRENT;
- }
-
@Override
public String toString() {
return "Lucene94HnswVectorsFormat(name=Lucene94HnswVectorsFormat, maxConn="
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseKnnVectorsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseKnnVectorsFormatTestCase.java
index 094ca83a310..fa1a8e62f30 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseKnnVectorsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseKnnVectorsFormatTestCase.java
@@ -670,14 +670,12 @@ public abstract class BaseKnnVectorsFormatTestCase extends BaseIndexFileFormatTe
random().nextInt(VectorSimilarityFunction.values().length)];
}
- private VectorEncoding randomVectorEncoding() {
- Codec codec = getCodec();
- if (codec.knnVectorsFormat().currentVersion()
- >= Codec.forName("Lucene94").knnVectorsFormat().currentVersion()) {
- return VectorEncoding.values()[random().nextInt(VectorEncoding.values().length)];
- } else {
- return VectorEncoding.FLOAT32;
- }
+ /**
+ * This method is overrideable since old codec versions only support {@link
+ * VectorEncoding#FLOAT32}.
+ */
+ protected VectorEncoding randomVectorEncoding() {
+ return VectorEncoding.values()[random().nextInt(VectorEncoding.values().length)];
}
public void testIndexedValueNotAliased() throws Exception {