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);
|
||||
if (target.length != values.dimension()) {
|
||||
throw new IllegalArgumentException(
|
||||
"incorrect dimension for field "
|
||||
+ field
|
||||
+ "; expected "
|
||||
+ values.dimension()
|
||||
+ " but target has "
|
||||
+ target.length);
|
||||
"vector dimensions differ: " + target.length + "!=" + values.dimension());
|
||||
}
|
||||
FieldInfo info = readState.fieldInfos.fieldInfo(field);
|
||||
VectorSimilarityFunction vectorSimilarity = info.getVectorSimilarityFunction();
|
||||
HitQueue topK = new HitQueue(k, false);
|
||||
int doc;
|
||||
while ((doc = values.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
||||
if (acceptDocs != null && acceptDocs.get(doc) == false) {
|
||||
continue;
|
||||
}
|
||||
float[] vector = values.vectorValue();
|
||||
float score = vectorSimilarity.compare(vector, target);
|
||||
if (vectorSimilarity.reversed) {
|
||||
|
|
|
@ -859,10 +859,11 @@ public abstract class BaseKnnVectorsFormatTestCase extends BaseIndexFileFormatTe
|
|||
}
|
||||
// assert that searchNearestVectors returns the expected number of documents, in
|
||||
// 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 =
|
||||
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++) {
|
||||
assertTrue(results.scoreDocs[i].score >= results.scoreDocs[i + 1].score);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue