Skip to content

Commit

Permalink
do not use external indexing if table does not contain tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Nov 15, 2024
1 parent 3574ee5 commit 5747727
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lantern_hnsw/src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_

uint32_t estimated_row_count = EstimateRowCount(heap);

if(estimated_row_count < EXTERNAL_INDEX_MIN_TUPLES) {
buildstate->external = false;
}

if(buildstate->external) {
buildstate->external_socket = palloc0(sizeof(external_index_socket_t));
create_external_index_session(ldb_external_index_host,
Expand Down
1 change: 1 addition & 0 deletions lantern_hnsw/src/hnsw/external_index_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "external_index_socket_ssl.h"
#include "usearch.h"

#define EXTERNAL_INDEX_MIN_TUPLES 1
#define EXTERNAL_INDEX_MAGIC_MSG_SIZE 4
#define EXTERNAL_INDEX_INIT_MSG 0x13333337
#define EXTERNAL_INDEX_END_MSG 0x31333337
Expand Down
8 changes: 8 additions & 0 deletions lantern_hnsw/test/expected/hnsw_create.out
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@ CREATE INDEX ON small_world4 USING lantern_hnsw (vector) WITH (M=14, ef=22, ef_c
INFO: done init usearch index
ERROR: Wrong number of dimensions: 3 instead of 4 expected
\set ON_ERROR_STOP on
\set ON_ERROR_STOP off
SET lantern.external_index_port=65535; -- this should fail if it will try to connect
CREATE TABLE empty(v REAL[]);
CREATE INDEX ON empty USING lantern_hnsw (v) WITH (dim=3, external=true); -- should success
INFO: done init usearch index
INFO: inserted 0 elements
INFO: done saving 0 vectors
\set ON_ERROR_STOP on
6 changes: 6 additions & 0 deletions lantern_hnsw/test/sql/hnsw_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ UPDATE small_world4 SET vector = '{0,0,0}' WHERE id = '001';
\set ON_ERROR_STOP off
CREATE INDEX ON small_world4 USING lantern_hnsw (vector) WITH (M=14, ef=22, ef_construction=2);
\set ON_ERROR_STOP on

\set ON_ERROR_STOP off
SET lantern.external_index_port=65535; -- this should fail if it will try to connect
CREATE TABLE empty(v REAL[]);
CREATE INDEX ON empty USING lantern_hnsw (v) WITH (dim=3, external=true); -- should success
\set ON_ERROR_STOP on

0 comments on commit 5747727

Please sign in to comment.