How to use the nmslib.loadIndex function in nmslib

To help you get started, we’ve selected a few nmslib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nmslib / nmslib / python_bindings / integration_tests / test_nmslib.py View on Github external
if id != pos:
            print('id %s != pos %s' % (id, pos))
            sys.exit(1)

    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')


    query_time_param = ['efSearch=50']

    nmslib.loadIndex(index, index_name)

    print("The index %s is loaded" % index_name)

    nmslib.setQueryTimeParams(index,query_time_param)

    print('Query time parameters are set')

    print("Results for the loaded index")

    k = 2
    for idx, data in enumerate(read_data('sample_queryset.txt')):
        print(idx, nmslib.knnQuery(index, k, data))

    nmslib.freeIndex(index)
github nmslib / nmslib / python_bindings / integration_tests / test_nmslib.py View on Github external
for id, data in enumerate(DATA_STRS):
        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.loadIndex(index, index_name)

    print("The index %s is loaded" % index_name)

    nmslib.setQueryTimeParams(index, query_time_param)

    print('Query time parameters are set')

    print("Results for the loaded index:")

    k = 2
    for idx, data in enumerate(QUERY_STRS):
        print(idx, nmslib.knnQuery(index, k, data))

    nmslib.freeIndex(index)
github kakao / n2 / benchmarks / youtube_reproduce.py View on Github external
def fit(self, X):
        import nmslib
        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)