Skip to content

Instantly share code, notes, and snippets.

@ankane
Created November 16, 2023 00:44
Show Gist options
  • Save ankane/2ea49423534051eb76565435e76b4b83 to your computer and use it in GitHub Desktop.
Save ankane/2ea49423534051eb76565435e76b4b83 to your computer and use it in GitHub Desktop.
# CREATE INDEX output omitted
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: vector_l2_squared_distance
psql:repro.sql:8: INFO: l2_distance
psql:repro.sql:8: INFO: l2_distance
id
----
1
2
(2 rows)
diff --git a/src/vector.c b/src/vector.c
index 2f1e886..bf6c01a 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -563,6 +563,8 @@ l2_distance(PG_FUNCTION_ARGS)
float distance = 0.0;
float diff;
+ elog(INFO, "l2_distance");
+
CheckDims(a, b);
/* Auto-vectorized */
@@ -590,6 +592,8 @@ vector_l2_squared_distance(PG_FUNCTION_ARGS)
float distance = 0.0;
float diff;
+ elog(INFO, "vector_l2_squared_distance");
+
CheckDims(a, b);
/* Auto-vectorized */
SET enable_seqscan = off;
DROP TABLE IF EXISTS items;
CREATE TABLE items (id bigserial primary key, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[0,0,0]'), ('[1,1,1]'), ('[2,2,2]'), ('[3,3,3]');
CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 1);
SELECT id FROM items ORDER BY embedding <-> '[0,0,0]' LIMIT 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment