Make KnnVectorsFormat#getMaxDimensions abstract (#12466)

- Backward codecs use 1024 as max dims
- Test classes use the current KnnVectorsFormat#DEFAULT_MAX_DIMENSIONS

Relates to PR#12436
Closes #12309
This commit is contained in:
Mayya Sharipova 2023-07-28 08:34:17 -04:00 committed by GitHub
parent 98320d7616
commit 119635ad80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 4 deletions

View File

@ -120,6 +120,11 @@ public class Lucene90HnswVectorsFormat extends KnnVectorsFormat {
return new Lucene90HnswVectorsReader(state);
}
@Override
public final int getMaxDimensions(String fieldName) {
return 1024;
}
@Override
public String toString() {
return "Lucene90HnswVectorsFormat(name = Lucene90HnswVectorsFormat, maxConn = "

View File

@ -136,6 +136,11 @@ public class Lucene91HnswVectorsFormat extends KnnVectorsFormat {
return new Lucene91HnswVectorsReader(state);
}
@Override
public final int getMaxDimensions(String fieldName) {
return 1024;
}
@Override
public String toString() {
return "Lucene91HnswVectorsFormat(name = Lucene91HnswVectorsFormat, maxConn = "

View File

@ -149,6 +149,11 @@ public class Lucene92HnswVectorsFormat extends KnnVectorsFormat {
return new Lucene92HnswVectorsReader(state);
}
@Override
public final int getMaxDimensions(String fieldName) {
return 1024;
}
@Override
public String toString() {
return "Lucene92HnswVectorsFormat(name = Lucene92HnswVectorsFormat, maxConn = "

View File

@ -155,6 +155,11 @@ public class Lucene94HnswVectorsFormat extends KnnVectorsFormat {
return new Lucene94HnswVectorsReader(state);
}
@Override
public final int getMaxDimensions(String fieldName) {
return 1024;
}
@Override
public String toString() {
return "Lucene94HnswVectorsFormat(name=Lucene94HnswVectorsFormat, maxConn="

View File

@ -47,6 +47,11 @@ public final class SimpleTextKnnVectorsFormat extends KnnVectorsFormat {
return new SimpleTextKnnVectorsReader(state);
}
@Override
public int getMaxDimensions(String fieldName) {
return KnnVectorsFormat.DEFAULT_MAX_DIMENSIONS;
}
/** Extension of vectors data file */
static final String VECTOR_EXTENSION = "vec";

View File

@ -83,14 +83,12 @@ public abstract class KnnVectorsFormat implements NamedSPILoader.NamedSPI {
* Returns the maximum number of vector dimensions supported by this codec for the given field
* name
*
* <p>Codecs should override this method to specify the maximum number of dimensions they support.
* <p>Codecs implement this method to specify the maximum number of dimensions they support.
*
* @param fieldName the field name
* @return the maximum number of vector dimensions.
*/
public int getMaxDimensions(String fieldName) {
return DEFAULT_MAX_DIMENSIONS;
}
public abstract int getMaxDimensions(String fieldName);
/**
* EMPTY throws an exception when written. It acts as a sentinel indicating a Codec that does not
@ -140,5 +138,10 @@ public abstract class KnnVectorsFormat implements NamedSPILoader.NamedSPI {
}
};
}
@Override
public int getMaxDimensions(String fieldName) {
return 0;
}
};
}

View File

@ -263,6 +263,11 @@ public class TestPerFieldKnnVectorsFormat extends BaseKnnVectorsFormatTestCase {
public KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException {
return delegate.fieldsReader(state);
}
@Override
public int getMaxDimensions(String fieldName) {
return KnnVectorsFormat.DEFAULT_MAX_DIMENSIONS;
}
}
private static class KnnVectorsFormatMaxDims32 extends KnnVectorsFormat {

View File

@ -54,6 +54,11 @@ public class AssertingKnnVectorsFormat extends KnnVectorsFormat {
return new AssertingKnnVectorsReader(delegate.fieldsReader(state), state.fieldInfos);
}
@Override
public int getMaxDimensions(String fieldName) {
return KnnVectorsFormat.DEFAULT_MAX_DIMENSIONS;
}
static class AssertingKnnVectorsWriter extends KnnVectorsWriter {
final KnnVectorsWriter delegate;