Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with TimeIt('preparing'):
for data in dataset:
d.append([[i, v] for i, v in enumerate(data) if v > 0])
for data in queryset:
q.append([[i, v] for i, v in enumerate(data) if v > 0])
with TimeIt('adding points'):
for id, data in enumerate(d):
nmslib.addDataPoint(index, id, data)
print('Let\'s invoke the index-build process')
index_param = ['NN=17', 'efConstruction=50', 'indexThreadQty=4']
query_time_param = ['efSearch=50']
with TimeIt('building index'):
nmslib.createIndex(index, index_param)
print('The index is created')
nmslib.setQueryTimeParams(index,query_time_param)
print('Query time parameters are set')
print("Results for the freshly created index:")
with TimeIt('knn query'):
if batch:
num_threads = 10
res = nmslib.knnQueryBatch(index, num_threads, k, query_matrix)
for idx, v in enumerate(res):
if idx < 5:
print(idx, v)
nmslib.DistType.FLOAT)
for id, data in enumerate(read_sparse_data('sample_sparse_dataset.txt')):
nmslib.addDataPoint(index, id, data)
print('We have added %d data points' % nmslib.getDataPointQty(index))
for i in range(0,min(MAX_PRINT_QTY,nmslib.getDataPointQty(index))):
print(nmslib.getDataPoint(index,i))
print('Let\'s invoke the index-build process')
index_param = ['NN=17', 'efConstruction=50', 'indexThreadQty=4']
query_time_param = ['efSearch=50']
nmslib.createIndex(index, index_param)
print('The index is created')
nmslib.setQueryTimeParams(index,query_time_param)
print('Query time parameters are set')
print("Results for the freshly created index:")
k = 3
for idx, data in enumerate(read_sparse_data('sample_sparse_queryset.txt')):
print(idx, nmslib.knnQuery(index, k, data))
nmslib.saveIndex(index, index_name)
print('We have added %d data points' % nmslib.getDataPointQty(index))
print("Distance between points (0,0) " + str(nmslib.getDistance(index, 0, 0)));
print("Distance between points (1,1) " + str(nmslib.getDistance(index, 1, 1)));
print("Distance between points (0,1) " + str(nmslib.getDistance(index, 0, 1)));
print("Distance between points (1,0) " + str(nmslib.getDistance(index, 1, 0)));
for i in range(0,min(MAX_PRINT_QTY,nmslib.getDataPointQty(index))):
print(nmslib.getDataPoint(index, i))
print('Let\'s invoke the index-build process')
index_param = ['NN=17', 'efConstruction=50', 'indexThreadQty=4']
query_time_param = ['efSearch=50']
nmslib.createIndex(index, index_param)
print('The index is created')
nmslib.setQueryTimeParams(index,query_time_param)
print('Query time parameters are set')
print("Results for the freshly created index:")
k = 3
start = time.time()
if fast:
num_threads = 10
query = read_data_fast('sample_queryset.txt')
res = nmslib.knnQueryBatch(index, num_threads, k, query)
print('We have added %d data points' % nmslib.getDataPointQty(index))
print("Distance between points (0,0) " + str(nmslib.getDistance(index, 0, 0)));
print("Distance between points (1,1) " + str(nmslib.getDistance(index, 1, 1)));
print("Distance between points (0,1) " + str(nmslib.getDistance(index, 0, 1)));
print("Distance between points (1,0) " + str(nmslib.getDistance(index, 1, 0)));
for i in range(0,min(MAX_PRINT_QTY,nmslib.getDataPointQty(index))):
print(nmslib.getDataPoint(index,i))
print('Let\'s invoke the index-build process')
index_param = ['NN=17', 'efConstruction=50', 'indexThreadQty=4']
query_time_param = ['efSearch=50']
nmslib.createIndex(index, index_param)
nmslib.setQueryTimeParams(index, query_time_param)
print('Query time parameters are set')
print("Results for the freshly created index:")
k = 2
if batch:
num_threads = 10
res = nmslib.knnQueryBatch(index, num_threads, k, QUERY_STRS)
for idx, data in enumerate(QUERY_STRS):
res = nmslib.knnQuery(index, k, data)
print(idx, data, res, [DATA_STRS[i] for i in res])
nmslib.saveIndex(index, index_name)
else:
for id, data in enumerate(read_data_as_string('sample_dataset.txt')):
nmslib.addDataPoint(index, id, data)
print('Let\'s print a few data entries')
print('We have added %d data points' % nmslib.getDataPointQty(index))
for i in range(0,min(MAX_PRINT_QTY,nmslib.getDataPointQty(index))):
print(nmslib.getDataPoint(index, i))
print('Let\'s invoke the index-build process')
index_param = ['NN=17', 'efConstruction=50', 'indexThreadQty=4']
query_time_param = ['efSearch=50']
nmslib.createIndex(index, index_param)
print('The index is created')
nmslib.setQueryTimeParams(index,query_time_param)
print('Query time parameters are set')
print("Results for the freshly created index:")
k = 3
for idx, data in enumerate(read_data_as_string('sample_queryset.txt')):
print(idx, nmslib.knnQuery(index, k, data))
nmslib.saveIndex(index, index_name)
self._index = nmslib.init(
self._nmslib_metric,
[],
self._method_name,
nmslib.DataType.DENSE_VECTOR,
nmslib.DistType.FLOAT)
for i, x in enumerate(X):
nmslib.addDataPoint(self._index, i, x.tolist())
if os.path.exists(self._index_name):
logging.debug("Loading index from file")
nmslib.loadIndex(self._index, self._index_name)
else:
logging.debug("Create Index")
nmslib.createIndex(self._index, self._index_param)
if self._save_index:
nmslib.saveIndex(self._index, self._index_name)
nmslib.setQueryTimeParams(self._index, self._query_param)