-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add e2e test Signed-off-by: silver-ymz <yinmingzhuo@gmail.com> * add github action Signed-off-by: silver-ymz <yinmingzhuo@gmail.com> --------- Signed-off-by: silver-ymz <yinmingzhuo@gmail.com>
- Loading branch information
1 parent
2dc91b5
commit 34bca2a
Showing
11 changed files
with
482 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Tests for pgvecto.rs | ||
|
||
We use [sqllogictest-rs](https://github.com/risinglightdb/sqllogictest-rs) to test the SQL queries. | ||
|
||
To run all tests, use the following command: | ||
```shell | ||
sqllogictest './tests/**/*.slt' | ||
``` | ||
|
||
Each time you modify the source code, you can run the following command to clean up the test data and reload the extension: | ||
```shell | ||
psql -f ./tests/init.sql | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP EXTENSION IF EXISTS vectors CASCADE; | ||
CREATE EXTENSION vectors; | ||
DROP TABLE IF EXISTS t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# cast string to vector | ||
query I | ||
SELECT '[1,2,3]'::vector; | ||
---- | ||
[1, 2, 3] | ||
|
||
statement error Bad charactor | ||
SELECT '{1,2,3}'::vector; | ||
|
||
# cast array to vector | ||
query I | ||
SELECT '{1,2,3}'::real[]::vector; | ||
---- | ||
[1, 2, 3] | ||
|
||
statement error cannot cast type double precision\[\] to vector | ||
SELECT '{1,2,3}'::float[]::vector; | ||
|
||
statement error cannot cast type integer\[\] to vector | ||
SELECT ARRAY[1,2,3]::vector; | ||
|
||
statement error cannot cast type numeric\[\] to vector | ||
SELECT ARRAY[1.,2.,3.]::vector; | ||
|
||
# cast vector to array | ||
query I | ||
SELECT '[1,2,3]'::vector::real[]; | ||
---- | ||
{1,2,3} | ||
|
||
statement error cannot cast type vector to double precision\[\] | ||
SELECT '[1,2,3]'::vector::float[]; | ||
|
||
statement error cannot cast type vector to integer\[\] | ||
SELECT '[1,2,3]'::vector::int[]; | ||
|
||
statement error cannot cast type vector to numeric\[\] | ||
SELECT '[1,2,3]'::vector::numeric[]; | ||
|
||
# cast unusual value to vector | ||
statement error assertion failed: !array.contains_nulls() | ||
SELECT '{NULL}'::real[]::vector; | ||
|
||
query I | ||
SELECT '{NaN, Infinity, -Infinity}'::real[]::vector; | ||
---- | ||
[NaN, inf, -inf] | ||
|
||
query I | ||
SELECT '[3.4e38, -3.4e38, 3.5e38, -3.5e38]'::vector | ||
---- | ||
[340000000000000000000000000000000000000, -340000000000000000000000000000000000000, inf, -inf] | ||
|
||
statement error assertion failed: !array.is_empty() | ||
SELECT '{}'::real[]::vector; | ||
|
||
# TODO: inconsistent behavior with empty array casting | ||
query I | ||
SELECT '[]'::vector; | ||
---- | ||
[] | ||
|
||
# parse all kinds of string | ||
statement error Bad sequence | ||
SELECT '[1,2,3'::vector; | ||
|
||
statement error Bad charactor | ||
SELECT '[1,2,3]9'::vector; | ||
|
||
statement error Bad charactor | ||
SELECT '1,2,3'::vector; | ||
|
||
statement error Bad sequence | ||
SELECT ''::vector; | ||
|
||
statement error Bad sequence | ||
SELECT '['::vector; | ||
|
||
statement error Expect a number | ||
SELECT '[,'::vector; | ||
|
||
query I | ||
SELECT '[]'::vector; | ||
---- | ||
[] | ||
|
||
query I | ||
SELECT '[1,]'::vector; | ||
---- | ||
[1] | ||
|
||
statement error Bad charactor | ||
SELECT '[1a]'::vector; | ||
|
||
statement error Expect a number | ||
SELECT '[1,,3]'::vector; | ||
|
||
statement error Expect a number | ||
SELECT '[1, ,3]'::vector; | ||
|
||
# cast large array to vector | ||
statement ok | ||
SELECT array_agg(n)::real[]::vector FROM generate_series(1, 16001) n; | ||
|
||
# vector array | ||
query I | ||
SELECT unnest('{"[1,2,3]", "[4,5,6]"}'::vector[]); | ||
---- | ||
[1, 2, 3] | ||
[4, 5, 6] | ||
|
||
query I | ||
SELECT '{"[1,2,3]"}'::vector[]; | ||
---- | ||
{"[1, 2, 3]"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
statement ok | ||
DROP TABLE IF EXISTS t; | ||
|
||
statement ok | ||
CREATE TABLE t (val vector(3)); | ||
|
||
statement ok | ||
INSERT INTO t (val) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 1000); | ||
|
||
statement ok | ||
CREATE INDEX ON t USING vectors (val l2_ops) | ||
WITH (options = $$ | ||
capacity = 2000 | ||
[algorithm.flat] | ||
$$); | ||
|
||
statement ok | ||
INSERT INTO t (val) VALUES ('[0.6,0.6,0.6]'); | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <-> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <=> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <#> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
statement ok | ||
DROP TABLE t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
statement ok | ||
DROP TABLE IF EXISTS t; | ||
|
||
statement ok | ||
CREATE TABLE t (val vector(3)); | ||
|
||
statement ok | ||
INSERT INTO t (val) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 1000); | ||
|
||
# TODO: if previous table has nulls, then this statement fails with 'ERROR: called `Option::unwrap()` on a `None` value'. | ||
# And because of borrow checker, we can't remove this table before restarting the postgres. | ||
# Maybe we need better error handling. | ||
statement ok | ||
CREATE INDEX ON t USING vectors (val l2_ops) | ||
WITH (options = $$ | ||
capacity = 2000 | ||
[algorithm.hnsw] | ||
$$); | ||
|
||
statement ok | ||
INSERT INTO t (val) VALUES ('[0.6,0.6,0.6]'); | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <-> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <=> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <#> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
statement ok | ||
DROP TABLE t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
statement ok | ||
DROP TABLE IF EXISTS t; | ||
|
||
# ivf native | ||
statement ok | ||
DROP TABLE IF EXISTS t; | ||
|
||
statement ok | ||
CREATE TABLE t (val vector(3)); | ||
|
||
statement ok | ||
INSERT INTO t (val) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 1000); | ||
|
||
statement ok | ||
CREATE INDEX ON t USING vectors (val l2_ops) | ||
WITH (options = $$ | ||
capacity = 2000 | ||
[algorithm.ivf] | ||
$$); | ||
|
||
statement ok | ||
INSERT INTO t (val) VALUES ('[0.6,0.6,0.6]'); | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <-> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <=> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <#> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
statement ok | ||
DROP TABLE t; | ||
|
||
# ivfpq | ||
statement ok | ||
DROP TABLE IF EXISTS t; | ||
|
||
statement ok | ||
CREATE TABLE t (val vector(3)); | ||
|
||
statement ok | ||
INSERT INTO t (val) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 1000); | ||
|
||
statement ok | ||
CREATE INDEX ON t USING vectors (val l2_ops) | ||
WITH (options = $$ | ||
capacity = 2000 | ||
[algorithm.ivf.quantization.product] | ||
$$); | ||
|
||
statement ok | ||
INSERT INTO t (val) VALUES ('[0.6,0.6,0.6]'); | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <-> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <=> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
query I | ||
SELECT COUNT(1) FROM (SELECT 1 FROM t ORDER BY val <#> '[0.5,0.5,0.5]' limit 10) t2; | ||
---- | ||
10 | ||
|
||
statement ok | ||
DROP TABLE t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# basic + - = <> < <= > >= | ||
query I | ||
SELECT '[1,2.3,4e5]'::vector + '[6,7.8,9e10]'; | ||
---- | ||
[7, 10.1, 90000400000] | ||
|
||
query I | ||
SELECT '[1,2.3,4e5]'::vector - '[6,7.8,9e10]'; | ||
---- | ||
[-5, -5.5, -89999600000] | ||
|
||
query I | ||
SELECT '[1,2,3]'::vector = '[1,2,3]'; | ||
---- | ||
t | ||
|
||
query I | ||
SELECT '[1,2,3]'::vector <> '[1,2,3]'; | ||
---- | ||
f | ||
|
||
query I | ||
SELECT '[1,2]'::vector < '[2,2]'; | ||
---- | ||
t | ||
|
||
query I | ||
SELECT '[1,2]'::vector < '[1,3]'; | ||
---- | ||
t | ||
|
||
# TODO: may need better error message | ||
statement error assertion failed: `\(left == right\)` | ||
SELECT '[1,2]'::vector < '[1,2,3]'; | ||
|
||
query I | ||
SELECT '[1,2]'::vector <= '[2,2]'; | ||
---- | ||
t | ||
|
||
query I | ||
SELECT '[1,2]'::vector > '[2,2]'; | ||
---- | ||
f | ||
|
||
query I | ||
SELECT '[1,2]'::vector >= '[2,2]'; | ||
---- | ||
f | ||
|
||
# basic <->(squared Euclidean distance) <#>(negative dot product distance) <=>(negative cosine distance) | ||
query I | ||
SELECT '[1,2]'::vector <-> '[3,4]'; | ||
---- | ||
8 | ||
|
||
query I | ||
SELECT '[1,2]'::vector <#> '[3,4]'; | ||
---- | ||
-11 | ||
|
||
query I | ||
SELECT '[1,2]'::vector <=> '[3,4]'; | ||
---- | ||
-0.98386997 |
Oops, something went wrong.