File: 038_hnsw_sparsevec_vacuum_insert.pl

package info (click to toggle)
pgvector 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,148 kB
  • sloc: ansic: 9,219; perl: 2,802; sql: 2,017; makefile: 53; sh: 1
file content (42 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;

# Initialize node
my $node = PostgreSQL::Test::Cluster->new('node');
$node->init;
$node->start;

# Create table and index
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
$node->safe_psql("postgres", "CREATE TABLE tst (i serial, v sparsevec(100000));");
$node->safe_psql("postgres", "CREATE INDEX ON tst USING hnsw (v sparsevec_l2_ops);");

for (1 .. 3)
{
	for (1 .. 100)
	{
		my @elements;
		my %indices;
		for (1 .. int(rand() * 100))
		{
			my $index = int(rand() * (100000 - 1)) + 1;
			if (!exists($indices{$index}))
			{
				my $value = rand();
				push(@elements, "$index:$value");
				$indices{$index} = 1;
			}
		}
		my $embedding = "{" . join(",", @elements) . "}/100000";
		$node->safe_psql("postgres", "INSERT INTO tst (v) VALUES ('$embedding');");
	}

	$node->safe_psql("postgres", "DELETE FROM tst WHERE i % 2 = 0;");
	$node->safe_psql("postgres", "VACUUM tst;");
	is(1, 1);
}

done_testing();