pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] PR #679: Hnsw streamed tests
5+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] PR #679: Hnsw streamed tests
@ 2024-09-23 12:05  "VladlenPopolitov (@VladlenPopolitov)" <noreply+VladlenPopolitov@github.com>
  0 siblings, 0 replies; 5+ messages in thread

From: VladlenPopolitov (@VladlenPopolitov) @ 2024-09-23 12:05 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Added tests fro hnsw streaming. Currently test crashes the server after TRUNCATE TABLE with active index and hnsw.streaming=ON. 

inline patch 1: test/expected/hnsw_streaming.out, test/sql/hnsw_streaming.sql (+147/-0 lines) download inline-1.patchdiff --git a/test/expected/hnsw_streaming.out b/test/expected/hnsw_streaming.out new file mode 100644 index 000000000..91b852a6c --- /dev/null +++ b/test/expected/hnsw_streaming.out @@ -0,0 +1,100 @@ +SELECT t, +Array[t,t+1,t+2]::vector(3) AS val +INTO test_where +FROM generate_series(1, 2000) as t; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; + t +------ + 1501 + 1502 +(2 rows) + +CREATE INDEX test_where_idx ON test_where USING hnsw (val vector_l2_ops) WITH (m=10); +set hnsw.streaming=off; +set hnsw.ef_search=100; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; + t +--- +(0 rows) + +set hnsw.streaming=on; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; + t +------ + 1501 + 1502 +(2 rows) + +SELECT t FROM test_where WHERE t>2000 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; + t +--- +(0 rows) + +DELETE FROM test_where; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; + t +--- +(0 rows) + +TRUNCATE test_where; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; + t +--- +(0 rows) + +DROP TABLE test_where; +SET enable_seqscan = off; +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX t_idx ON t USING hnsw (val vector_l2_ops); +INSERT INTO t (val) VALUES ('[1,2,4]'); +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + val +--------- + [1,2,3] + [1,2,4] + [1,1,1] + [0,0,0] +(4 rows) + +SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector)) t2; + count +------- + 4 +(1 row) + +SELECT COUNT(*) FROM t; + count +------- + 5 +(1 row) + +TRUNCATE t; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + val +----- +(0 rows) + +DROP TABLE t; +SET enable_seqscan = off; +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX t_idx ON t USING hnsw (val vector_ip_ops); +INSERT INTO t (val) VALUES ('[1,2,4]'); +SELECT * FROM t ORDER BY val <#> '[3,3,3]'; + val +--------- + [1,2,4] + [1,2,3] + [1,1,1] + [0,0,0] +(4 rows) + +SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::vector)) t2; + count +------- + 4 +(1 row) + +DROP TABLE t; +set hnsw.streaming=off; diff --git a/test/sql/hnsw_streaming.sql b/test/sql/hnsw_streaming.sql new file mode 100644 index 000000000..75f4a3855 --- /dev/null +++ b/test/sql/hnsw_streaming.sql @@ -0,0 +1,47 @@ +SELECT t, +Array[t,t+1,t+2]::vector(3) AS val +INTO test_where +FROM generate_series(1, 2000) as t; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; +CREATE INDEX test_where_idx ON test_where USING hnsw (val vector_l2_ops) WITH (m=10); +set hnsw.streaming=off; +set hnsw.ef_search=100; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; +set hnsw.streaming=on; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; +SELECT t FROM test_where WHERE t>2000 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; +DELETE FROM test_where; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; +TRUNCATE test_where; +SELECT t FROM test_where WHERE t>1500 ORDER BY val <-> '[1000.2,1000,1000.1]' LIMIT 2; +DROP TABLE test_where; +SET enable_seqscan = off; + +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX t_idx ON t USING hnsw (val vector_l2_ops); + +INSERT INTO t (val) VALUES ('[1,2,4]'); + +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; +SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <-> (SELECT NULL::vector)) t2; +SELECT COUNT(*) FROM t; + +TRUNCATE t; +SELECT * FROM t ORDER BY val <-> '[3,3,3]'; + +DROP TABLE t; +SET enable_seqscan = off; + +CREATE TABLE t (val vector(3)); +INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]'), (NULL); +CREATE INDEX t_idx ON t USING hnsw (val vector_ip_ops); + +INSERT INTO t (val) VALUES ('[1,2,4]'); + +SELECT * FROM t ORDER BY val <#> '[3,3,3]'; +SELECT COUNT(*) FROM (SELECT * FROM t ORDER BY val <#> (SELECT NULL::vector)) t2; + +DROP TABLE t; + +set hnsw.streaming=off;
^ permalink raw [nested|flat] 5+ messages in thread

* Re: [pgvector/pgvector] PR #679: Hnsw streamed tests
@ 2024-10-14 20:01  "ankane (@ankane)" <noreply+ankane@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: ankane (@ankane) @ 2024-10-14 20:01 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Hi @VladlenPopolitov, thanks for the PR. I added basic tests for iterative search in b26a21b848fdb0a642fa16053ebdd1baddac0e25 (as the TAP tests should cover the main functionality), but it'd be good to include a test for `TRUNCATE` in `hnsw_vector.sql` as well.

^ permalink  raw  [nested|flat] 5+ messages in thread

* Re: [pgvector/pgvector] PR #679: Hnsw streamed tests
@ 2024-10-23 13:00  "VladlenPopolitov (@VladlenPopolitov)" <noreply+VladlenPopolitov@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: VladlenPopolitov (@VladlenPopolitov) @ 2024-10-23 13:00 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane  I added other test #698, that checks the insertion of the first row to a table with index. It works in pair with TRUNCATE test.

^ permalink  raw  [nested|flat] 5+ messages in thread

* Re: [pgvector/pgvector] PR #679: Hnsw streamed tests
@ 2025-02-14 00:28  "ankane (@ankane)" <noreply+ankane@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: ankane (@ankane) @ 2025-02-14 00:28 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 5+ messages in thread

* Re: [pgvector/pgvector] PR #679: Hnsw streamed tests
@ 2025-02-14 00:29  "ankane (@ankane)" <noreply+ankane@github.com>
  3 siblings, 0 replies; 5+ messages in thread

From: ankane (@ankane) @ 2025-02-14 00:29 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

Added minimal tests for iterative index scans with empty indexes in the commit above.

^ permalink  raw  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2025-02-14 00:29 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-09-23 12:05 [pgvector/pgvector] PR #679: Hnsw streamed tests "VladlenPopolitov (@VladlenPopolitov)" <noreply+VladlenPopolitov@github.com>
2024-10-14 20:01 ` "ankane (@ankane)" <noreply+ankane@github.com>
2024-10-23 13:00 ` "VladlenPopolitov (@VladlenPopolitov)" <noreply+VladlenPopolitov@github.com>
2025-02-14 00:28 ` "ankane (@ankane)" <noreply+ankane@github.com>
2025-02-14 00:29 ` "ankane (@ankane)" <noreply+ankane@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox