Skip to content

Commit

Permalink
Remove hnswlib remants since we no longer support hnslib as hnsw prov…
Browse files Browse the repository at this point in the history
…ider
  • Loading branch information
Ngalstyan4 committed Feb 8, 2024
1 parent 1caa6bf commit 36022de
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 62 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ endif ()
target_link_libraries(lantern PRIVATE "libstdc++.a")

set_target_properties(lantern PROPERTIES LINKER_LANGUAGE C)

target_compile_definitions(lantern PRIVATE LANTERN_USE_USEARCH)
# the flag instructs usearch/lib.c to builds with lantern-postgres compatible storage, which
# assumes storage is handled inside postgres and so usearch allocates no memory for it
target_compile_definitions(lantern PRIVATE LANTERN_INSIDE_POSTGRES)
Expand Down
8 changes: 0 additions & 8 deletions src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ static void AddTupleToUsearchIndex(ItemPointer tid, Datum *values, HnswBuildStat
// casting tid structure to a number to be used as value in vector search
// tid has info about disk location of this item and is 6 bytes long
usearch_label_t label = GetUsearchLabel(tid);
#ifdef LANTERN_USE_LIBHNSW
if(buildstate->hnsw != NULL) hnsw_add(buildstate->hnsw, vector, label);
#endif
#ifdef LANTERN_USE_USEARCH
if(buildstate->usearch_index != NULL) {
size_t capacity = usearch_capacity(buildstate->usearch_index, &error);
if(capacity == usearch_size(buildstate->usearch_index, &error)) {
Expand All @@ -115,7 +111,6 @@ static void AddTupleToUsearchIndex(ItemPointer tid, Datum *values, HnswBuildStat
}
usearch_add(buildstate->usearch_index, label, vector, usearch_scalar, &error);
}
#endif
assert(error == NULL);
buildstate->tuples_indexed++;
buildstate->reltuples++;
Expand Down Expand Up @@ -450,7 +445,6 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, Hnsw
elog(INFO, "done init usearch index");
assert(error == NULL);

buildstate->hnsw = NULL;
if(buildstate->index_file_path) {
if(access(buildstate->index_file_path, F_OK) != 0) {
ereport(ERROR,
Expand Down Expand Up @@ -582,8 +576,6 @@ static void BuildEmptyIndex(Relation index, IndexInfo *indexInfo, HnswBuildState
buildstate->usearch_index = usearch_init(&opts, &error);
assert(error == NULL);

buildstate->hnsw = NULL;

char *result_buf = palloc(USEARCH_EMPTY_INDEX_SIZE);
usearch_save_buffer(buildstate->usearch_index, result_buf, USEARCH_EMPTY_INDEX_SIZE, &error);
assert(error == NULL && result_buf != NULL);
Expand Down
2 changes: 0 additions & 2 deletions src/hnsw/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <utils/relcache.h>

#include "hnsw.h"
#include "lib_interface.h"
#include "usearch.h"

typedef struct HnswBuildState
Expand All @@ -26,7 +25,6 @@ typedef struct HnswBuildState
double reltuples;

/* hnsw */
hnsw_t hnsw;
usearch_index_t usearch_index;

/* Memory */
Expand Down
24 changes: 0 additions & 24 deletions src/hnsw/lib_interface.h

This file was deleted.

10 changes: 0 additions & 10 deletions src/hnsw/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ void _PG_init(void)
// todo:: cross-check with this`
// https://github.com/zombodb/zombodb/blob/34c732a0b143b5e424ced64c96e8c4d567a14177/src/access_method/options.rs#L895
ldb_hnsw_index_withopts = add_reloption_kind();
#if 0
add_int_reloption(ldb_hnsw_index_withopts, "element_limit",
"Maximum table size (needed for hnswlib)",
HNSW_DEFAULT_ELEMENT_LIMIT, 1, HNSW_MAX_ELEMENT_LIMIT
#if PG_VERSION_NUM >= 130000
,
AccessExclusiveLock
#endif
);
#endif
add_int_reloption(ldb_hnsw_index_withopts,
"dim",
"Number of dimensions of the vector",
Expand Down
9 changes: 3 additions & 6 deletions src/hnsw/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@
#define HNSW_DEFAULT_EF_CONSTRUCTION 128
#define HNSW_MAX_EF_CONSTRUCTION 400
/* 10 in faiss*/
#define HNSW_DEFAULT_EF 64
#define HNSW_MAX_EF 400
#define HNSW_DEFAULT_PROVIDER "usearch"
#define HNSW_MAX_ELEMENT_LIMIT 200000000
#define HNSWLIB_DEFAULT_ELEMENT_LIMIT 2000000
#define HNSW_DEFAULT_EF 64
#define HNSW_MAX_EF 400
#define HNSW_MAX_ELEMENT_LIMIT 200000000

#define LDB_HNSW_DEFAULT_K 10
#define LDB_HNSW_MAX_K 1000

/* HNSW index options */
typedef struct ldb_HnswOptions
{
// max elements the table will ever have. required for hnswlib
int32 vl_len_; /* varlena header (do not touch directly!) */
int dim;
int element_limit;
Expand Down
8 changes: 0 additions & 8 deletions src/hnsw/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,12 @@ void ldb_amendscan(IndexScanDesc scan)
// todo:: once VACUUM/DELETE are implemented, during scan we need to hold a pin
// on the buffer we have last returned.
// make sure to release that pin here

#ifdef LANTERN_USE_LIBHNSW
if(scanstate->hnsw) hnsw_destroy(scanstate->hnsw);
#endif
#ifdef LANTERN_USE_USEARCH
if(scanstate->usearch_index) {
usearch_error_t error = NULL;
usearch_free(scanstate->usearch_index, &error);
ldb_wal_retriever_area_fini(scanstate->retriever_ctx);
assert(error == NULL);
}
#else
elog(ERROR, "no index implementation specified");
#endif

if(scanstate->distances) pfree(scanstate->distances);

Expand Down
2 changes: 0 additions & 2 deletions src/hnsw/scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <assert.h>

#include "hnsw.h"
#include "lib_interface.h"
#include "retriever.h"
#include "usearch.h"

Expand All @@ -25,7 +24,6 @@ typedef struct HnswScanState
int current;
// set when the distances and labels are populated
int count;
hnsw_t hnsw;
usearch_index_t usearch_index;

RetrieverCtx *retriever_ctx;
Expand Down

0 comments on commit 36022de

Please sign in to comment.