mirror of https://github.com/apache/lucene.git
Small fix for assertConsistentGraph (#631)
TestKnnGraph.testMultipleVectorFields sometimes breaks with the following message: java.lang.NullPointerException: Cannot invoke "org.apache.lucene.codecs.lucene91.Lucene91HnswVectorsReader.getGraphValues(String)" because "vectorReader" is null This happens in assertConsistentGraph. This patch ensures that for a segment and a field where there is no vectors indexed, we don't run a check on consistent graph.
This commit is contained in:
parent
f103cca565
commit
c8e1c08cc8
|
@ -172,9 +172,11 @@ public class TestKnnGraph extends LuceneTestCase {
|
||||||
int numDoc = atLeast(100);
|
int numDoc = atLeast(100);
|
||||||
int[] dims = new int[numVectorFields];
|
int[] dims = new int[numVectorFields];
|
||||||
float[][][] values = new float[numVectorFields][][];
|
float[][][] values = new float[numVectorFields][][];
|
||||||
|
FieldType[] fieldTypes = new FieldType[numVectorFields];
|
||||||
for (int field = 0; field < numVectorFields; field++) {
|
for (int field = 0; field < numVectorFields; field++) {
|
||||||
dims[field] = atLeast(3);
|
dims[field] = atLeast(3);
|
||||||
values[field] = randomVectors(numDoc, dims[field]);
|
values[field] = randomVectors(numDoc, dims[field]);
|
||||||
|
fieldTypes[field] = KnnVectorField.createFieldType(dims[field], similarityFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Directory dir = newDirectory();
|
try (Directory dir = newDirectory();
|
||||||
|
@ -184,8 +186,7 @@ public class TestKnnGraph extends LuceneTestCase {
|
||||||
for (int field = 0; field < numVectorFields; field++) {
|
for (int field = 0; field < numVectorFields; field++) {
|
||||||
float[] vector = values[field][docID];
|
float[] vector = values[field][docID];
|
||||||
if (vector != null) {
|
if (vector != null) {
|
||||||
FieldType fieldType = KnnVectorField.createFieldType(vector.length, similarityFunction);
|
doc.add(new KnnVectorField(KNN_GRAPH_FIELD + field, vector, fieldTypes[field]));
|
||||||
doc.add(new KnnVectorField(KNN_GRAPH_FIELD + field, vector, fieldType));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String idString = Integer.toString(docID);
|
String idString = Integer.toString(docID);
|
||||||
|
@ -428,7 +429,6 @@ public class TestKnnGraph extends LuceneTestCase {
|
||||||
try (DirectoryReader dr = DirectoryReader.open(iw)) {
|
try (DirectoryReader dr = DirectoryReader.open(iw)) {
|
||||||
for (LeafReaderContext ctx : dr.leaves()) {
|
for (LeafReaderContext ctx : dr.leaves()) {
|
||||||
LeafReader reader = ctx.reader();
|
LeafReader reader = ctx.reader();
|
||||||
VectorValues vectorValues = reader.getVectorValues(vectorField);
|
|
||||||
PerFieldKnnVectorsFormat.FieldsReader perFieldReader =
|
PerFieldKnnVectorsFormat.FieldsReader perFieldReader =
|
||||||
(PerFieldKnnVectorsFormat.FieldsReader) ((CodecReader) reader).getVectorReader();
|
(PerFieldKnnVectorsFormat.FieldsReader) ((CodecReader) reader).getVectorReader();
|
||||||
if (perFieldReader == null) {
|
if (perFieldReader == null) {
|
||||||
|
@ -436,7 +436,11 @@ public class TestKnnGraph extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
Lucene91HnswVectorsReader vectorReader =
|
Lucene91HnswVectorsReader vectorReader =
|
||||||
(Lucene91HnswVectorsReader) perFieldReader.getFieldReader(vectorField);
|
(Lucene91HnswVectorsReader) perFieldReader.getFieldReader(vectorField);
|
||||||
|
if (vectorReader == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
KnnGraphValues graphValues = vectorReader.getGraphValues(vectorField);
|
KnnGraphValues graphValues = vectorReader.getGraphValues(vectorField);
|
||||||
|
VectorValues vectorValues = reader.getVectorValues(vectorField);
|
||||||
if (vectorValues == null) {
|
if (vectorValues == null) {
|
||||||
assert graphValues == null;
|
assert graphValues == null;
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue