Currently we support the following distance functions:

NameOperator ClassFunctionData TypesOperator
Euclideandist_l2sq_opsl2sq_distREAL[], VECTOR<->
Cosinedist_cos_opscos_distREAL[], VECTOR<->

To create an index you can use the following syntax:

CREATE INDEX ON [TABLE] USING hnsw ([column] [operator class]) WITH (m=[int], ef_construction=[int], ef=[int]);

Example of creating and index which will use cosine function for distance calculation

CREATE INDEX ON lantern_demo USING hnsw (v dist_cos_ops) WITH (m=8, ef_construction=64, ef=128);

You can also use the provided distance functions without index:

SELECT l2sq_dist(ARRAY[0,0.1,0], ARRAY[0.5,0.0,0.2]); -- Euclidean
SELECT cos_dist(ARRAY[0,1,0], ARRAY[1,1,1]); -- Cosine
SELECT hamming_dist(ARRAY[0,1,0], ARRAY[1,1,1]); -- Hamming