Skip to content

Commit

Permalink
Add env variable governing usearch index behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-maan committed Mar 21, 2024
1 parent dffa33f commit ca8a7b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use_faiss_indexes = bool(int(os.environ.get('USE_FAISS_INDEXES')))
use_annoy_indexes = bool(int(os.environ.get('USE_ANNOY_INDEXES')))
use_usearch_indexes = bool(int(os.environ.get('USE_USEARCH_INDEXES')))
load_usearch_indexes_in_memory = bool(int(os.environ.get('LOAD_USEARCH_INDEXES_IN_MEMORY')))

if not (use_faiss_indexes or use_annoy_indexes or use_usearch_indexes):
print('Bad config! At least one index type must be activated.')
Expand Down
5 changes: 4 additions & 1 deletion core/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ def __init__(self, dims, metric):

def read_from_files(self, index_file, json_file, name=None):
index = usearch.index.Index(ndim=self._dims, metric=self._metric)
index.view(index_file)
if config.load_usearch_indexes_in_memory:
index.load(index_file)
else:
index.view(index_file)
items = self._get_items_from_json(json_file)
item_resolver = items.__getitem__
return USearchIndex(index, item_resolver, name)
Expand Down
1 change: 1 addition & 0 deletions env
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ INCOMING_EXT=0
USE_FAISS_INDEXES=1
USE_ANNOY_INDEXES=1
USE_USEARCH_INDEXES=1
LOAD_USEARCH_INDEXES_IN_MEMORY=0
TOKEN_AUTHENTICATION=0
PLUGINS="miniapps"
YEAR_WISE_INDEXES=1
Expand Down

0 comments on commit ca8a7b5

Please sign in to comment.