Ejemplo n.º 1
0
    def test_annoy_wrap_indexer(self):
        with NumpyIndexer(index_filename='wrap-npidx.gz') as a:
            a.name = 'wrap-npidx'
            a.add(vec_idx, vec)
            a.save()
            index_abspath = a.index_abspath
            save_abspath = a.save_abspath

        with BaseIndexer.load_config(os.path.join(cur_dir,
                                                  'annoy-wrap.yml')) as b:
            idx, dist = b.query(query, top_k=4)
            global retr_idx
            if retr_idx is None:
                retr_idx = idx
            else:
                np.testing.assert_almost_equal(retr_idx, idx)
            self.assertEqual(idx.shape, dist.shape)
            self.assertEqual(idx.shape, (10, 4))

        with BaseIndexer.load_config(os.path.join(cur_dir,
                                                  'nmslib-wrap.yml')) as c:
            idx, dist = c.query(query, top_k=4)
            if retr_idx is None:
                retr_idx = idx
            else:
                np.testing.assert_almost_equal(retr_idx, idx)
            self.assertEqual(idx.shape, dist.shape)
            self.assertEqual(idx.shape, (10, 4))
            self.add_tmpfile(index_abspath, save_abspath)
Ejemplo n.º 2
0
    def test_annoy_wrap_indexer(self):
        a = NumpyIndexer(index_filename='wrap-npidx.gz')
        a.name = 'wrap-npidx'
        a.add(vec_idx, vec)
        a.save()
        a.close()

        b = BaseIndexer.load_config('annoy-wrap.yml')
        idx, dist = b.query(query, top_k=4)
        print(idx, dist)
        global retr_idx
        if retr_idx is None:
            retr_idx = idx
        else:
            np.testing.assert_almost_equal(retr_idx, idx)
        self.assertEqual(idx.shape, dist.shape)
        self.assertEqual(idx.shape, (10, 4))

        c = BaseIndexer.load_config('nmslib-wrap.yml')
        idx, dist = c.query(query, top_k=4)
        print(idx, dist)
        if retr_idx is None:
            retr_idx = idx
        else:
            np.testing.assert_almost_equal(retr_idx, idx)
        self.assertEqual(idx.shape, dist.shape)
        self.assertEqual(idx.shape, (10, 4))
        self.add_tmpfile(a.index_abspath, a.save_abspath)
Ejemplo n.º 3
0
def test_annoy_wrap_indexer(metas):
    with NumpyIndexer(index_filename='wrap-npidx.gz', metas=metas) as indexer:
        indexer.name = 'wrap-npidx'
        indexer.add(vec_idx, vec)

    with BaseIndexer.load_config(os.path.join(
            cur_dir, 'yaml/annoy-wrap.yml')) as indexer:
        assert isinstance(indexer, AnnoyIndexer)
        idx, dist = indexer.query(query, top_k=4)
        assert idx.shape == dist.shape
        assert idx.shape == (10, 4)
Ejemplo n.º 4
0
def test_sptag_wrap_indexer(metas):
    with NumpyIndexer(index_filename='wrap-npidx.gz', metas=metas) as indexer:
        indexer.name = 'wrap-npidx'
        indexer.add(vec_idx, vec)
        indexer.save()

    with BaseIndexer.load_config(os.path.join(
            cur_dir, 'yaml/sptag-wrap.yml')) as indexer:
        assert isinstance(indexer, SptagIndexer)
        idx, dist = indexer.query(query, top_k=top_k)
        assert idx.shape == dist.shape
        assert idx.shape == (num_queries, top_k)
Ejemplo n.º 5
0
def test_annoy_wrap_indexer():
    with NumpyIndexer(index_filename='wrap-npidx.gz') as indexer:
        indexer.name = 'wrap-npidx'
        indexer.add(vec_idx, vec)
        indexer.save()
        save_abspath = indexer.save_abspath
        index_abspath = indexer.index_abspath

    with BaseIndexer.load_config(os.path.join(cur_dir, 'yaml/annoy-wrap.yml')) as indexer:
        assert isinstance(indexer, AnnoyIndexer)
        idx, dist = indexer.query(query, top_k=4)
        global retr_idx
        if retr_idx is None:
            retr_idx = idx
        else:
            np.testing.assert_almost_equal(retr_idx, idx)
        assert idx.shape == dist.shape
        assert idx.shape == (10, 4)
    rm_files([save_abspath, index_abspath])
Ejemplo n.º 6
0
    def test_annoy_wrap_indexer(self):
        with NumpyIndexer(index_filename='wrap-npidx.gz') as indexer:
            indexer.name = 'wrap-npidx'
            indexer.add(vec_idx, vec)
            indexer.save()
            index_abspath = indexer.index_abspath
            save_abspath = indexer.save_abspath
            self.add_tmpfile(index_abspath, save_abspath)

        with BaseIndexer.load_config(
                os.path.join(cur_dir, 'yaml/annoy-wrap.yml')) as indexer:
            self.assertIsInstance(indexer, AnnoyIndexer)
            idx, dist = indexer.query(query, top_k=4)
            global retr_idx
            if retr_idx is None:
                retr_idx = idx
            else:
                np.testing.assert_almost_equal(retr_idx, idx)
            self.assertEqual(idx.shape, dist.shape)
            self.assertEqual(idx.shape, (10, 4))