Improved random_sparsevec subroutine [skip ci]

This commit is contained in:
Andrew Kane committed 2026-12-02 22:01:15 -08:00
1 parent 3cb6da44fa
commit aced364bb2
1 file changed
+3 -2
+3 -2
View File
@@ -16,9 +16,10 @@ $node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v sparsevec_l2_ops
sub random_sparsevec
{
my ($nnz) = @_;
my @elements;
my %indices;
for (1 .. int(rand(1001)))
while (keys %indices < $nnz)
{
my $index = int(rand(100000)) + 1;
if (!exists($indices{$index}))
@@ -37,7 +38,7 @@ for (1 .. 3)
{
for (1 .. 100)
{
my $embedding = random_sparsevec();
my $embedding = random_sparsevec(int(rand(1001)));
$node->safe_psql("postgres", "INSERT INTO tst (v) VALUES ('$embedding');");
}