-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
renamed to lantern_hnsw.ef_search, refactored usearch code, and added…
… a test hnsw_ef_search
- Loading branch information
1 parent
b5b93ac
commit 7c260fc
Showing
6 changed files
with
270 additions
and
21 deletions.
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,194 @@ | ||
------------------------------------------------------------------------------ | ||
-- Test changing lantern_hnsw.ef_search variable at runtime | ||
------------------------------------------------------------------------------ | ||
\ir utils/sift1k_array.sql | ||
CREATE TABLE IF NOT EXISTS sift_base1k ( | ||
id SERIAL, | ||
v REAL[] | ||
); | ||
COPY sift_base1k (v) FROM '/tmp/lantern/vector_datasets/sift_base1k_arrays.csv' WITH csv; | ||
CREATE INDEX hnsw_l2_index ON sift_base1k USING hnsw (v) WITH (_experimental_index_path='/tmp/lantern/files/index-sift1k-l2.usearch'); | ||
INFO: done init usearch index | ||
INFO: done loading usearch index | ||
INFO: done saving 1000 vectors | ||
SELECT * FROM ldb_get_indexes('sift_base1k'); | ||
indexname | size | indexdef | total_index_size | ||
---------------+--------+----------------------------------------------------------------------------------------------------------------------------------------------+------------------ | ||
hnsw_l2_index | 720 kB | CREATE INDEX hnsw_l2_index ON public.sift_base1k USING hnsw (v) WITH (_experimental_index_path='/tmp/lantern/files/index-sift1k-l2.usearch') | 720 kB | ||
(1 row) | ||
|
||
INSERT INTO sift_base1k (id, v) VALUES | ||
(1001, array_fill(1, ARRAY[128])), | ||
(1002, array_fill(2, ARRAY[128])); | ||
-- Validate error on invalid ef_search values | ||
\set ON_ERROR_STOP off | ||
--SET lantern_hnsw.ef_search = -1; | ||
--SET lantern_hnsw.ef_search = 0; | ||
--SET lantern_hnsw.ef_search = 401; | ||
\set ON_ERROR_STOP on | ||
-- Repeat the same query while varying ef parameter | ||
-- NOTE: it is not entirely known if the results of these are deterministic | ||
SET enable_seqscan = false; | ||
SELECT v AS v1001 FROM sift_base1k WHERE id = 1001 \gset | ||
-- Queries below have the same result | ||
SET lantern_hnsw.ef_search = 1; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
249675.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 2; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
249675.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 4; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
249675.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 8; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
249675.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 16; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
249675.00 | ||
(10 rows) | ||
|
||
-- Queries below have the same result, which is different from above | ||
SET lantern_hnsw.ef_search = 32; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249457.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 64; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249457.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 128; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249457.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 256; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249457.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
(10 rows) | ||
|
||
SET lantern_hnsw.ef_search = 400; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
round | ||
----------- | ||
0.00 | ||
128.00 | ||
249249.00 | ||
249285.00 | ||
249418.00 | ||
249457.00 | ||
249515.00 | ||
249589.00 | ||
249647.00 | ||
249652.00 | ||
(10 rows) | ||
|
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,56 @@ | ||
------------------------------------------------------------------------------ | ||
-- Test changing lantern_hnsw.ef_search variable at runtime | ||
------------------------------------------------------------------------------ | ||
|
||
\ir utils/sift1k_array.sql | ||
|
||
CREATE INDEX hnsw_l2_index ON sift_base1k USING hnsw (v) WITH (_experimental_index_path='/tmp/lantern/files/index-sift1k-l2.usearch'); | ||
SELECT * FROM ldb_get_indexes('sift_base1k'); | ||
|
||
INSERT INTO sift_base1k (id, v) VALUES | ||
(1001, array_fill(1, ARRAY[128])), | ||
(1002, array_fill(2, ARRAY[128])); | ||
|
||
-- Validate error on invalid ef_search values | ||
\set ON_ERROR_STOP off | ||
--SET lantern_hnsw.ef_search = -1; | ||
--SET lantern_hnsw.ef_search = 0; | ||
--SET lantern_hnsw.ef_search = 401; | ||
\set ON_ERROR_STOP on | ||
|
||
-- Repeat the same query while varying ef parameter | ||
-- NOTE: it is not entirely known if the results of these are deterministic | ||
SET enable_seqscan = false; | ||
SELECT v AS v1001 FROM sift_base1k WHERE id = 1001 \gset | ||
|
||
-- Queries below have the same result | ||
SET lantern_hnsw.ef_search = 1; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 2; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 4; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 8; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 16; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
-- Queries below have the same result, which is different from above | ||
SET lantern_hnsw.ef_search = 32; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 64; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 128; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 256; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; | ||
|
||
SET lantern_hnsw.ef_search = 400; | ||
SELECT ROUND(l2sq_dist(v, :'v1001')::numeric, 2) FROM sift_base1k order by v <-> :'v1001' LIMIT 10; |
Submodule usearch
updated
3 files
+35 −24 | c/lib.cpp | |
+1 −4 | c/usearch.h | |
+24 −7 | include/usearch/index_punned_dense.hpp |