Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: add custom allocator on lantern #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/hnsw/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ static void BuildIndex(Relation heap, Relation index, IndexInfo *indexInfo, ldb_
opts.retriever = ldb_wal_index_node_retriever;
opts.retriever_mut = ldb_wal_index_node_retriever_mut;

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

buildstate->usearch_index = usearch_init(&opts, buildstate->pq_codebook, &error);
elog(INFO, "done init usearch index");
assert(error == NULL);
Expand Down Expand Up @@ -590,6 +594,10 @@ static void BuildEmptyIndex(Relation index, IndexInfo *indexInfo, ldb_HnswBuildS
assert(0 < opts.num_centroids && opts.num_centroids <= 256);
}

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

buildstate->usearch_index = usearch_init(&opts, buildstate->pq_codebook, &error);
assert(error == NULL);

Expand Down
5 changes: 5 additions & 0 deletions src/hnsw/insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ bool ldb_aminsert(Relation index,
assert(tmp_num_centroids == hdr->num_centroids);
assert(tmp_num_subvectors == hdr->num_subvectors);
}

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

// todo:: do usearch init in indexInfo->ii_AmCache
uidx = usearch_init(&opts, insertstate->pq_codebook, &error);
if(uidx == NULL) {
Expand Down
4 changes: 4 additions & 0 deletions src/hnsw/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ IndexScanDesc ldb_ambeginscan(Relation index, int nkeys, int norderbys)
opts.expansion_add,
opts.expansion_search);

// use palloc and pfree
opts.alloc_func = palloc;
opts.free_func = pfree;

scanstate->usearch_index = usearch_init(&opts, scanstate->pq_codebook, &error);
if(error != NULL) elog(ERROR, "error loading index: %s", error);
assert(error == NULL);
Expand Down
Loading