Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if issparse(X):
for i in tqdm(range(X.shape[0]), disable=verbose < 1):
v = X[i].toarray()[0]
index.add_item(i, v)
else:
for i in tqdm(range(X.shape[0]), disable=verbose < 1):
v = X[i]
index.add_item(i, v)
try:
index.build(ntrees)
except Exception:
msg = ("Error building Annoy Index. Passing on_disk_build=False"
" may solve the issue, especially on Windows.")
raise IndexBuildingError(msg)
else:
if not build_index_on_disk:
index.save(path)
return index