-
Notifications
You must be signed in to change notification settings - Fork 1.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
Fix NPE when LeafReader return null VectorValues #13162
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,11 +246,12 @@ public final PostingsEnum postings(Term term) throws IOException { | |
public final TopDocs searchNearestVectors( | ||
String field, float[] target, int k, Bits acceptDocs, int visitedLimit) throws IOException { | ||
FieldInfo fi = getFieldInfos().fieldInfo(field); | ||
if (fi == null || fi.getVectorDimension() == 0) { | ||
// The field does not exist or does not index vectors | ||
FloatVectorValues floatVectorValues = getFloatVectorValues(fi.name); | ||
if (floatVectorValues == null) { | ||
FloatVectorValues.checkField(this, field); | ||
return TopDocsCollector.EMPTY_TOPDOCS; | ||
} | ||
k = Math.min(k, getFloatVectorValues(fi.name).size()); | ||
k = Math.min(k, floatVectorValues.size()); | ||
if (k == 0) { | ||
return TopDocsCollector.EMPTY_TOPDOCS; | ||
} | ||
|
@@ -287,11 +288,12 @@ public final TopDocs searchNearestVectors( | |
public final TopDocs searchNearestVectors( | ||
String field, byte[] target, int k, Bits acceptDocs, int visitedLimit) throws IOException { | ||
FieldInfo fi = getFieldInfos().fieldInfo(field); | ||
if (fi == null || fi.getVectorDimension() == 0) { | ||
// The field does not exist or does not index vectors | ||
ByteVectorValues byteVectorValues = getByteVectorValues(fi.name); | ||
if (byteVectorValues == null) { | ||
ByteVectorValues.checkField(this, field); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The leaf reader here shouldn't throw. Especially since the companion method that accepts a KnnCollector doesn't. |
||
return TopDocsCollector.EMPTY_TOPDOCS; | ||
} | ||
k = Math.min(k, getByteVectorValues(fi.name).size()); | ||
k = Math.min(k, byteVectorValues.size()); | ||
if (k == 0) { | ||
return TopDocsCollector.EMPTY_TOPDOCS; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,9 @@ public FloatVectorSimilarityValuesSource(float[] vector, String fieldName) { | |
@Override | ||
public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { | ||
final FloatVectorValues vectorValues = ctx.reader().getFloatVectorValues(fieldName); | ||
if (vectorValues == null) { | ||
return DoubleValues.EMPTY; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you throw in the byte similarity source, but not here? We need to be consistent. I think throwing here is acceptable as well (via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. I will fix it. |
||
VectorSimilarityFunction function = | ||
ctx.reader().getFieldInfos().fieldInfo(fieldName).getVectorSimilarityFunction(); | ||
return new DoubleValues() { | ||
|
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.
The leaf reader here shouldn't throw. Especially since the companion method that accepts a KnnCollector doesn't.