mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-16 18:02:56 +00:00
## Describe your changes Port HNSW implementation for ANN search top Postgres ## Issue ticket number and link https://www.pinecone.io/learn/hnsw ## Checklist before requesting a review - [ ] I have performed a self-review of my code. - [ ] If it is a core feature, I have added thorough tests. - [ ] Do we need to implement analytics? if so did you add the relevant metrics to the dashboard? - [ ] If this PR requires public announcement, mark it with /release-notes label and add several sentences in this section. ## Checklist before merging - [ ] Do not forget to reformat commit message to not include the above checklist
29 lines
740 B
Plaintext
29 lines
740 B
Plaintext
SET enable_seqscan = off;
|
|
CREATE TABLE t (val real[]);
|
|
INSERT INTO t (val) VALUES ('{0,0,0}'), ('{1,2,3}'), ('{1,1,1}'), (NULL);
|
|
CREATE INDEX ON t USING hnsw (val) WITH (maxelements = 10, dims=3, m=3);
|
|
INSERT INTO t (val) VALUES (array[1,2,4]);
|
|
explain SELECT * FROM t ORDER BY val <-> array[3,3,3];
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------
|
|
Index Scan using t_val_idx on t (cost=4.02..8.06 rows=3 width=36)
|
|
Order By: (val <-> '{3,3,3}'::real[])
|
|
(2 rows)
|
|
|
|
SELECT * FROM t ORDER BY val <-> array[3,3,3];
|
|
val
|
|
---------
|
|
{1,2,3}
|
|
{1,2,4}
|
|
{1,1,1}
|
|
{0,0,0}
|
|
(4 rows)
|
|
|
|
SELECT COUNT(*) FROM t;
|
|
count
|
|
-------
|
|
5
|
|
(1 row)
|
|
|
|
DROP TABLE t;
|