mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 17:32: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
30 lines
774 B
SQL
30 lines
774 B
SQL
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
\echo Use "CREATE EXTENSION hnsw" to load this file. \quit
|
|
|
|
-- functions
|
|
|
|
CREATE FUNCTION l2_distance(real[], real[]) RETURNS real
|
|
AS 'MODULE_PATHNAME' LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE;
|
|
|
|
-- operators
|
|
|
|
CREATE OPERATOR <-> (
|
|
LEFTARG = real[], RIGHTARG = real[], PROCEDURE = l2_distance,
|
|
COMMUTATOR = '<->'
|
|
);
|
|
|
|
-- access method
|
|
|
|
CREATE FUNCTION hnsw_handler(internal) RETURNS index_am_handler
|
|
AS 'MODULE_PATHNAME' LANGUAGE C;
|
|
|
|
CREATE ACCESS METHOD hnsw TYPE INDEX HANDLER hnsw_handler;
|
|
|
|
COMMENT ON ACCESS METHOD hnsw IS 'hnsw index access method';
|
|
|
|
-- opclasses
|
|
|
|
CREATE OPERATOR CLASS knn_ops
|
|
DEFAULT FOR TYPE real[] USING hnsw AS
|
|
OPERATOR 1 <-> (real[], real[]) FOR ORDER BY float_ops;
|