Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public static ProductQuantization compute(RandomAccessVectorValues ravv,
{
checkClusterCount(clusterCount);

if (ravv.size() < clusterCount) {
throw new IllegalArgumentException("Cannot train PQ with %d clusters on %d points, supply more training vectors or lower cluster count.");
}
var subvectorSizesAndOffsets = getSubvectorSizesAndOffsets(ravv.dimension(), M);
var vectors = extractTrainingVectors(ravv, parallelExecutor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,17 @@ public void testPQCodebookSums() {
}
}
}

@Test
public void testErrorOnInsufficientVectors() {
int dim = 384;
var pqM = 48;

var ravv100 = new ListRandomAccessVectorValues(createRandomVectors(100, dim), dim);
var ravv200 = new ListRandomAccessVectorValues(createRandomVectors(200, dim), dim);
ProductQuantization.compute(ravv100, pqM, 50, false); // should not throw
assertThrows(IllegalArgumentException.class, () -> ProductQuantization.compute(ravv100, pqM, 150, false));
ProductQuantization.compute(ravv200, pqM, 150, false); // should not throw
assertThrows(IllegalArgumentException.class, () -> ProductQuantization.compute(ravv200, pqM, 256, false));
}
}
Loading