pgvector.git / summary / log / commit / refs
commit 94a684c9e9d83602bd8b5ee2fa0842ada5c5b736
Author: Andrew Kane <andrew@ankane.org>
Date: Fri Aug 11 03:52:58 2023 +0000
Added test for duplicates
test/t/015_hnsw_duplicates.pl | 45 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/test/t/015_hnsw_duplicates.pl b/test/t/015_hnsw_duplicates.pl
new file mode 100644
index 00000000..5a2b9d19
--- /dev/null
+++ b/test/t/015_hnsw_duplicates.pl
@@ -0,0 +1,45 @@
+use strict;
+use warnings;
+use PostgresNode;
+use TestLib;
+use Test::More;
+
+# Initialize node
+my $node = get_new_node('node');
+$node->init;
+$node->start;
+
+# Create table
+$node->safe_psql("postgres", "CREATE EXTENSION vector;");
+$node->safe_psql("postgres", "CREATE TABLE tst (v vector(3));");
+
+sub insert_vectors
+{
+ for my $i (1 .. 20) {
+ $node->safe_psql("postgres", "INSERT INTO tst VALUES ('[1,1,1]')");
+ }
+}
+
+sub test_duplicates
+{
+ my $res = $node->safe_psql("postgres", qq(
+ SET enable_seqscan = off;
+ SET hnsw.ef_search = 1;
+ SELECT COUNT(*) FROM (SELECT * FROM tst ORDER BY v <-> '[1,1,1]') t;
+ ));
+ is($res, 10);
+}
+
+# Test duplicates with build
+insert_vectors();
+$node->safe_psql("postgres", "CREATE INDEX idx ON tst USING hnsw (v vector_l2_ops);");
+test_duplicates();
+
+# Reset
+$node->safe_psql("postgres", "TRUNCATE tst;");
+
+# Test duplicates with inserts
+insert_vectors();
+test_duplicates();
+
+done_testing();
[parent: 1a0d7bccc7f5]