mirror of https://github.com/apache/lucene.git
LUCENE-10063: test fixes relating to SimpleTextKnnVectorsReader (#273)
This commit is contained in:
parent
424192e170
commit
e3e54c95c9
|
@ -148,18 +148,16 @@ public class SimpleTextKnnVectorsReader extends KnnVectorsReader {
|
||||||
VectorValues values = getVectorValues(field);
|
VectorValues values = getVectorValues(field);
|
||||||
if (target.length != values.dimension()) {
|
if (target.length != values.dimension()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"incorrect dimension for field "
|
"vector dimensions differ: " + target.length + "!=" + values.dimension());
|
||||||
+ field
|
|
||||||
+ "; expected "
|
|
||||||
+ values.dimension()
|
|
||||||
+ " but target has "
|
|
||||||
+ target.length);
|
|
||||||
}
|
}
|
||||||
FieldInfo info = readState.fieldInfos.fieldInfo(field);
|
FieldInfo info = readState.fieldInfos.fieldInfo(field);
|
||||||
VectorSimilarityFunction vectorSimilarity = info.getVectorSimilarityFunction();
|
VectorSimilarityFunction vectorSimilarity = info.getVectorSimilarityFunction();
|
||||||
HitQueue topK = new HitQueue(k, false);
|
HitQueue topK = new HitQueue(k, false);
|
||||||
int doc;
|
int doc;
|
||||||
while ((doc = values.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
while ((doc = values.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
||||||
|
if (acceptDocs != null && acceptDocs.get(doc) == false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
float[] vector = values.vectorValue();
|
float[] vector = values.vectorValue();
|
||||||
float score = vectorSimilarity.compare(vector, target);
|
float score = vectorSimilarity.compare(vector, target);
|
||||||
if (vectorSimilarity.reversed) {
|
if (vectorSimilarity.reversed) {
|
||||||
|
|
|
@ -859,10 +859,11 @@ public abstract class BaseKnnVectorsFormatTestCase extends BaseIndexFileFormatTe
|
||||||
}
|
}
|
||||||
// assert that searchNearestVectors returns the expected number of documents, in
|
// assert that searchNearestVectors returns the expected number of documents, in
|
||||||
// descending score order
|
// descending score order
|
||||||
int k = random().nextInt(numDoc / 2);
|
int size = ctx.reader().getVectorValues(fieldName).size();
|
||||||
|
int k = random().nextInt(size / 2 + 1);
|
||||||
TopDocs results =
|
TopDocs results =
|
||||||
ctx.reader().searchNearestVectors(fieldName, randomVector(dimension), k, liveDocs);
|
ctx.reader().searchNearestVectors(fieldName, randomVector(dimension), k, liveDocs);
|
||||||
assertEquals(k, results.scoreDocs.length);
|
assertEquals(Math.min(k, size), results.scoreDocs.length);
|
||||||
for (int i = 0; i < k - 1; i++) {
|
for (int i = 0; i < k - 1; i++) {
|
||||||
assertTrue(results.scoreDocs[i].score >= results.scoreDocs[i + 1].score);
|
assertTrue(results.scoreDocs[i].score >= results.scoreDocs[i + 1].score);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue